/* base.css: design tokens, typography and shared components (admin app and customer page). */

:root {
  --ink: #201C19;
  --gold: #D4AF5A;       /* only on dark backgrounds */
  --gold-text: #80621A;  /* gold labels/links on light backgrounds (4.8:1 on panel, 5.3:1 on cream) */
  --cream: #F9F6F0;
  --panel: #F0ECE2;
  --line: #DDD6C8;       /* dividers (decorative) */
  --field: #8A8072;      /* borders of inputs and controls: at least 3:1 on white, cream and panel */
  --muted: #6B6359;
  --oxblood: #6E1A1E;
  --ok: #2F6B3A;
  --white: #FFFFFF;

  --font-head: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --font-body: 'Jost', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  --radius: 8px;
  --tap: 48px;
  --control: 52px;
  --gap: 16px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

img { max-width: 100%; height: auto; }

h1, h2, h3 { font-family: var(--font-head); font-weight: 600; line-height: 1.15; margin: 0 0 12px; }
/* Cormorant uses old-style numbers (0 looks like o); use standard ones for anything with numbers. */
h1, h2, h3, .num, .amount, .app-header .title { font-variant-numeric: lining-nums tabular-nums; }
h1 { font-size: 32px; }
h2 { font-size: 24px; }
h3 { font-size: 20px; }
p { margin: 0 0 12px; }

a { color: var(--gold-text); text-underline-offset: 3px; }

.label {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--gold-text);
  margin: 0 0 8px;
}

.muted { color: var(--muted); }
.small { font-size: 15px; }
.center { text-align: center; }
.stack > * + * { margin-top: var(--gap); }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid var(--gold-text); outline-offset: 2px; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--control); padding: 0 20px;
  border: 2px solid var(--ink); border-radius: var(--radius);
  background: var(--ink); color: var(--cream);
  font: 500 18px/1.2 var(--font-body);
  text-decoration: none; cursor: pointer;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.45; cursor: default; transform: none; }
.btn-block { display: flex; width: 100%; }
.btn-secondary { background: transparent; color: var(--ink); }
.btn-gold { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.btn-danger { background: transparent; color: var(--oxblood); border-color: var(--oxblood); }
.btn-link {
  background: none; border: 0; padding: 0 4px; min-height: var(--tap);
  color: var(--gold-text); font: 500 18px var(--font-body); text-decoration: underline;
  text-underline-offset: 3px; cursor: pointer;
}
.btn-big { min-height: 72px; font-size: 20px; }

/* ---------- forms ---------- */

.field { display: block; margin-bottom: var(--gap); }
.field > span, .field > label { display: block; font-weight: 500; margin-bottom: 6px; }
.hint { display: block; color: var(--muted); font-size: 15px; margin: 6px 0 0; }
.input.money { max-width: 180px; text-align: right; font-variant-numeric: tabular-nums; }
.input.search {
  padding-left: 44px;
  background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236B6359' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.5-3.5'/%3E%3C/svg%3E") no-repeat 14px center;
}
select.input {
  padding-right: 40px;
  background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23201C19' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 14px center;
}

/* on/off switch */
.toggle-row {
  display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 8px 0;
  cursor: pointer; position: relative;
}
.toggle-row .grow { flex: 1; }
.toggle-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-row .switch {
  flex: none; width: 56px; height: 32px; border-radius: 16px; background: var(--field); position: relative;
  transition: background 0.15s;
}
.toggle-row .switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--white); box-shadow: 0 1px 3px rgba(0,0,0,0.25); transition: transform 0.15s;
}
.toggle-row input:checked + .switch { background: var(--ok); }
.toggle-row input:checked + .switch::after { transform: translateX(24px); }
.toggle-row input:focus-visible + .switch { outline: 3px solid var(--gold-text); outline-offset: 2px; }

/* segmented control */
.segmented {
  display: flex; background: var(--panel); border: 1px solid var(--field); border-radius: var(--radius); padding: 3px; gap: 3px;
}
.segmented button {
  flex: 1; min-height: var(--tap); border: 0; border-radius: 6px; background: transparent; color: var(--ink);
  font: 500 17px var(--font-body); cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--cream); }

/* square icon button (reorder, delete) */
.icon-btn {
  flex: none; width: var(--tap); height: var(--tap); border-radius: var(--radius);
  border: 1px solid var(--field); background: var(--white); color: var(--ink);
  font: 500 20px/1 var(--font-body); cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn.danger { color: var(--oxblood); }
.input, select.input, textarea.input {
  display: block; width: 100%;
  min-height: var(--control); padding: 12px 14px;
  border: 1px solid var(--field); border-radius: var(--radius);
  background-color: var(--white); color: var(--ink);
  font: 400 18px/1.4 var(--font-body); /* 16px+ prevents iOS zoom on focus */
  -webkit-appearance: none; appearance: none;
}
textarea.input { min-height: 120px; resize: vertical; }
.input:focus { border-color: var(--ink); outline: 2px solid var(--ink); outline-offset: 0; }

/* ---------- cards and lists ---------- */

.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: var(--gap);
}
.card + .card { margin-top: 12px; }

.list { list-style: none; margin: 0; padding: 0; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.list-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px; padding: 12px var(--gap);
  color: inherit; text-decoration: none;
}
.list-row .grow { flex: 1; min-width: 0; }
.list-row .chev { color: var(--muted); font-size: 22px; }

/* ---------- badges ---------- */

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font: 600 13px/1.6 var(--font-body); letter-spacing: 0.04em; white-space: nowrap;
  border: 1px solid transparent;
}
.badge-draft { background: var(--panel); color: var(--muted); border-color: var(--line); }
.badge-sent { background: transparent; color: var(--gold-text); border-color: var(--gold-text); }
.badge-viewed { background: var(--panel); color: var(--muted); }
.badge-overdue { background: var(--oxblood); color: var(--cream); }
.badge-progress { background: var(--ink); color: var(--cream); }
.badge-ready { background: var(--ink); color: var(--gold); }
.badge-paid { background: var(--ok); color: var(--cream); }
.badge-closed { background: var(--panel); color: var(--muted); text-decoration: line-through; }

/* ---------- empty state, spinner ---------- */

.empty { text-align: center; padding: 32px var(--gap); color: var(--muted); }
.empty h2 { color: var(--ink); }

.spinner {
  width: 32px; height: 32px; margin: 32px auto;
  border: 3px solid var(--line); border-top-color: var(--ink); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toast ---------- */

.toast-wrap {
  position: fixed; left: 0; right: 0; z-index: 100;
  bottom: calc(88px + var(--safe-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 0 var(--gap); pointer-events: none;
}
.toast {
  max-width: 480px; padding: 14px 18px; border-radius: var(--radius);
  background: var(--ink); color: var(--cream); font-weight: 500;
  box-shadow: 0 6px 24px rgba(32, 28, 25, 0.25);
  animation: toast-in 0.2s ease-out;
}
.toast-error { background: var(--oxblood); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- bottom sheet / dialog ---------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(32, 28, 25, 0.5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade-in 0.15s ease-out;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
  background: var(--cream); border-radius: 16px 16px 0 0;
  padding: 24px var(--gap) calc(var(--gap) + var(--safe-bottom));
  animation: sheet-in 0.2s ease-out;
}
.sheet .actions { display: grid; gap: 12px; margin-top: 20px; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0.6; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
