/* Mars Hill admin styles */
:root {
  --blue: #0b3d6b;
  --blue-dark: #082a4a;
  --gold: #f4b942;
  --red: #c62828;
  --green: #2e7d32;
  --gray-100: #f6f7f9;
  --gray-200: #e7eaee;
  --gray-300: #cdd3da;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--gray-900);
  background: var(--gray-100);
  font-size: 15px;
  line-height: 1.55;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus { outline: 3px solid var(--blue); outline-offset: 2px; }
h1, h2, h3 { color: var(--blue-dark); margin-top: 0; }

/* Screen reader only class */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Layout */
.admin-wrap { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: var(--blue-dark); color: #cfd9e3;
  flex-shrink: 0; padding: 1.25rem 0;
}
.sidebar .brand {
  display: flex; align-items: center; gap: .6rem;
  padding: 0 1.25rem 1.25rem; border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar .brand img { width: 38px; }
.sidebar .brand strong { color: #fff; font-size: 1rem; line-height: 1.2; }
.sidebar nav { padding: 1rem 0; }
.sidebar nav a {
  display: block; color: #cfd9e3; padding: .65rem 1.25rem;
  border-left: 3px solid transparent; font-size: .95rem;
}
.sidebar nav a:hover { background: rgba(255,255,255,.05); text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,.08); border-left-color: var(--gold); color: #fff; }
.sidebar .user-info {
  padding: 1rem 1.25rem; margin-top: auto; border-top: 1px solid rgba(255,255,255,.1);
  font-size: .85rem;
}

.main { flex: 1; min-width: 0; }
.topbar {
  background: #fff; border-bottom: 1px solid var(--gray-200);
  padding: .9rem 1.5rem; display: flex; align-items: center; justify-content: space-between;
}
.topbar h1 { margin: 0; font-size: 1.2rem; }
.topbar .actions a { margin-left: .5rem; }
.content { padding: 1.5rem; max-width: 1100px; }

/* Cards */
.card {
  background: #fff; border: 1px solid var(--gray-200); border-radius: 8px;
  padding: 1.25rem; margin-bottom: 1.25rem; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.card h2 { margin-top: 0; padding-bottom: .5rem; border-bottom: 2px solid var(--gold); }

/* Forms */
form label { display: block; margin: .85rem 0; font-weight: 600; color: var(--gray-700); }
form input[type=text], form input[type=email], form input[type=password],
form input[type=url], form input[type=number], form input[type=file],
form input:not([type]), form select, form textarea {
  display: block; width: 100%; max-width: 640px;
  padding: .55rem .7rem; font-size: .95rem;
  border: 1px solid var(--gray-300); border-radius: 6px;
  background: #fff; font-family: inherit;
}
form input:focus, form select:focus, form textarea:focus {
  outline: 3px solid var(--blue);
  outline-offset: 0;
  border-color: var(--blue);
}
form textarea { min-height: 220px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9rem; }
form input[type=checkbox] { width: auto; margin-right: .4rem; }
.rich-editor { max-width: none; }
.tox-tinymce { margin-top: .35rem; }
.help { font-size: .8rem; color: var(--gray-500); font-weight: normal; margin-top: .25rem; display:block; }

/* Accessible on/off switch */
.toggle-control {
  display: flex; align-items: center; gap: .8rem; max-width: 460px;
  padding: .8rem .9rem; border: 1px solid var(--gray-300); border-radius: 8px;
  background: var(--gray-100); cursor: pointer;
}
.toggle-control input {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
}
.toggle-slider {
  position: relative; width: 48px; height: 28px; flex: 0 0 48px;
  border-radius: 999px; background: var(--gray-500); transition: background .18s ease;
}
.toggle-slider::after {
  content: ""; position: absolute; width: 22px; height: 22px; top: 3px; left: 3px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform .18s ease;
}
.toggle-control input:checked + .toggle-slider { background: var(--green); }
.toggle-control input:checked + .toggle-slider::after { transform: translateX(20px); }
.toggle-control input:focus-visible + .toggle-slider { outline: 3px solid var(--blue); outline-offset: 3px; }
.toggle-copy { display: flex; flex-direction: column; line-height: 1.3; }
.toggle-label { color: var(--gray-900); }
.toggle-status { margin-top: .15rem; font-size: .8rem; font-weight: 500; }
.toggle-status-on { display: none; color: var(--green); }
.toggle-status-off { color: var(--gray-500); }
.toggle-control input:checked ~ .toggle-copy .toggle-status-on { display: block; }
.toggle-control input:checked ~ .toggle-copy .toggle-status-off { display: none; }
.toggle-control input:disabled + .toggle-slider { opacity: .65; cursor: wait; }
.toggle-saving { min-height: 1rem; margin-top: .2rem; color: var(--gray-500); font-size: .75rem; font-weight: 600; }
.toggle-saving.is-saved { color: var(--green); }
.toggle-saving.is-error { color: var(--red); }

.btn {
  display: inline-block; padding: .55rem 1.1rem; background: var(--gray-200);
  color: var(--gray-900); border-radius: 6px; font-weight: 600; text-decoration: none;
  border: 0; cursor: pointer; font-size: .9rem;
}
.btn:hover { text-decoration: none; }
.btn:focus { outline: 3px solid var(--blue); outline-offset: 2px; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger:hover { background: #8b1212; }
.btn.success { background: var(--green); color: #fff; }
.btn.small { padding: .35rem .7rem; font-size: .8rem; }

/* Tables */
table.list {
  width: 100%; background: #fff; border-collapse: collapse;
  border: 1px solid var(--gray-200); border-radius: 8px; overflow: hidden;
}
table.list th, table.list td {
  text-align: left; padding: .75rem 1rem; border-bottom: 1px solid var(--gray-200);
  font-size: .92rem;
}
table.list th { background: var(--gray-100); font-size: .8rem; text-transform: uppercase; color: var(--gray-500); letter-spacing: .03em; }
table.list tr:last-child td { border-bottom: 0; }
table.list .actions { white-space: nowrap; text-align: right; }
table.list .actions a, table.list .actions button {
  margin-left: .25rem;
}

/* Auto-saving drag order used by the Town Officials tables */
.sortable-heading {
  min-height: 1.6rem; display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin: -.25rem 0 .45rem;
}
.sortable-heading .help { margin: 0; }
.autosave-status { min-width: 5rem; color: var(--gray-500); font-size: .8rem; font-weight: 600; text-align: right; }
.autosave-status.is-saved { color: var(--green); }
.autosave-status.is-error { color: var(--red); }
.reorder-column { width: 92px; }
.reorder-cell { white-space: nowrap; }
.drag-handle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; margin-right: .35rem; border: 1px solid transparent; border-radius: 7px;
  color: var(--gray-500); font-size: 1.35rem; line-height: 1; cursor: grab;
  user-select: none; touch-action: none;
}
.drag-handle:hover { color: var(--blue); background: var(--gray-100); border-color: var(--gray-300); }
.drag-handle:active { cursor: grabbing; }
.order-number { display: inline-block; min-width: 1.5rem; text-align: center; font-weight: 600; color: var(--gray-500); }
.official-sortable tr.is-dragging,
.document-sortable tr.is-dragging { opacity: .45; }
.official-sortable tr.drag-target,
.document-sortable tr.drag-target { box-shadow: inset 0 3px 0 var(--gold); }
.sortable-ghost { opacity: .25; background: #eaf2f9; }
.sortable-chosen { background: #fffaf0; box-shadow: 0 4px 16px rgba(8,42,74,.12); }
.sortable-drag { opacity: .95; background: #fff; box-shadow: 0 10px 28px rgba(8,42,74,.22); }
.official-sortable.is-saving .drag-handle,
.document-sortable.is-saving .drag-handle { pointer-events: none; opacity: .55; }

/* Alerts */
.alert { padding: .85rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: .95rem; }
.alert.success { background: #e8f5e9; color: #2e7d32; border: 1px solid #c8e6c9; }
.alert.error { background: #ffebee; color: #c62828; border: 1px solid #ffcdd2; }
.alert.info { background: #e3f2fd; color: #1565c0; border: 1px solid #bbdefb; }

.dashboard-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.stat-card {
  background: #fff; padding: 1.25rem; border-radius: 8px;
  border-left: 4px solid var(--blue); box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.stat-card .num { font-size: 2rem; font-weight: 800; color: var(--blue-dark); }
.stat-card .label { color: var(--gray-500); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }

.muted { color: var(--gray-500); }
.row { display: flex; gap: 1rem; align-items: center; }
.row > * { margin: 0; }

/* Install screen */
body.install {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 2rem;
}
.install-box {
  background: #fff; padding: 2rem; border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.1); max-width: 480px; width: 100%;
}
.install-box h1 { margin-top: 0; }

/* Login */
body.login {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 2rem;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
}
.login-box {
  background: #fff; padding: 2rem; border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.2); max-width: 400px; width: 100%;
}
.login-box .brand-center {
  text-align: center; margin-bottom: 1.5rem;
}
.login-box .brand-center img { width: 70px; margin: 0 auto .5rem; display: block; }
