/* ─── Design tokens ───────────────────────────────────── */
:root {
  --bg:           #f5f4f1;
  --surface:      #ffffff;
  --border:       #e5e2dd;
  --border-mid:   #d0cdc8;
  --text:         #1a1917;
  --text-2:       #6b6560;
  --text-3:       #a8a39d;
  --green:        #15803d;
  --green-bg:     #f0fdf4;
  --blue:         #1d4ed8;
  --blue-bg:      #eff6ff;
  --indigo:       #4338ca;
  --red:          #b91c1c;
  --red-bg:       #fef2f2;
  --radius-sm:    6px;
  --radius:       10px;
  --radius-lg:    14px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.06), 0 1px 8px rgba(0,0,0,.03);
  --shadow:       0 2px 8px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

/* ─── Base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
.hidden { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

/* iOS: prevent zoom on input focus */
input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="search"],
input[type="tel"],
select,
textarea { font-size: 16px !important; }

/* ─── Page wrapper ──────────────────────────────────────── */
.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px calc(56px + env(safe-area-inset-bottom) + 24px);
}

@media (min-width: 640px) {
  .page { padding-bottom: 60px; }
}

/* ─── Typography ────────────────────────────────────────── */
.page-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 2px;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}

/* ─── Section cap ───────────────────────────────────────── */
.section-cap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.section-cap-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
}
.section-cap-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── Card ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card-p { padding: 16px; }

/* ─── Inputs & Forms ────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}

input:not([type="radio"]):not([type="checkbox"]), select, textarea {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
  line-height: 1.4;
}

input:not([type="radio"]):not([type="checkbox"]):focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(67,56,202,.1);
}

input::placeholder, textarea::placeholder { color: var(--text-3); }
input:disabled, select:disabled, textarea:disabled {
  background: #f0eeeb;
  color: var(--text-2);
  cursor: default;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b6560' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ─── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
  line-height: 1;
  text-decoration: none;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); opacity: 0.85; }

.btn-primary  { background: var(--indigo); color: #fff; }
.btn-success  { background: var(--green);  color: #fff; }
.btn-dark     { background: var(--text);   color: #fff; }
.btn-outline  { background: var(--surface); border: 1.5px solid var(--border-mid); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-ghost    { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: rgba(0,0,0,.05); }
.btn-danger   { background: var(--red-bg); color: var(--red); }

.btn-sm { font-size: 13px; padding: 7px 12px; min-height: 36px; }
.btn-xs { font-size: 12px; padding: 5px 10px; min-height: 30px; }

/* ─── Money numbers ─────────────────────────────────────── */
.money { font-variant-numeric: tabular-nums; }
.money-green { color: var(--green); font-weight: 700; }
.money-blue  { color: var(--blue);  font-weight: 600; }
.money-muted { color: var(--text-2); font-weight: 500; }
.money-label { font-size: 10px; font-weight: 500; color: var(--text-3); margin-left: 2px; vertical-align: baseline; }

/* ─── Modals / Sheets ───────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 640px) {
  .overlay { align-items: center; padding: 24px; }
}

.sheet {
  background: var(--surface);
  width: 100%;
  max-height: 92dvh;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

@media (min-width: 640px) {
  .sheet {
    max-width: 540px;
    border-radius: var(--radius-lg);
    max-height: 88dvh;
  }
  .sheet-lg { max-width: 680px; }
}

.sheet-handle {
  width: 36px; height: 4px;
  background: var(--border-mid);
  border-radius: 2px;
  margin: 10px auto 0;
}

@media (min-width: 640px) { .sheet-handle { display: none; } }

.sheet-header {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-title { font-size: 16px; font-weight: 700; }
.sheet-body  { padding: 20px; }
.sheet-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}

.sheet-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: none;
  background: #f0eeeb;
  color: var(--text-2);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
}
.sheet-close:hover { background: var(--border); }

/* ─── Sale card ──────────────────────────────────────────── */
.sale-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s;
  animation: fadeUp .2s ease-out both;
}
.sale-card:hover { border-color: var(--border-mid); }

.sale-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.sale-amounts {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}

.sale-net-amount  { font-size: 20px; }
.sale-adf-amount  { font-size: 14px; }
.sale-total-amount{ font-size: 15px; }

.sale-meta { display: flex; flex-direction: column; gap: 3px; }
.sale-meta-row { font-size: 13px; color: var(--text-2); }
.sale-meta-row strong { color: var(--text); font-weight: 600; }

.sale-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

@media (min-width: 640px) {
  .sale-card-inner { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
  .sale-actions { flex-direction: column; margin-top: 0; padding-top: 0; border-top: none; align-items: flex-end; flex-shrink: 0; }
}

/* ─── Filters bar ────────────────────────────────────────── */
.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
@media (min-width: 640px) {
  .filters { display: flex; flex-wrap: wrap; gap: 8px; }
  .filters input[type="search"] { width: 200px; flex-shrink: 0; }
  .filters select { width: auto; min-width: 130px; }
}

/* ─── Stats grid ─────────────────────────────────────────── */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); margin-bottom: 4px; }
.stat-value { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; color: var(--text); }
.stat-sub   { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ─── Animations ─────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Auth pages ─────────────────────────────────────────── */
.auth-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}
.auth-card { width: 100%; max-width: 400px; }
.auth-logo  { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; color: var(--text); }
.auth-sub   { font-size: 14px; color: var(--text-2); margin-top: 4px; }
.auth-switch { text-align: center; font-size: 13px; color: var(--text-2); margin-top: 16px; }
.auth-switch a { color: var(--indigo); font-weight: 600; text-decoration: none; }
.auth-error { font-size: 13px; color: var(--red); min-height: 18px; }

/* ─── Responsive stat grids ──────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
@media (max-width: 479px) {
  .stat-grid { grid-template-columns: 1fr; }

  /* stack 2-col form rows on very small phones */
  .form-row-2 { grid-template-columns: 1fr !important; }

  /* tighten page horizontal padding */
  .page { padding-left: 12px; padding-right: 12px; }

  /* prevent fin-num overflow */
  .fin-num { font-size: 18px; }
  .stat-value { font-size: 20px; }
}

/* ─── Top nav ─────────────────────────────────────────────── */
.top-nav {
  background: rgba(255,255,255,.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}
.nav-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
  height: 52px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.nav-desktop-links {
  display: none;
  align-items: center;
  gap: 2px;
  flex: 1;
  justify-content: center;
}
@media (min-width: 640px) {
  .nav-desktop-links { display: flex; }
  .nav-mobile-btn    { display: none !important; }
}
.nav-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: var(--bg); color: var(--text); font-weight: 700; }

.nav-mobile-menu {
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow: hidden;
  max-height: 0;
  transition: max-height .22s ease;
}
.nav-mobile-menu.open { max-height: 560px; }
.nav-mobile-link {
  display: block;
  padding: 13px 20px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  -webkit-tap-highlight-color: transparent;
}
.nav-mobile-link.active { color: var(--indigo); font-weight: 700; background: var(--blue-bg); }

/* ─── Bottom tab bar ─────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  z-index: 40;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 640px) { .bottom-nav { display: none; } }
.bottom-nav-inner {
  display: flex;
  align-items: stretch;
  height: 56px;
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-3);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .01em;
  transition: color .12s;
  -webkit-tap-highlight-color: transparent;
  padding-top: 4px;
}
.bottom-nav-item.active { color: var(--indigo); }
.bottom-nav-item svg { flex-shrink: 0; }

/* ─── Quick link cards ───────────────────────────────────── */
.quick-link-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  transition: border-color .15s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
}
.quick-link-card:hover { border-color: var(--border-mid); box-shadow: var(--shadow); }
.quick-link-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.quick-link-body { flex: 1; min-width: 0; }
.quick-link-title { font-size: 14px; font-weight: 700; color: var(--text); line-height: 1.2; }
.quick-link-sub   { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.quick-link-arrow { color: var(--text-3); flex-shrink: 0; }
