/* Khun — direction « Papier ».
   Un fond crème, des filets, un seul accent bleu encre. Pas d'ombres, pas de
   cartes : ce sont des lignes sur une page. Les titres sont en Newsreader,
   le corps en Source Sans 3. */

:root {
  --paper:        #f7f3e9;
  --paper-raised: #fffdf7;
  --ink:          #22201b;
  --ink-soft:     #6f6959;
  --ink-faint:    #9c9484;
  --rule:         #ddd4c1;
  --rule-strong:  #c7bca4;
  --accent:       #1f4e79;
  --accent-wash:  rgba(31, 78, 121, .08);
  --danger:       #8c3a2b;
  --radius:       10px;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans:  "Source Sans 3", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:        #16150f;
    --paper-raised: #1f1e16;
    --ink:          #ece6d8;
    --ink-soft:     #a49c8b;
    --ink-faint:    #756e60;
    --rule:         #33312a;
    --rule-strong:  #4a473d;
    --accent:       #86adda;
    --accent-wash:  rgba(134, 173, 218, .12);
    --danger:       #d98675;
  }
}
:root[data-theme="dark"] {
  --paper:        #16150f;
  --paper-raised: #1f1e16;
  --ink:          #ece6d8;
  --ink-soft:     #a49c8b;
  --ink-faint:    #756e60;
  --rule:         #33312a;
  --rule-strong:  #4a473d;
  --accent:       #86adda;
  --accent-wash:  rgba(134, 173, 218, .12);
  --danger:       #d98675;
}

* { box-sizing: border-box; }

/* `hidden` must beat the display rules below it — .login sets display:grid,
   which would otherwise outrank the UA stylesheet's [hidden] and leave the
   login screen on top of the app. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ── login ─────────────────────────────────────────────────────────── */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card { width: 100%; max-width: 340px; }
.login-sub { color: var(--ink-soft); margin: 0 0 28px; font-size: 15px; }
.field { display: block; margin-bottom: 16px; }
.field > span {
  display: block;
  font-size: 12px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 9px 2px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--rule-strong);
  border-radius: 0;
  outline: none;
}
.field input:focus { border-bottom-color: var(--accent); }
.login-error { color: var(--danger); font-size: 14px; margin: 14px 0 0; }

/* ── shell ─────────────────────────────────────────────────────────── */
.app {
  max-width: 620px;
  margin: 0 auto;
  padding: 0 20px 120px;
}
.topbar { padding-top: max(20px, env(safe-area-inset-top)); }
.topbar-line { display: flex; align-items: baseline; justify-content: space-between; }
.wordmark {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 30px;
  letter-spacing: -.01em;
  margin: 0;
}
.datestamp {
  margin: 2px 0 18px;
  color: var(--ink-soft);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.icon-btn {
  background: none;
  border: 0;
  color: var(--ink-soft);
  font-size: 20px;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
}

.offline-bar {
  margin: 0 0 14px;
  padding: 8px 12px;
  border-left: 3px solid var(--rule-strong);
  background: var(--accent-wash);
  color: var(--ink-soft);
  font-size: 14px;
}

.tabs {
  display: flex;
  gap: 20px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none;
  border: 0;
  padding: 8px 0 10px;
  color: var(--ink-faint);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.is-active { color: var(--ink); border-bottom-color: var(--accent); }

/* ── lists: des filets, rien d'autre ───────────────────────────────── */
.section-title {
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 28px 0 2px;
}
.rows { border-top: 1px solid var(--rule); }
.row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 2px;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  background: none;
  border-left: 0; border-right: 0; border-top: 0;
  width: 100%;
  text-align: left;
}
.row:active { background: var(--accent-wash); }
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; }
.row-sub {
  display: block;
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 14px;
}
.row-sub em { font-style: italic; color: var(--ink-soft); }
.row-meta {
  color: var(--ink-faint);
  font-size: 13px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  padding-top: 2px;
}
.row.is-done .row-title { text-decoration: line-through; color: var(--ink-faint); }
.overdue { color: var(--danger); }

/* checkbox à filet, pas de widget natif */
.tick {
  width: 20px; height: 20px;
  flex: 0 0 20px;
  margin-top: 2px;
  border: 1px solid var(--rule-strong);
  border-radius: 50%;
  background: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: transparent;
  font-size: 12px;
  line-height: 1;
  padding: 0;
}
.tick[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--paper-raised);
}

.dot {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 7px;
  vertical-align: middle;
}
.dot.low { background: var(--ink-faint); }
.dot.medium { background: var(--rule-strong); }

.empty {
  color: var(--ink-faint);
  font-style: italic;
  padding: 18px 2px;
  border-bottom: 1px solid var(--rule);
}

/* ── FAB ───────────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  right: max(20px, calc(50vw - 290px));
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--paper-raised);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  z-index: 20;
}

/* ── sheets ────────────────────────────────────────────────────────── */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20,18,12,.42); }
.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  margin: 0 auto;
  max-width: 620px;
  background: var(--paper-raised);
  border-top: 1px solid var(--rule-strong);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  max-height: 88dvh;
  overflow-y: auto;
}
.sheet-tall { min-height: 62dvh; }
.composer-input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--rule-strong);
  background: transparent;
  padding: 6px 2px 10px;
  font-family: var(--serif);
  font-size: 20px;
  outline: none;
  border-radius: 0;
}
.composer-input:focus { border-bottom-color: var(--accent); }
.composer-hint {
  margin: 8px 0 18px;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
}
.composer-row { display: flex; gap: 16px; flex-wrap: wrap; }
.mini { flex: 1 1 130px; }
.mini > span {
  display: block;
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.mini select, .mini input {
  width: 100%;
  padding: 7px 2px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  outline: none;
}
.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 26px;
}
.btn-primary {
  background: var(--accent);
  color: var(--paper-raised);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 20px;
  cursor: pointer;
  width: 100%;
}
.sheet-actions .btn-primary { width: auto; }
.btn-quiet {
  background: none;
  border: 0;
  color: var(--ink-soft);
  padding: 10px 8px;
  cursor: pointer;
}
.btn-line {
  background: none;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  padding: 9px 16px;
  color: var(--ink);
  cursor: pointer;
}
.btn-line.accent { border-color: var(--accent); color: var(--accent); }
.btn-line.danger { border-color: transparent; color: var(--danger); padding-left: 0; }

/* ── detail ────────────────────────────────────────────────────────── */
.detail-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 25px;
  line-height: 1.2;
  margin: 0 0 4px;
  border: 0;
  background: transparent;
  width: 100%;
  outline: none;
  resize: none;
  overflow: hidden;
}
.detail-kind {
  font-size: 12px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 20px;
}
.next-step {
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 14px 0;
  margin-bottom: 4px;
}
.next-step-label {
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 6px;
}
.next-step textarea, .notes textarea {
  width: 100%;
  border: 0;
  background: transparent;
  outline: none;
  resize: vertical;
  min-height: 2.6em;
  padding: 0;
  font-family: inherit;
}
.next-step .missing { color: var(--danger); font-style: italic; }
.notes { padding: 16px 0; border-bottom: 1px solid var(--rule); }
.notes textarea { min-height: 6em; }
.field-grid {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  padding: 14px 0;
  border-bottom: 1px solid var(--rule);
}
.detail-actions { display: flex; gap: 10px; align-items: center; margin: 18px 0 6px; flex-wrap: wrap; }
.journal { margin-top: 24px; }
.journal-entry {
  display: flex;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 15px;
}
.journal-date {
  color: var(--ink-faint);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex: 0 0 auto;
}
.journal-by { color: var(--accent); font-size: 13px; }
.saved-flash { color: var(--ink-faint); font-size: 13px; }

/* ── habit week strip ──────────────────────────────────────────────── */
.week { display: flex; gap: 6px; margin-top: 6px; }
.week span {
  width: 17px; height: 17px;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  display: grid;
  place-items: center;
  font-size: 9px;
  color: var(--ink-faint);
}
.week span.on { background: var(--accent); border-color: var(--accent); color: var(--paper-raised); }
