/* static/css/theme.css */

/* =========================
   Color tokens / themes
   ========================= */
:root {
  /* Dark (default) */
  --bg: #0b0f14;
  --card: #121821;
  --text: #e6edf3;
  --muted: #9aa7b2;
  --link: #7bb2ff;
  --border: #30404e;
  --accent: #1b4b91;
  --hover: rgba(255,255,255,0.06);

  /* Nested card bg (slightly lighter than --card in dark mode) */
  --subcard: #17202b;

  /* Pill selection defaults */
  --pill-selected-bg: var(--link);
  --pill-selected-fg: #ffffff;
  --pill-selected-border: var(--link);

  color-scheme: dark;
}

html[data-theme="light"] {
  /* Light (explicit) */
  --bg: #ffffff;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --link: #1d4ed8;
  --border: #e5e7eb;
  --accent: #e5efff;
  --hover: rgba(0,0,0,0.05);

  /* Nested card bg (slightly darker than section cards in light mode) */
  --subcard: #eef2f7;

  color-scheme: light;
  --btn-bg: var(--link);
  --btn-fg: #ffffff;

  /* Cadence pills stay strong blue with white text in light theme */
  --pill-selected-bg: var(--link);
  --pill-selected-fg: #ffffff;
  --pill-selected-border: var(--link);
}

/* Light theme card polish */
html[data-theme="light"] .card {
  background: #f9fafb;
  border-color: #e5e7eb;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
}

@media (prefers-color-scheme: light) {
  html:not([data-theme]) {
    --bg: #ffffff;
    --card: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --link: #1d4ed8;
    --border: #e5e7eb;
    --accent: #e5efff;
    --hover: rgba(0,0,0,0.05);
    --subcard: #eef2f7;

    color-scheme: light;
  }
}

/* Smooth theme switch */
html {
  transition: background 0.3s ease, color 0.3s ease;
}

/* =========================
   Base / Typography
   ========================= */
html, body {
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  font-weight: 400;
  margin: 0;
}

a { color: var(--link); }
.muted { color: var(--muted); }
h3 { margin: 0px; }

/* Layout container */
.container { max-width: 900px; margin: 0 auto; padding: 16px; }

/* =========================
   Cards / Inputs
   ========================= */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
main > .card + .card { margin-top: 16px; }

.card .search-card,
.card .journal-card {
  background: var(--subcard);
  border-color: var(--border);
}
.card .search-card:hover,
.card .journal-card:hover { box-shadow: 0 2px 10px rgba(0,0,0,.12); }

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  box-sizing: border-box;
}

/* Full-width input utility */
.input-full { width: 100%; max-width: 100%; display: block; box-sizing: border-box; }

/* Prevent iOS Safari focus-zoom by ensuring 16px+ on controls */
@media (max-width: 640px) {
  input,
  select,
  textarea,
  button {
    font-size: 16px !important;   /* iOS zoom threshold */
    line-height: 1.3;
  }

  /* iOS date/time pickers sometimes need explicit inner sizing */
  input[type="date"],
  input[type="time"],
  input[type="datetime-local"],
  input[type="month"],
  input[type="week"],
  input[type="number"],
  input[type="search"] {
    font-size: 16px !important;
  }
}

/* Helps keep iOS from auto-resizing text */
html { -webkit-text-size-adjust: 100%; }

/* =========================
   Buttons (unified)
   ========================= */
.btn,
button.btn,
a.btn {
  display: inline-block;
  background: var(--btn-bg, var(--link));
  color: var(--btn-fg, #0b0f14);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
  line-height: 1.2;
}
.btn:hover,
button.btn:hover,
a.btn:hover { filter: brightness(1.05); }

.btn--outline {
  --btn-bg: transparent;
  --btn-fg: var(--text);
  border: 1px solid var(--border);
  background: transparent;
}

.btn--outline:hover { background: var(--hover); }

form .btn,
form button.btn,
form a.btn {
  display: inline-block;
  background: var(--btn-bg, var(--link));
  color: var(--btn-fg, #0b0f14);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
  line-height: 1.2;
}
form .btn:hover { filter: brightness(1.05); }

.toggle {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

/* =========================
   Header / Navigation
   ========================= */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.nav-actions { display: flex; align-items: center; gap: 8px; }
.nav-inline  { display: flex; align-items: center; gap: 8px; }
.nav-mobile  { display: none; position: relative; }

.nav-mobile summary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 10px;
  user-select: none;
  padding: 0;
}
.nav-mobile summary::-webkit-details-marker { display: none; }

.nav-sheet {
  position: absolute;
  right: 0; top: calc(100% + 8px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 1000;
}

.sheet-link {
  display: block; width: 100%; text-align: left;
  background: transparent; border: 0;
  padding: 10px 12px; color: var(--text); text-decoration: none; border-radius: 8px;
}
.sheet-link:hover { background: var(--hover); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border); background: var(--bg);
}
.topbar--sticky { position: sticky; top: 0; z-index: 100; backdrop-filter: saturate(1.2) blur(4px); }

.brand {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text);
  font-weight: 700; letter-spacing: 0.2px;
}
.brandmark svg rect { fill: var(--card); stroke: var(--border); stroke-width: 1; }
.brandmark svg text { fill: var(--text); }
.brandname { font-size: 18px; }

.nav-link {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; text-decoration: none;
  color: var(--text); border: 1px solid transparent; background: transparent; font: inherit; cursor: pointer;
}
.nav-link:hover { background: var(--hover); }

.nav-inline-form { display: inline; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px;
  border: none; background: transparent; cursor: pointer; font-size: 14px; line-height: 1;
  color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

.icon-sun { display: none; }
html[data-theme="light"] .icon-sun { display: inline-block; }
html[data-theme="light"] .icon-moon { display: none; }

@media (max-width: 640px) {
  .brandname { font-size: 16px; }
  .nav-inline { display: none; }
  .nav-mobile { display: block; }
}

.nav-quick { display: none; align-items: center; gap: 8px; }
@media (max-width: 640px) {
  .nav-inline { display: none; }
  .nav-quick { display: flex; }
  .nav-mobile { display: block; }
}

.nav-link.is-active,
.nav-link[aria-current="page"],
.btn.is-active { background: var(--hover); border-color: var(--border); }
.nav-link.is-active { box-shadow: inset 0 -2px 0 var(--link); }
.btn.is-active { filter: brightness(1.05); }

.icon--stroke { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon--solid { fill: currentColor; stroke: none; }

/* =========================
   Footer
   ========================= */
.site-footer {
  margin-top: 24px; padding: 16px 0; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  color: var(--muted); font-size: 14px;
}
.footer-left, .footer-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.footer-brand { color: var(--text); font-weight: 600; }
.footer-link { color: var(--link); text-decoration: none; }
.footer-link:hover { text-decoration: underline; }
.footer-sep { color: var(--muted); }

@media (max-width: 640px) {
  .site-footer { flex-direction: column; align-items: flex-start; }
}

/* Ensure header/nav icons follow text color */
.nav-link svg,
.icon-btn svg {
  width: 1.1em; height: 1.1em; stroke: currentColor; fill: none;
}

/* =========================
   Flash messages
   ========================= */
.flash-stack { margin: 12px 0 16px; }
.flash {
  padding: 10px 14px; border-radius: 6px; margin-bottom: 10px; border: 1px solid transparent;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 14px; font-weight: 500; line-height: 1.4;
}
.flash.info    { background: #e6f0ff; border-color: #5a9bff; color: #0b3d91; }
.flash.success { background: #e9f7ef; border-color: #28a745; color: #155724; }
.flash.warning { background: #fff8e5; border-color: #ffc107; color: #856404; }
.flash.error   { background: #fdecea; border-color: #dc3545; color: #721c24; }
.flash-text { flex-grow: 1; margin-right: 8px; }
.flash-close { background: none; border: none; font-size: 18px; font-weight: bold; cursor: pointer; line-height: 1; color: inherit; padding: 0; }
.flash-close:hover { opacity: 0.7; }

/* =========================
   Tables
   ========================= */
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid var(--border); padding: 8px; }
th { background: var(--card); }

/* =========================
   Responsive tweaks
   ========================= */
@media (max-width: 640px) {
  .container { padding: 12px; }
  .nav-inline { display: none; }
  .nav-mobile { display: block; }
  .btn, .toggle, .sheet-link {
    font-size: clamp(14px, 2.5vw, 16px);
    padding: 10px 14px;
    border-radius: 10px;
  }
}
@media (max-width: 640px) {
  .gsi-material-button { width: 100%; max-width: none; }
}

/* =========================
   Pills / badges (global)
   ========================= */
.pill {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--accent);
  color: var(--text);
  font-size: 12px;
  line-height: 1;
  vertical-align: middle;
}
.pill--soft { background: var(--accent); }
.pill--neutral { background: transparent; }

/* ===== Cadence Toggle Pills (dashboard) ===== */
.cadence-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  line-height: 1.1;
}
.cadence-pill:hover { background: var(--hover); }

/* Selected state (theme-driven) */
.cadence-pill.selected {
  background: var(--pill-selected-bg);
  color: var(--pill-selected-fg);
  border-color: var(--pill-selected-border);
}

/* ---- Light theme readability for generic selected pills ---- */
/* These target non-cadence pills (e.g., category pills defined in dashboard.html)
   so selected text isn't washed out on light backgrounds. */
html[data-theme="light"] .pill.selected { color: #111 !important; }

/* Explicitly keep cadence pills white-on-blue in light theme */
html[data-theme="light"] .cadence-pill.selected { color: #fff; }

/* Softer selected background for CATEGORY pills specifically in light mode
   (class .cat-pill is added in dashboard.html) */
html[data-theme="light"] body .cat-pill.chip {
  background: #eef4ff !important;   /* softer light blue */
  border-color: #cfe0ff !important;
  color: #111 !important;
}

html[data-theme="light"] body .cat-pill.chip .cat-dot {
  background: #1d4ed8 !important; /* match your link blue */
}