/* Coondor web. Colors follow the mobile app (app/src/theme.ts). */
:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --text: #1d1b18;
  --muted: #6a645b;
  --line: #e3ddd2;
  --brand: #1f4d45;
  --on-brand: #ffffff;
  --brand-soft: #e3eeeb;
  --danger: #b3321c;
  --success: #1d7a46;
  --failure: #b3321c;
  --series: #2a78d6;
  --dot-journal: #2a78d6;
  --dot-approach: #2f9e44;
  --dot-event: #eb6834;
  --dot-place: #e34948;
  --dot-walk: #eda100;
  --input-bg: #f8f6f2;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  --radius: 14px;
  --nav-w: 220px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --card: #1e1d1a;
    --text: #ece8e1;
    --muted: #a39d92;
    --line: #34322d;
    --brand: #4fa392;
    --on-brand: #0d1f1b;
    --brand-soft: #1f302c;
    --danger: #ff8a73;
    --success: #6fd69b;
    --failure: #ff8a73;
    --series: #3987e5;
    --dot-journal: #3987e5;
    --dot-approach: #4cc764;
    --dot-event: #d95926;
    --dot-place: #e66767;
    --dot-walk: #c98500;
    --input-bg: #262521;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
.icon { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.spacer { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 100; background: var(--card); padding: 8px 12px; border-radius: 8px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.boot { display: grid; place-items: center; min-height: 100vh; font-weight: 700; font-size: 20px; color: var(--muted); }

/* ------------------------------------------------------------ shell */
.shell { min-height: 100vh; }
.nav {
  position: fixed; inset: 0 auto 0 0; width: var(--nav-w);
  background: var(--card); border-right: 1px solid var(--line);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 16px; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; color: var(--text); text-decoration: none; padding: 4px 8px; }
.brand-lg { font-size: 24px; }
.nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav li a {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav li a:hover { background: var(--bg); color: var(--text); }
.nav li a.is-active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.main { margin-left: var(--nav-w); min-width: 0; }

.page { max-width: 860px; margin: 0 auto; padding: 0 24px 48px; }
.page-wide { max-width: 1180px; }
.page-head {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; gap: 8px; padding: 18px 0 12px; min-height: 68px;
}
.page-head h1 { font-size: 24px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-actions { display: flex; gap: 4px; align-items: center; }
.page-body { display: flex; flex-direction: column; gap: 14px; }

@media (max-width: 860px) {
  .nav {
    inset: auto 0 0 0; width: auto; height: calc(62px + env(safe-area-inset-bottom));
    flex-direction: row; padding: 0 4px env(safe-area-inset-bottom); border-right: 0; border-top: 1px solid var(--line);
  }
  .nav .brand { display: none; }
  .nav ul { flex-direction: row; flex: 1; justify-content: space-around; gap: 0; }
  .nav li { flex: 1; min-width: 0; }
  .nav li a { flex-direction: column; gap: 2px; padding: 8px 2px; font-size: 10.5px; border-radius: 8px; text-align: center; }
  .nav li a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .nav li a.is-active { background: none; }
  .main { margin-left: 0; padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  .page { padding: 0 16px 32px; }
  .page-head { padding: 10px 0 8px; min-height: 56px; }
  .page-head h1 { font-size: 20px; }
}

/* ------------------------------------------------------------ cards, lists */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.card.notice { border-color: var(--danger); }
.card-title { font-size: 15px; font-weight: 600; }
.section-title { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.section-title h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 700; flex: 1; }
.sub-title { font-size: 14px; color: var(--muted); font-weight: 600; margin-top: 6px; }
.day-title { font-size: 18px; margin-bottom: 4px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 24px 4px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-state { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; padding: 16px; color: var(--danger); }

.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 16px; min-height: 52px;
  background: none; border: 0; border-top: 1px solid var(--line); text-align: left; color: var(--text); text-decoration: none;
}
.row:first-child { border-top: 0; }
a.row:hover, button.row:hover { background: var(--bg); cursor: pointer; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-right { flex: none; display: flex; align-items: center; color: var(--muted); }

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }
.dot-sm { width: 6px; height: 6px; }
.dot-journal { background: var(--dot-journal); }
.dot-approach { background: var(--dot-approach); }
.dot-event { background: var(--dot-event); }
.dot-place { background: var(--dot-place); }
.dot-walk { background: var(--dot-walk); }

.badge { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.badge-success { color: var(--success); }
.badge-failure { color: var(--failure); }

.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.line-icon { display: flex; align-items: center; gap: 6px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.entry-text { font-size: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 180px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; color: var(--muted); }
.search input { border: 0; background: none; outline: none; padding: 8px 0; flex: 1; min-width: 0; color: var(--text); }
.month-switch { display: flex; align-items: center; gap: 4px; }
.month-switch strong { min-width: 150px; text-align: center; }

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary { background: var(--card); color: var(--text); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }
.btn-danger { background: var(--danger); color: var(--card); }
.btn-ghost { background: none; color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--brand-soft); color: var(--brand); }
.btn-small { min-height: 32px; padding: 4px 12px; font-size: 14px; }
.btn-icon { padding: 0; width: 40px; }
.btn-small.btn-icon { width: 32px; }

/* ------------------------------------------------------------ forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.form-error { color: var(--danger); font-weight: 500; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field textarea, .note-form textarea, .note textarea, .add-day input {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--input-bg);
}
.field textarea, .note-form textarea, .note textarea { resize: vertical; }
.field input:focus, .field textarea:focus, .note-form textarea:focus, .note textarea:focus, .add-day input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.fieldset legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 6px; }

.toggle { display: flex; align-items: center; gap: 12px; cursor: pointer; padding: 4px 0; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-track { width: 42px; height: 24px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: background 0.15s; }
.toggle-thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--card); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform 0.15s; }
.toggle input:checked + .toggle-track { background: var(--brand); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(18px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--brand); outline-offset: 2px; }
.toggle input:disabled + .toggle-track { opacity: 0.6; }
.toggle-text { display: flex; flex-direction: column; }
.toggle-text small { color: var(--muted); font-size: 13px; }

.segmented { align-self: flex-start; display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg { border: 0; background: none; padding: 6px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; color: var(--muted); }
.seg:hover { color: var(--text); }
.seg-on { background: var(--brand); color: var(--on-brand); }
.seg-on.seg-success { background: var(--success); color: var(--card); }
.seg-on.seg-failure { background: var(--failure); color: var(--card); }
.seg-on:hover { color: var(--on-brand); }

.note-form { display: flex; gap: 8px; align-items: flex-start; }
.note-form textarea { flex: 1; }
.notes { display: flex; flex-direction: column; gap: 8px; }
.note { gap: 6px; padding: 12px 14px; }
.add-day input { width: auto; }
.mcp-url { background: var(--input-bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; overflow-wrap: anywhere; }
.mcp-url code { font-size: 13px; }

/* ------------------------------------------------------------ dashboard */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.tiles-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .tiles { grid-template-columns: repeat(2, 1fr); } .tiles-3 { grid-template-columns: repeat(3, 1fr); } }
.tile { gap: 2px; }
.tile-label { font-size: 13px; color: var(--muted); }
.tile-value { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile-value-sm { font-size: 18px; }
.tile-sub { font-size: 12px; color: var(--muted); }

.chart { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.chart-plot { display: flex; align-items: flex-end; gap: 2px; border-bottom: 1px solid var(--line); }
.chart-col { flex: 1; height: 100%; display: flex; align-items: flex-end; background: none; border: 0; padding: 0; cursor: default; min-width: 0; }
.chart-bar { display: block; width: 100%; background: var(--series); border-radius: 4px 4px 0 0; }
.chart-col.is-active .chart-bar, .chart-col:hover .chart-bar { filter: brightness(1.2); }
.chart-col.is-active { background: var(--brand-soft); border-radius: 4px 4px 0 0; }
.chart-labels { display: flex; gap: 2px; }
.chart-labels span { flex: 1; text-align: center; font-size: 11px; color: var(--muted); min-width: 0; overflow: visible; white-space: nowrap; }
.chart-caption { font-size: 13px; color: var(--muted); min-height: 1.5em; }

/* ------------------------------------------------------------ calendar */
.calendar-layout { display: grid; grid-template-columns: minmax(320px, 440px) 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .calendar-layout { grid-template-columns: 1fr; } }
.calendar-day { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-title { background: none; border: 0; font-size: 18px; font-weight: 700; cursor: pointer; padding: 6px 10px; border-radius: 8px; color: var(--text); }
button.cal-title:hover { background: var(--bg); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-weekday { text-align: center; font-size: 12px; color: var(--muted); padding-bottom: 4px; }
.cal-day { background: none; border: 0; padding: 3px 0; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; min-height: 50px; border-radius: 10px; color: var(--text); }
.cal-day:hover { background: var(--bg); }
.cal-num { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-variant-numeric: tabular-nums; }
.cal-day.is-today .cal-num { box-shadow: inset 0 0 0 1.5px var(--brand); font-weight: 700; }
.cal-day.is-selected .cal-num { background: var(--brand); color: var(--on-brand); }
.cal-dots { display: flex; gap: 2px; height: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; font-size: 12px; color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: 5px; }
.cal-foot { display: flex; justify-content: center; }
.month-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.month-cell { padding: 12px 0; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer; }
.month-cell:hover { background: var(--bg); }
.month-cell.is-selected { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }

/* ------------------------------------------------------------ maps */
.map { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; z-index: 0; }
.map-picker { display: flex; flex-direction: column; gap: 8px; }
.leaflet-container { font: inherit; background: var(--input-bg); }

/* ------------------------------------------------------------ modal, toast */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; padding: 16px; z-index: 1000; }
.modal { background: var(--card); border-radius: 16px; width: min(480px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 4px 20px; }
.modal-head h2 { flex: 1; font-size: 18px; }
.modal-body { padding: 8px 20px 16px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px 16px; border-top: 1px solid var(--line); }
.picker-list { max-height: 50vh; overflow: auto; }
.toast-area { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 1100; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
@media (max-width: 860px) { .toast-area { bottom: calc(80px + env(safe-area-inset-bottom)); } }
.toast { background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-weight: 500; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25); }
.toast-error { background: var(--danger); color: var(--card); }

/* ------------------------------------------------------------ login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(400px, 100%); padding: 28px; gap: 14px; }
.login-card h1 { font-size: 22px; }
.lang-switch { display: flex; justify-content: center; }
