/* Daybook — ledger-inspired design system
   Ink teal + paper + ochre/brick/sage accents. Rows over cards. */

:root {
  --ink: #1B2A2E;
  --ink-soft: #4A5A5C;
  --paper: #F1F0EA;
  --paper-raised: #FFFFFF;
  --line: #D9D5C9;
  --amber: #C98A2C;
  --brick: #B44432;
  --sage: #4B7A63;
  --radius: 10px;
  --font-head: Georgia, 'Iowan Old Style', 'Palatino Linotype', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

/* Keep the HTML hidden attribute authoritative even when a component sets display. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

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

/* Topbar owns the top safe area. This avoids iOS standalone content sitting under the status bar. */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 62px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--line);
  background: rgba(241, 240, 234, 0.98);
  position: sticky;
  top: 0;
  z-index: 15;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-mark {
  font-family: var(--font-head);
  font-weight: 700;
  background: var(--ink);
  color: var(--paper);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  flex: 0 0 auto;
}

.brand-name {
  font-family: var(--font-head);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.topbar-date {
  font-size: 13px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Views */
.view {
  flex: 1;
  padding-top: 14px;
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: 28px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

/* Ledger summary hero */
.ledger-summary {
  padding: 14px 2px 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.ledger-summary-label {
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 3px;
}
.ledger-summary-amount {
  font-family: var(--font-head);
  font-size: 38px;
  font-weight: 700;
  line-height: 1.08;
  font-variant-numeric: tabular-nums;
}
.ledger-summary-sub {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 3px;
}

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.section-row h2 {
  font-family: var(--font-head);
  font-size: 18px;
  margin: 0;
  font-weight: 700;
}

.btn-add {
  border: none;
  background: var(--ink);
  color: var(--paper);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 700;
}
.btn-add.small { padding: 5px 12px; font-size: 13px; }

.btn-text {
  border: none;
  background: none;
  color: var(--amber);
  font-size: 13px;
  font-weight: 600;
  padding: 4px;
}

/* Ledger rows */
.ledger {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ledger-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 2px;
  border-bottom: 1px solid var(--line);
}

.ledger-row .marker {
  width: 4px;
  align-self: stretch;
  border-radius: 2px;
  flex-shrink: 0;
  min-height: 36px;
}
.marker.ok { background: var(--sage); }
.marker.soon { background: var(--amber); }
.marker.overdue { background: var(--brick); }

.ledger-row .details {
  flex: 1;
  min-width: 0;
}
.ledger-row .name {
  font-size: 16px;
  font-weight: 600;
}
.ledger-row .meta {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.ledger-row .meta.warn { color: var(--brick); font-weight: 600; }
.ledger-row .meta.soon { color: var(--amber); font-weight: 600; }

.ledger-row .amount {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ledger-row.paid { opacity: 0.55; }
.ledger-row.paid .name { text-decoration: line-through; }

/* Empty states */
.empty-state {
  text-align: center;
  padding: 34px 18px;
  color: var(--ink-soft);
}
.empty-state.small { padding: 18px 8px; }
.empty-state p { margin: 4px 0; }
.empty-sub { font-size: 13px; max-width: 320px; margin: 6px auto 0; line-height: 1.45; }

/* Sheets */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(27, 42, 46, 0.45);
  display: flex;
  align-items: flex-end;
  z-index: 30;
  padding-top: env(safe-area-inset-top, 0px);
}
.sheet {
  background: var(--paper-raised);
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  border-radius: 18px 18px 0 0;
  padding: 10px max(18px, env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px));
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 12px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  margin: 6px auto 14px;
}
.sheet h3 {
  font-family: var(--font-head);
  font-size: 19px;
  margin: 0 0 16px;
}
.field {
  display: block;
  margin-bottom: 14px;
}
.field span {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
.field input, .field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  background: var(--paper);
  color: var(--ink);
}
.field input:focus, .field select:focus {
  outline: 2px solid var(--ink);
  outline-offset: -1px;
}

.sheet-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  gap: 10px;
}
.sheet-actions-right {
  display: flex;
  gap: 10px;
  margin-left: auto;
}
.btn-primary {
  border: none;
  background: var(--ink);
  color: var(--paper);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
}
.btn-ghost {
  border: none;
  background: none;
  color: var(--ink-soft);
  padding: 10px 8px;
  font-size: 15px;
  font-weight: 600;
}
#deleteBillBtn { color: var(--brick); }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 40;
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
  text-align: center;
}

/* Focus visibility */
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

@media (max-width: 390px) {
  .brand-name { font-size: 20px; }
  .topbar-date { font-size: 12px; }
  .ledger-summary-amount { font-size: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
