/* --- Variables & Color Palettes --- */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --bg-page: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-subtle: #f1f5f9;
  --bg-hover: #f1f5f9;

  --border: #e2e8f0;
  --border-subtle: #edf2f7;
  --border-focus: #4f46e5;

  --text-main: #0f172a;
  --text-muted: #64748b;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-subtle: #eef2ff;

  --success-bg: #ecfdf5;
  --success-text: #065f46;
  --success-border: #a7f3d0;

  --warning-bg: #fffbeb;
  --warning-text: #92400e;
  --warning-border: #fde68a;

  --error-bg: #fef2f2;
  --error-text: #991b1b;
  --error-border: #fecaca;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-pill: 9999px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-page: #0b0f17;
    --bg-surface: #131b26;
    --bg-surface-subtle: #1c2635;
    --bg-hover: #1e293b;

    --border: #243247;
    --border-subtle: #1c2638;
    --border-focus: #6366f1;

    --text-main: #f1f5f9;
    --text-muted: #94a3b8;

    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-subtle: #1e1b4b;

    --success-bg: #064e3b;
    --success-text: #6ee7b7;
    --success-border: #047857;

    --warning-bg: #451a03;
    --warning-text: #fde68a;
    --warning-border: #78350f;

    --error-bg: #450a0a;
    --error-text: #fca5a5;
    --error-border: #7f1d1d;

    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.4);
  }
}

/* --- Base --- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }

/* --- Navigation --- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.nav-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 3.5rem;
  gap: 1rem;
}
.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-main);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.brand::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--accent);
}
.main-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  overflow-x: auto;
  white-space: nowrap;
}
.main-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease-in-out;
}
.main-nav a:hover { color: var(--text-main); background-color: var(--bg-surface-subtle); }
.main-nav a.active { color: var(--accent); background-color: var(--accent-subtle); }
.main-nav a:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 1px; }
.main-nav a.nav-signout {
  border-left: 1px solid var(--border);
  padding-left: 0.85rem;
  margin-left: 0.5rem;
  border-radius: 0;
}

/* --- Layout --- */
.container {
  width: 100%;
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 1.25rem;
  flex: 1;
}
.auth-page .container { max-width: 420px; margin-top: 5vh; }

/* --- Cards & Panels --- */
.panel, fieldset, #sync, #counts, #placements, #notices {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}
#placements .table-wrapper { margin-bottom: 0; }

/* Status: counts as stat cards */
#counts ul {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.875rem;
}
#counts li {
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
}
#notices ul { list-style: none; padding: 0; margin: 0; }
#notices li {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.875rem;
  color: var(--text-muted);
}
#notices li:last-child { border-bottom: none; }

/* --- Typography --- */
h1, h2, h3 { color: var(--text-main); margin-top: 0; }
h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 1.25rem; }
h2 { font-size: 1.15rem; font-weight: 600; margin-bottom: 0.75rem; }
h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.5rem; }
p { margin-top: 0; margin-bottom: 1rem; }

/* --- Forms --- */
label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], select, textarea {
  width: 100%;
  font-family: inherit;
  font-size: 0.875rem;
  background-color: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  margin-bottom: 1rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgb(99 102 241 / 0.25);
}
input[type="checkbox"], input[type="radio"] {
  accent-color: var(--accent);
  width: 1rem;
  height: 1rem;
  cursor: pointer;
  vertical-align: middle;
}
fieldset { margin: 1.25rem 0; }
legend {
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0 0.5rem;
  color: var(--text-muted);
}
.weekday-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.75rem;
}

/* --- Buttons --- */
button, input[type="submit"], .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: var(--accent);
  color: #ffffff;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s ease-in-out;
  text-decoration: none;
}
button:hover, input[type="submit"]:hover, .button:hover { background-color: var(--accent-hover); }
button:focus-visible, input[type="submit"]:focus-visible, .button:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.button-link { margin-left: 0.75rem; font-size: 0.875rem; }
code {
  font-family: var(--font-mono);
  background: var(--bg-surface-subtle);
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
  word-break: break-all;
}
#google-client form { padding: 0; border: 0; box-shadow: none; }

/* --- Tables --- */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
  background: var(--bg-surface);
}
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 0.875rem; }
th {
  background-color: var(--bg-surface-subtle);
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--border-subtle); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background-color: var(--bg-hover); }
td input[type="text"], td input[type="number"], td select {
  margin-bottom: 0;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
}

/* --- Badges & Alerts --- */
.badge, #google-state {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
}
.badge::before, #google-state::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  background-color: currentColor;
}
.badge-success, [data-state="connected"] {
  background-color: var(--success-bg);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}
.badge-warning, [data-state="reconnect"], [data-state="connect"] {
  background-color: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid var(--warning-border);
}
.badge-error {
  background-color: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error-border);
}

#notice, #oauth-error, [role="alert"] {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
}
#notice {
  background-color: var(--success-bg);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}
#notice h2 { font-size: 1rem; }
#oauth-error, [role="alert"] {
  background-color: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error-border);
}

/* --- Mobile --- */
@media (max-width: 640px) {
  .nav-container { height: auto; padding: 0.75rem 1rem; flex-direction: column; align-items: stretch; }
  .main-nav { padding-top: 0.5rem; }
  .container { margin-top: 1rem; padding: 0 1rem; }
  #counts ul { grid-template-columns: 1fr 1fr; }
}
