/* ==========================================================================
   Routine Tracker — shared UI design system
   Direction: warm minimalism (Notion). Paper-tone field, white cards,
   serif headings, calm sage accent. Airy, low-glare, document-like.
   ========================================================================== */

:root {
  /* Surfaces — warm paper field with near-white cards */
  --bg: #f7f4ee;
  --surface: #fffdf8;
  --surface-2: #f1ece2;
  /* Back-compat alias: per-service CSS still references --card */
  --card: var(--surface);

  /* Text — warm near-black (Notion ink) */
  --ink: #37352f;
  --ink-soft: #5f5b51;
  --muted: #9b9488;

  /* Lines — warm hairlines */
  --line: #e7e0d4;
  --line-strong: #ddd4c4;

  /* Accent — calm sage green (fits habits/health, low glare) */
  --accent: #4f7a5b;
  --accent-hover: #436b4f;
  --accent-ink: #ffffff;
  --accent-soft: #e6efe6;

  /* Focus + links — sage, cohesive with accent */
  --focus: #4f7a5b;
  --focus-ring: rgba(79, 122, 91, 0.30);

  /* Semantics (warm) */
  --success: #4f7a5b;
  --success-soft: #e6efe6;
  --danger-ink: #b0503a;
  --danger-soft: #f6e6df;

  /* Shape & depth — rounder, softer, near-flat */
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(55, 53, 47, 0.06);

  /* Typography — serif display + system sans body */
  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI Variable",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
}

html[data-theme="dark"] {
  /* Neutral graphite dark (not warm/brown). Sage accent ties it to light. */
  --bg: #18191b;
  --surface: #212327;
  --surface-2: #2a2c30;
  --card: var(--surface);

  --ink: #ececee;
  --ink-soft: #c6c8cd;
  --muted: #9a9da4;

  --line: #303237;
  --line-strong: #41444b;

  --accent: #7fbf96;
  --accent-hover: #92cba6;
  --accent-ink: #0c1a12;
  --accent-soft: rgba(127, 191, 150, 0.16);

  --focus: #7fbf96;
  --focus-ring: rgba(127, 191, 150, 0.40);

  --success: #7fbf96;
  --success-soft: rgba(127, 191, 150, 0.16);
  --danger-ink: #e89a8a;
  --danger-soft: #3a2724;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

html[data-layout="wide"] .page {
  max-width: none;
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 20px 56px;
}

/* --------------------------------------------------------------------------
   Top bar
   -------------------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 16px;
}

.brand,
.topbar-actions,
.auth-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-width: 0;
}

.topbar-actions {
  gap: 8px;
}

.auth-actions {
  gap: 8px;
}

.logo {
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: var(--accent-ink);
  background: var(--accent);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

/* --------------------------------------------------------------------------
   Segmented controls (language / theme / layout)
   -------------------------------------------------------------------------- */

.lang-switch,
.theme-switch,
.layout-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 2px;
}

.lang-button,
.theme-button,
.layout-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
}

.lang-button:hover,
.theme-button:hover,
.layout-button:hover {
  color: var(--ink);
}

.lang-button.is-active,
.theme-button.is-active,
.layout-button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.layout-switch {
  padding: 0;
  background: transparent;
  border: 0;
}

.layout-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  padding: 6px 11px;
}

.layout-button:hover {
  background: var(--surface-2);
}

.layout-button.is-active {
  box-shadow: none;
  background: var(--surface-2);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  line-height: 1.2;
  padding: 7px 13px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease,
    color 0.12s ease, transform 0.04s ease;
}

.button:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
}

.button:active {
  transform: translateY(0.5px);
}

.button[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}

.button-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.button-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.button-danger {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--danger-ink);
}

.button-danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger-soft);
}

.button-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
}

.button-ghost:hover {
  background: var(--surface-2);
  border-color: transparent;
}

.button-compact {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12.5px;
}

.button-icon {
  width: 32px;
  min-width: 32px;
  padding: 0;
}

/* --------------------------------------------------------------------------
   User chip
   -------------------------------------------------------------------------- */

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 12px;
}

.user-name {
  max-width: 140px;
  overflow: hidden;
  color: var(--ink);
  font-weight: 550;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Navigation (tab-style)
   -------------------------------------------------------------------------- */

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding-bottom: 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.nav-link {
  color: var(--muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  padding: 6px 11px;
  font-size: 13px;
  font-weight: 550;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-link:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.nav-link.is-active {
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   Content + messages
   -------------------------------------------------------------------------- */

.content {
  margin-top: 20px;
}

.messages {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.message {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px 14px;
  font-size: 13px;
}

.message.success {
  background: var(--success-soft);
  color: var(--success);
  border-color: transparent;
}

.message.error {
  background: var(--danger-soft);
  color: var(--danger-ink);
  border-color: transparent;
}

/* --------------------------------------------------------------------------
   Panels & cards
   -------------------------------------------------------------------------- */

.panel,
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.panel {
  padding: 20px;
}

.card {
  padding: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.card-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin: 3px 0 0;
}

.card > .card-subtitle {
  margin-bottom: 16px;
}

/* --------------------------------------------------------------------------
   Page heading
   -------------------------------------------------------------------------- */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.lead {
  color: var(--muted);
  margin: 6px 0 0;
  max-width: 720px;
  font-size: 14px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

.form-grid {
  display: grid;
  gap: 16px;
}

.form {
  display: grid;
  gap: 14px;
}

.form-row {
  display: grid;
  gap: 6px;
}

.field label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
}

.label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.helptext {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 5px;
}

.input,
.select,
.textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  padding: 8px 11px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--muted);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--muted);
}

.input:focus,
.select:focus,
.textarea:focus,
.button:focus-visible,
.lang-button:focus-visible,
.theme-button:focus-visible,
.layout-button:focus-visible,
.nav-link:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.button:focus-visible,
.nav-link:focus-visible {
  border-color: transparent;
}

.link {
  color: var(--focus);
  text-decoration: none;
  font-weight: 550;
}

.link:hover {
  text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Alerts
   -------------------------------------------------------------------------- */

.alerts {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.alert {
  background: var(--danger-soft);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--danger-ink);
  font-size: 13px;
  padding: 10px 12px;
}

.errorlist {
  color: var(--danger-ink);
  font-size: 12px;
  margin: 0 0 6px;
  padding-left: 16px;
}

/* --------------------------------------------------------------------------
   Layout helpers
   -------------------------------------------------------------------------- */

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.inline-form {
  display: inline;
}

.inline {
  display: inline;
}

.muted {
  color: var(--muted);
}

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  color: var(--muted);
  padding: 28px 18px;
  text-align: center;
  font-size: 13px;
}

.form-actions,
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  .page {
    padding: 14px 16px 40px;
  }

  .topbar,
  .page-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    align-items: center;
    flex-wrap: wrap;
  }

  .actions {
    width: 100%;
  }

  .actions .button {
    flex: 1 1 auto;
  }
}
