/* ===== Ledger — slow capital ===== */

:root {
  --bg: #f3efe6;
  --bg-deep: #ece6d8;
  --surface: #faf6ed;
  --surface-warm: #f0e9d8;
  --ink: #211e19;
  --ink-soft: #4a443b;
  --ink-mute: #7c7468;
  --laurel: #6e8a64;
  --laurel-dark: #3d5a3a;
  --laurel-soft: #c2cfb6;
  --laurel-bg: rgba(110, 138, 100, 0.10);
  --oxblood: #8a2b22;
  --oxblood-soft: #b5453a;
  --oxblood-bg: rgba(138, 43, 34, 0.08);
  --gold: #9c7c3a;
  --gold-bg: rgba(156, 124, 58, 0.10);
  --border: rgba(33, 30, 25, 0.13);
  --border-strong: rgba(33, 30, 25, 0.22);
  --shadow-soft: 0 1px 4px rgba(33, 30, 25, 0.06);
  --shadow-card: 0 2px 14px rgba(33, 30, 25, 0.10);
  --shadow-modal: 0 24px 60px rgba(33, 30, 25, 0.28);
  --display: 'Cormorant Garamond', 'Georgia', serif;
  --body: 'Spectral', 'Georgia', serif;
  --radius: 4px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100vh; }

body {
  font-family: var(--body);
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse at 15% -10%, rgba(156,124,58,0.06), transparent 55%),
    radial-gradient(ellipse at 90% 120%, rgba(61,90,58,0.05), transparent 50%);
  color: var(--ink);
  line-height: 1.65;
  letter-spacing: 0.005em;
  font-size: 16px;
  min-height: 100vh;
  padding: 40px 28px 60px;
}

/* paper grain overlay — same as the articles */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.32;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

.hidden { display: none !important; }

a { color: var(--laurel-dark); text-decoration: none; border-bottom: 1px solid var(--laurel-soft); transition: all 0.2s; }
a:hover { color: var(--ink); border-color: var(--ink); }

/* ===== Login ===== */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
  z-index: 10;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 64px 56px 56px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-modal);
  position: relative;
}

.ornament {
  font-family: var(--display);
  font-size: 32px;
  color: var(--gold);
  letter-spacing: 0.4em;
  margin-bottom: 16px;
  line-height: 1;
  font-style: italic;
}

.ornament-line {
  height: 1px;
  width: 100px;
  margin: 28px auto;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.brand-title {
  font-family: var(--display);
  font-size: 64px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  line-height: 1;
}

.brand-subtitle {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 16px;
  letter-spacing: 0.04em;
  font-family: var(--body);
}

.btn-google {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 12px 26px;
  font-family: var(--body);
  font-size: 15px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: all 0.25s ease;
  letter-spacing: 0.02em;
}
.btn-google:hover {
  background: var(--laurel-bg);
  border-color: var(--laurel);
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}

.login-error {
  color: var(--oxblood);
  margin-top: 16px;
  font-size: 14px;
  font-style: italic;
  min-height: 1.2em;
}

.login-or {
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 13px;
  margin: 18px 0 12px;
  letter-spacing: 0.08em;
  position: relative;
}
.login-or::before,
.login-or::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 28%;
  height: 1px;
  background: var(--border);
}
.login-or::before { left: 12%; }
.login-or::after { right: 12%; }

.btn-readonly {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--ink-soft);
  padding: 10px 22px;
  font-family: var(--body);
  font-size: 14px;
  letter-spacing: 0.04em;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-readonly:hover {
  border-color: var(--laurel);
  color: var(--ink);
  background: var(--laurel-bg);
  transform: translateY(-1px);
}

.btn-logout {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--ink-soft);
  font-family: var(--body);
  font-size: 12.5px;
  letter-spacing: 0.04em;
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  margin-left: 8px;
}
.btn-logout:hover {
  border-color: var(--oxblood);
  color: var(--oxblood);
  background: var(--oxblood-bg);
}

.readonly-banner {
  background: var(--laurel-bg);
  border: 1px solid var(--laurel);
  color: var(--ink);
  text-align: center;
  font-family: var(--body);
  font-size: 13px;
  padding: 8px 14px;
  border-radius: var(--radius);
  margin-bottom: 18px;
}
.readonly-banner.hidden { display: none; }
.readonly-banner a {
  color: var(--laurel-dark);
  font-weight: 600;
  border-bottom: 1px solid currentColor;
  text-decoration: none;
}
.readonly-banner a:hover { color: var(--ink); }

body.read-only .edit-only { display: none !important; }

/* ===== App layout ===== */
.app {
  max-width: 960px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 28px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px;
}

.header-title {
  font-family: var(--display);
  font-size: 32px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.05em;
  line-height: 1;
}

.header-subtitle {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 12.5px;
  letter-spacing: 0.04em;
  margin-top: 4px;
}

.tabs {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.tab {
  background: transparent;
  border: none;
  color: var(--ink-soft);
  font-family: var(--body);
  font-size: 14px;
  letter-spacing: 0.06em;
  padding: 8px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}
.tab:hover { color: var(--ink); }
.tab.active {
  color: var(--ink);
  background: var(--laurel-bg);
}

.sync-status {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink-mute);
  transition: background 0.3s;
  justify-self: end;
}
.sync-status.synced { background: var(--laurel); }
.sync-status.syncing { background: var(--gold); }
.sync-status.error { background: var(--oxblood); }

/* ===== Views ===== */
.view { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

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

.section-title {
  font-family: var(--display);
  font-size: 30px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: 0.04em;
}

.section-sub {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 14px;
  margin-top: 4px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-mute);
  font-style: italic;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ===== Library ===== */
.library-filters {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 28px;
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.filter-group-label {
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-mute);
  min-width: 80px;
}
.library-filter {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink-soft);
  font-family: var(--body);
  font-size: 12.5px;
  letter-spacing: 0.04em;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s;
}
.library-filter:hover { border-color: var(--laurel); color: var(--ink); }
.library-filter.active {
  background: var(--laurel-bg);
  border-color: var(--laurel);
  color: var(--ink);
}

.library-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}
.library-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  cursor: pointer;
  transition: all 0.25s;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
}
.library-card:hover {
  transform: translateY(-2px);
  border-color: var(--laurel);
  box-shadow: var(--shadow-card);
}
.library-card-breadcrumb {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 10px;
}
.library-card-breadcrumb .sep { color: var(--ink-mute); margin: 0 6px; }
.library-card-title {
  font-family: var(--display);
  font-size: 24px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 8px;
  line-height: 1.2;
  letter-spacing: 0.005em;
}
.library-card-title em { font-style: italic; color: var(--oxblood); font-weight: 500; }
.library-card-excerpt {
  font-size: 14.5px;
  color: var(--ink-soft);
  line-height: 1.6;
  margin-bottom: 14px;
  flex: 1;
}
.library-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11.5px;
  color: var(--ink-mute);
  letter-spacing: 0.05em;
  font-style: italic;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.library-card-actions {
  display: flex;
  gap: 8px;
}
.library-card-download {
  font-family: var(--body);
  font-size: 11px;
  color: var(--ink-mute);
  letter-spacing: 0.04em;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: all 0.15s;
}
.library-card-download:hover { color: var(--gold); border-color: var(--gold); }

/* ===== Calendar (event tracker) ===== */
.event-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--ink-soft);
}
.event-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.event-legend-dot { width: 10px; height: 10px; border-radius: 50%; }

.event-calendar {
  background: var(--surface-warm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  box-shadow: var(--shadow-soft);
}
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-bottom: 14px;
}
.cal-nav-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink-soft);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: all 0.2s;
  font-family: var(--display);
}
.cal-nav-btn:hover { border-color: var(--laurel); color: var(--ink); background: var(--laurel-bg); }
.cal-month-label {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.03em;
  min-width: 200px;
  text-align: center;
}
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
  font-style: italic;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.cal-weekdays span { text-align: center; padding: 4px 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 92px;
  padding: 6px 6px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: border-color 0.15s;
}
.cal-day-empty { background: transparent; border-color: transparent; }
.cal-day-today { border-color: var(--laurel); box-shadow: 0 0 0 1px var(--laurel-soft); }
.cal-day-has { cursor: pointer; }
.cal-day[data-date] { cursor: pointer; }
.cal-day[data-date]:hover { border-color: var(--laurel); }
.cal-day-num {
  font-family: var(--display);
  font-size: 15px;
  font-weight: 500;
  color: var(--ink-soft);
  text-align: right;
  line-height: 1;
  margin-bottom: 2px;
}
.cal-day-today .cal-day-num { color: var(--laurel-dark); font-weight: 700; }
.cal-chip {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 2px;
  border-left: 2px solid;
  background: var(--surface-warm);
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  line-height: 1.4;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 5px;
}
.cal-chip:hover { background: var(--laurel-bg); }
.cal-chip-ticker {
  font-family: var(--display);
  font-weight: 700;
  font-size: 10px;
  color: var(--ink-soft);
  background: rgba(33, 30, 25, 0.06);
  border-radius: 2px;
  padding: 0 4px;
  letter-spacing: 0.04em;
}
.cal-chip-label { overflow: hidden; text-overflow: ellipsis; }
.cal-chip-clip { margin-left: auto; font-size: 9px; opacity: 0.7; }
.cal-more {
  font-style: italic;
  font-size: 10.5px;
  color: var(--ink-mute);
  padding: 1px 4px;
  cursor: pointer;
}
.cal-more:hover { color: var(--laurel-dark); }

/* Day popover */
.day-popover {
  position: absolute;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--laurel);
  border-radius: var(--radius);
  box-shadow: var(--shadow-modal);
  min-width: 260px;
  max-width: 340px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 10px 0;
}
.day-popover-title {
  font-style: italic;
  font-size: 12px;
  color: var(--ink-soft);
  padding: 0 16px 8px;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.03em;
}
.day-popover-list { list-style: none; margin: 0; padding: 6px 0; }
.day-popover-list li {
  padding: 8px 16px;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s;
  flex-direction: column;
  align-items: stretch;
  display: flex;
}
.day-popover-list li:hover { background: var(--laurel-bg); }
.day-popover-main { display: flex; align-items: center; gap: 9px; width: 100%; }
.day-popover-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.day-popover-amount {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--ink-soft);
  font-size: 12px;
}
.day-popover-reads { display: flex; flex-direction: column; gap: 2px; margin: 4px 0 0 18px; }
.day-popover-read {
  font-size: 12px;
  color: var(--laurel-dark);
  border-bottom: none;
  font-style: italic;
}
.day-popover-read:hover { color: var(--ink); }

/* ===== Buttons ===== */
.btn-primary, .btn-secondary, .btn-danger {
  font-family: var(--body);
  font-size: 14px;
  letter-spacing: 0.05em;
  padding: 9px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}
.btn-primary:hover {
  background: var(--laurel-dark);
  border-color: var(--laurel-dark);
}
.btn-secondary {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--ink);
}
.btn-secondary:hover {
  background: var(--laurel-bg);
  border-color: var(--laurel);
}
.btn-danger {
  background: transparent;
  border-color: var(--oxblood);
  color: var(--oxblood);
}
.btn-danger:hover { background: var(--oxblood-bg); }

/* ===== Modals ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(33, 30, 25, 0.46);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  animation: fadeIn 0.25s ease;
}
.modal.open { display: flex; }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 40px;
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
  position: relative;
  animation: slideUp 0.3s ease;
}
.modal-content.modal-large { max-width: 680px; }

@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: transparent;
  border: none;
  font-size: 26px;
  color: var(--ink-mute);
  cursor: pointer;
  line-height: 1;
  padding: 6px 10px;
  border-radius: var(--radius);
  transition: all 0.2s;
  font-family: var(--display);
}
.modal-close:hover { color: var(--ink); background: var(--laurel-bg); }

.modal-content h3 {
  font-family: var(--display);
  font-size: 26px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.03em;
  margin-bottom: 4px;
}

.modal-sub {
  color: var(--ink-soft);
  font-style: italic;
  font-size: 14px;
  margin-bottom: 20px;
}

/* ===== Forms ===== */
.form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 16px;
}

.form label, .form fieldset legend {
  font-size: 11.5px;
  color: var(--ink-soft);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 6px;
  display: block;
}
.form label { display: flex; flex-direction: column; gap: 6px; }
.form .hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-style: italic;
  color: var(--ink-mute);
}

.form input[type="text"],
.form input[type="number"],
.form input[type="date"],
.form input[type="time"],
.form select,
.form textarea {
  font-family: var(--body);
  font-size: 15.5px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.2s;
  font-weight: 400;
}
.form input:focus, .form textarea:focus, .form select:focus { border-color: var(--laurel); }
.form textarea {
  resize: vertical;
  min-height: 110px;
  line-height: 1.7;
}

.form-row { display: flex; gap: 12px; }
.flex-1 { flex: 1; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 16px;
}
.form-actions .btn-danger { margin-right: auto; }

/* Studies picker in event modal */
.studies-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}
.studies-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  color: var(--ink-soft);
  transition: all 0.15s;
}
.studies-picker-row:hover { border-color: var(--laurel); color: var(--ink); }
.studies-picker-row input { margin: 0; accent-color: var(--laurel-dark); width: 16px; height: 16px; }
.studies-picker-row.checked { background: var(--laurel-bg); border-color: var(--laurel); color: var(--ink); }
.studies-picker-meta { font-style: italic; color: var(--ink-mute); font-size: 12px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--ink);
  color: var(--bg);
  padding: 11px 22px;
  border-radius: var(--radius);
  font-family: var(--body);
  font-size: 14px;
  letter-spacing: 0.04em;
  box-shadow: var(--shadow-modal);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  z-index: 200;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Responsive ===== */
@media (max-width: 720px) {
  body { padding: 24px 16px 60px; }
  .header { grid-template-columns: 1fr; gap: 16px; }
  .header-left { text-align: center; }
  .tabs { flex-wrap: wrap; }
  .sync-status { justify-self: center; }
  .brand-title { font-size: 48px; }
  .section-title { font-size: 24px; }
  .section-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .modal-content { padding: 28px 22px; }
  .cal-day { min-height: 68px; }
  .cal-month-label { font-size: 18px; min-width: 0; }
  .library-card-title { font-size: 21px; }
  .filter-group-label { min-width: 0; width: 100%; }
}
