:root {
  --bg: #ffffff;
  --bg-soft: #f7f5f2;
  --bg-sunken: #f1efe9;
  --border: #e7e3da;
  --border-strong: #d8d2c5;
  --text: #24211c;
  --text-dim: #6b665c;
  --text-faint: #a49e91;

  --accent: #cb6a4b;
  --accent-dark: #a8543a;
  --accent-bright: #d97757;
  --accent-soft: #f7e6df;

  --red: #c13b2a;
  --red-soft: #fbe6e2;
  --green: #4f8f68;
  --green-soft: #e6f2ea;

  --shadow: rgba(36, 33, 28, 0.08);
  --shadow-strong: rgba(36, 33, 28, 0.16);

  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, Helvetica, Arial, sans-serif;
  --font-ledger: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
}

body {
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
}

/* Topbar */

.topbar {
  padding: calc(env(safe-area-inset-top) + 18px) 20px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

/* Main / views */

main {
  flex: 1;
  padding: 22px 20px calc(96px + env(safe-area-inset-bottom));
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fade-in 0.2s ease;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Status plate */

.status-plate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 auto 18px;
  padding: 6px 16px;
  width: fit-content;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-family: var(--font-ledger);
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  background: var(--bg-soft);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
}

.status-plate.active .status-dot { background: var(--green); box-shadow: 0 0 6px rgba(79, 143, 104, 0.5); }
.status-plate.active { color: var(--text); border-color: var(--green); background: var(--green-soft); }
.status-plate.overdue .status-dot { background: var(--red); box-shadow: 0 0 8px rgba(193, 59, 42, 0.5); }
.status-plate.overdue { color: var(--red); border-color: var(--red); background: var(--red-soft); }

/* Clock */

.clock-frame {
  text-align: center;
  margin-bottom: 22px;
}

.clock {
  font-family: var(--font-ledger);
  font-variant-numeric: tabular-nums;
  font-size: 54px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}

.clock.overdue {
  color: var(--red);
}

.clock-caption {
  margin-top: 4px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--text-faint);
}

/* CTA button */

.gavel-btn {
  display: block;
  width: 100%;
  padding: 16px;
  margin-bottom: 26px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 1px 2px var(--shadow), 0 6px 16px -6px var(--shadow-strong);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.15s ease;
}

.gavel-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 2px var(--shadow);
}

.gavel-btn:hover {
  background: var(--accent-dark);
}

.gavel-btn.active-session {
  background: var(--red);
}

.gavel-btn.active-session:hover {
  background: #a12f21;
}

.gavel-btn.small {
  width: auto;
  padding: 10px 22px;
  margin: 12px 0 0;
  font-size: 13px;
  border-radius: 10px;
}

/* Meters */

.meters {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 30px;
}

.meter-label {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.meter-readout {
  font-family: var(--font-ledger);
  color: var(--text-faint);
}

.meter-track {
  height: 8px;
  border-radius: 6px;
  background: var(--bg-sunken);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  background: var(--green);
  transition: width 0.4s ease, background-color 0.4s ease;
}

/* Today log */

.today-log h3,
.day-list-wrap h3,
.settings-form h3,
.data-actions h3 {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.session-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.session-list li {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  color: var(--text-dim);
}

.session-list li .s-time {
  font-family: var(--font-ledger);
  color: var(--text);
}

.session-list li .s-dur {
  font-family: var(--font-ledger);
  color: var(--accent-dark);
  font-weight: 600;
}

.empty-note {
  color: var(--text-faint) !important;
  font-style: italic;
  justify-content: center !important;
  border-bottom: none !important;
}

/* History view */

.trends {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}

.trend-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 8px;
  text-align: center;
  background: var(--bg-soft);
}

.trend-value {
  font-family: var(--font-ledger);
  font-size: 17px;
  font-weight: 700;
  color: var(--accent-dark);
}

.trend-label {
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-top: 4px;
}

.heatmap-wrap {
  margin-bottom: 26px;
}

.heatmap-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-dim);
}

.heatmap-nav button {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--accent-dark);
  border-radius: 7px;
  width: 28px;
  height: 28px;
  font-size: 15px;
}

.heatmap-nav button:disabled {
  opacity: 0.35;
}

.heatmap-scroll {
  overflow-x: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-soft);
}

.heatmap {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 13px);
  gap: 3px;
  width: max-content;
}

.hm-cell {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
}

.hm-cell.hm-void { background: transparent; border-color: transparent; }
.hm-cell.hm-0 { background: var(--bg-sunken); }
.hm-cell.hm-1 { background: #f0d6c8; border-color: #e8c3ae; }
.hm-cell.hm-2 { background: #e5ac8d; border-color: #dd9a76; }
.hm-cell.hm-3 { background: var(--accent); border-color: var(--accent-dark); }
.hm-cell.hm-4 { background: var(--accent-dark); border-color: #8a4530; }
.hm-cell.hm-5 { background: var(--red); border-color: #9c2f21; box-shadow: 0 0 0 1px rgba(193, 59, 42, 0.25); }
.hm-cell.hm-today { outline: 1.5px solid var(--text); outline-offset: 1px; }
.hm-cell:not(.hm-void) { cursor: pointer; }

.heatmap-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 10px;
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.legend-swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  display: inline-block;
  margin: 0 2px;
}

.swatch-0 { background: var(--bg-sunken); }
.swatch-1 { background: #f0d6c8; }
.swatch-2 { background: #e5ac8d; }
.swatch-3 { background: var(--accent); }
.swatch-4 { background: var(--accent-dark); }

.day-list {
  display: flex;
  flex-direction: column;
}

.day-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  color: var(--text);
  text-align: left;
  width: 100%;
}

.day-row .d-date {
  font-size: 13.5px;
}

.day-row .d-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.day-row .d-total {
  font-family: var(--font-ledger);
  color: var(--accent-dark);
  font-weight: 600;
  font-size: 13px;
}

.day-row .d-count {
  font-size: 11px;
  color: var(--text-faint);
}

.link-btn {
  display: block;
  margin: 14px auto 0;
  background: none;
  border: none;
  color: var(--accent-dark);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Settings */

.settings-form {
  margin-bottom: 30px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.field input {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 16px;
  font-family: var(--font-ledger);
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.checkbox-field input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.settings-actions .gavel-btn.small {
  margin: 0;
}

.settings-actions .link-btn {
  margin: 0;
}

.save-note {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--green);
  margin-top: 8px;
  min-height: 14px;
}

.hint {
  font-size: 12.5px;
  color: var(--text-faint);
  line-height: 1.5;
  margin: 0 0 14px;
}

.data-actions {
  display: flex;
  flex-direction: column;
}

.ledger-btn {
  display: block;
  text-align: center;
  padding: 13px;
  margin-bottom: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  position: relative;
}

.ledger-btn.danger {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-soft);
}

.import-label input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* Bottom navigation */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  max-width: 480px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}

.bottom-nav .tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  padding: 6px 4px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  border-radius: 10px;
  transition: color 0.15s ease;
}

.bottom-nav .nav-icon {
  width: 23px;
  height: 23px;
}

.bottom-nav .tab.active {
  color: var(--accent-dark);
}

/* Modals */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(36, 33, 28, 0.45);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  padding: 18px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px var(--shadow-strong);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-head h3 {
  margin: 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 22px;
  line-height: 1;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 6px 20px var(--shadow-strong);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 600px) {
  .clock { font-size: 62px; }
}
