:root {
  --bg: #f2f2f7;
  --panel: #ffffff;
  --ink: #1c1c1e;
  --muted: #8e8e93;
  --line: rgba(60,60,67,0.18);
  --brand: #007aff;
  --brand-dark: #0063d1;
  --green: #34c759;
  --red: #ff3b30;
  --amber: #ff9500;
  --shadow: 0 2px 8px rgba(0,0,0,0.07), 0 0 1px rgba(0,0,0,0.05);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  background: rgba(255,255,255,0.85);
  backdrop-filter: saturate(200%) blur(20px);
  -webkit-backdrop-filter: saturate(200%) blur(20px);
  border-bottom: 1px solid rgba(60,60,67,0.12);
  padding: 0 24px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  flex-shrink: 0;
  letter-spacing: -0.2px;
}
.brand .logo { color: var(--brand); font-size: 20px; }
.nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex: 1;
}
.nav::-webkit-scrollbar { display: none; }
.nav-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn:hover { background: rgba(0,0,0,0.05); color: var(--ink); }
.nav-btn.active { background: var(--brand); color: #fff; }

/* ── Layout ─────────────────────────────────────────────── */
main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 24px 88px;
}
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 26px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.4px;
  line-height: 1.2;
}
.page-head p { margin: 3px 0 0; color: var(--muted); font-size: 14px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.12s, opacity 0.12s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:hover { background: var(--bg); }
.btn:active { opacity: 0.7; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { color: var(--red); border-color: rgba(255,59,48,0.25); }
.btn-danger:hover { background: rgba(255,59,48,0.06); }
.btn-sm { padding: 5px 12px; font-size: 13px; border-radius: 8px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: rgba(0,0,0,0.05); }

/* ── Cards ──────────────────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.card .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.card .value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 4px;
  letter-spacing: -0.6px;
  line-height: 1.1;
}
.card .value.green { color: var(--green); }
.card .value.red { color: var(--red); }

/* ── Panel / Table ──────────────────────────────────────── */
.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; }
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,0.012);
}
td { border-bottom: 1px solid var(--line); font-size: 14px; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: rgba(0,0,0,0.02); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: nowrap; white-space: nowrap; }

.empty {
  padding: 56px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.empty .big { font-size: 48px; opacity: .35; margin-bottom: 8px; }

/* ── Filter bar / Sub-tabs ──────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-btn {
  border: none;
  background: rgba(118,118,128,0.12);
  color: var(--muted);
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.filter-btn:hover { background: rgba(118,118,128,0.2); color: var(--ink); }
.filter-btn.active { background: var(--brand); color: #fff; }
.filter-btn.active .muted { color: rgba(255,255,255,0.75); }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge.paid  { background: rgba(52,199,89,0.12); color: var(--green); }
.badge.unpaid{ background: rgba(255,59,48,0.10); color: var(--red); }
.badge.draft { background: rgba(142,142,147,0.12); color: var(--muted); }
.badge.quote { background: rgba(0,122,255,0.10); color: var(--brand); }

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.38);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px 24px;
  z-index: 50;
  overflow-y: auto;
}
.modal {
  background: var(--panel);
  border-radius: 18px;
  width: 100%;
  max-width: 640px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.22), 0 0 1px rgba(0,0,0,0.06);
  margin: auto 0;
}
.modal.wide { max-width: 820px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.2px; }
.modal-body { padding: 22px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.close-x {
  border: none;
  background: rgba(120,120,128,0.14);
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  transition: background 0.12s;
  flex-shrink: 0;
}
.close-x:hover { background: rgba(120,120,128,0.24); }

/* ── Forms ──────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--ink);
}
.input,
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px; /* 16px prevents iOS zoom on focus */
  font-family: inherit;
  background: var(--panel);
  color: var(--ink);
  transition: border-color 0.12s, box-shadow 0.12s;
  -webkit-appearance: none;
  appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath fill='%238e8e93' d='M5 6L0 0h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.input:focus,
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.14);
}
.field textarea { resize: vertical; line-height: 1.5; }
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; min-width: 0; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ── Invoice lines ──────────────────────────────────────── */
.lines-table { table-layout: fixed; }
.lines-table th, .lines-table td { padding: 8px 6px; overflow: hidden; }
.lines-table input, .lines-table select { width: 100%; min-width: 0; padding: 7px 8px; font-size: 14px; }
.lines-table .num input { text-align: right; }
.line-total { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.lines-table td .btn { padding: 5px 8px; }

.totals { margin-top: 18px; margin-left: auto; width: 280px; }
.totals .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.totals .row.grand {
  border-top: 1.5px solid var(--ink);
  margin-top: 6px;
  padding-top: 10px;
  font-size: 18px;
  font-weight: 700;
}

/* ── Toast ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(28,28,30,0.92);
  backdrop-filter: blur(16px) saturate(200%);
  -webkit-backdrop-filter: blur(16px) saturate(200%);
  color: #fff;
  padding: 12px 20px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.22);
  z-index: 200;
  white-space: nowrap;
}

/* ── Auth ───────────────────────────────────────────────── */
.auth-wrap {
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 36px;
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.auth-error {
  background: rgba(255,59,48,0.08);
  color: var(--red);
  border: 1px solid rgba(255,59,48,0.22);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  margin: 0 0 16px;
}

/* ── Misc ───────────────────────────────────────────────── */
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }

/* ── Invoice detail ─────────────────────────────────────── */
.inv-detail h2 { margin: 0 0 4px; }
.inv-meta { display: flex; gap: 48px; margin: 20px 0; flex-wrap: wrap; }
.inv-meta .block .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.inv-meta .block .v { font-weight: 500; margin-top: 2px; }

/* ── Tablet (≤768px) ────────────────────────────────────── */
@media (max-width: 768px) {
  main { padding: 20px 16px 88px; }
  .topbar { gap: 10px; padding: 0 16px; }
  .page-head { flex-direction: column; gap: 12px; }
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 14px 16px; }
  .card .value { font-size: 22px; }
  .totals { width: 100%; }
  .inv-meta { gap: 20px; }
  table { font-size: 13px; }
  th, td { padding: 10px 12px; }
}

/* ── Mobile (≤540px) ────────────────────────────────────── */
@media (max-width: 540px) {
  .topbar { height: 52px; gap: 8px; padding: 0 12px; }
  main { padding: 16px 12px 80px; }

  .page-head h1 { font-size: 22px; }

  /* Taflan flettist lárétt */
  .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .panel table { min-width: 480px; }

  /* Modal → bottom sheet */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    border-radius: 20px 20px 0 0;
    max-width: 100%;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
  }
  .modal.wide { max-width: 100%; }
  .modal-body { overflow-y: auto; flex: 1; }

  /* Form dálkar → ein lína */
  .field-row { flex-direction: column; gap: 0; }

  /* Fela netfang í header */
  #user-area > span { display: none; }

  .cards { gap: 8px; }
  .card { padding: 12px 14px; }
  .card .value { font-size: 20px; }

  .totals { width: 100%; }
  .filter-btn { font-size: 13px; padding: 6px 13px; }
}

/* ── Prentun ────────────────────────────────────────────── */
#print-area { display: none; }

@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; }
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; background: #fff; }
  @page { margin: 18mm; }
}
