/*
 * Hisaab UI layer - loaded AFTER app.css (public/index.html). Presentation only: no markup, data, route or behaviour is changed here.
 * Design tokens first, then phone / tablet / desktop refinements, tested at 320, 375, 390, 430, 768, 1024, 1366 and 1440 px.
 *   phone  (<= 700 px): compact header, two-column quick actions, even KPI cards, charts sized for the screen, content that clears the bottom bar
 *   tablet (<= 900 px): the bottom bar tidied (it is shown up to 900 px)
 *   all  : aligned digits for money, visible keyboard focus, dropdowns kept inside the screen
 */
:root {
  --ui-safe-t: env(safe-area-inset-top, 0px);
  --ui-safe-b: env(safe-area-inset-bottom, 0px);
  --ui-bar: 58px;                  /* height of the phone bottom bar, without the safe area */
  --ui-tap: 40px;                  /* smallest comfortable touch target in the header */
}

/* ---------- numbers: digits line up wherever money is shown ---------- */
.stat .val, .big, .delta, .tbl td.r, .tbl th.r, .tbl td.num, .tbl th.num, .totals td, .tot td { font-variant-numeric: tabular-nums; }
.tbl td.r, .tbl th.r, .tbl td.num, .tbl th.num { text-align: right; }

/* ---------- keyboard and focus ---------- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible { outline: 2px solid var(--blue, #2563eb); outline-offset: 2px; }
:where(.btn, .ctile, .bb-tab, .bb-plus):focus-visible { outline-offset: 1px; }

/* ---------- Create menu and search box ---------- */
.create-search { width: 100%; margin: 0 0 12px; }
.palette-list { max-height: min(60vh, 460px); overflow-y: auto; }
.palette-list .pi { gap: 10px; }
.palette-list .pi-sub { margin-left: 4px; color: var(--muted); font-weight: 400; }
.palette-hint { padding: 8px 12px 10px; font-size: 12px; line-height: 1.35; border-top: 1px solid var(--line); }

/* ---------- trial / subscription: the bar, the plans, the subscription screen ---------- */
.subbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 18px; font-size: 14px; border-bottom: 1px solid transparent; }
.subbar[hidden] { display: none; }
.subbar .sb-text { min-width: 0; overflow-wrap: anywhere; }
.subbar.blue { background: #e0ecff; color: #1e3a8a; border-color: #bcd3ff; }
.subbar.amber { background: var(--amber-l, #fef3c7); color: #78350f; border-color: #fcd34d; }
.subbar.red { background: var(--red-l, #fee2e2); color: #7f1d1d; border-color: #fca5a5; font-weight: 600; }
.sb-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 10px 0 14px; }
.sb-plan { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 4px; background: var(--card, #fff); }
.sb-plan .sb-price { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sb-plan .sb-price small { font-size: 12px; font-weight: 400; color: var(--muted); }
.sb-plan .btn { margin-top: auto; align-self: flex-start; }
.sb-contact { display: flex; flex-wrap: wrap; gap: 8px; }
.paywall { position: fixed; inset: 0; z-index: 2000; background: linear-gradient(160deg, #0f2a5c 0%, #1d4ed8 100%); overflow-y: auto; display: grid; place-items: start center; padding: 24px 14px calc(24px + env(safe-area-inset-bottom, 0px)); }
.pw-card { background: var(--card, #fff); color: var(--text, #0f172a); border-radius: 18px; width: min(760px, 100%); padding: 26px 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.pw-brand { font-weight: 800; letter-spacing: .3px; color: var(--navy, #0f2a5c); font-size: 18px; }
.pw-badge { display: inline-block; margin: 12px 0 4px; padding: 3px 10px; border-radius: 999px; background: var(--red-l, #fee2e2); color: var(--red, #b91c1c); font-weight: 700; font-size: 12px; }
.pw-card h1 { margin: 4px 0 6px; font-size: 26px; line-height: 1.2; }
.pw-lead { font-size: 15px; margin: 0 0 4px; }
.pw-safe { margin: 14px 0; padding: 10px 12px; border-radius: 10px; background: var(--green-l, #dcfce7); color: #14532d; font-size: 14px; }
.pw-foot { flex-wrap: wrap; }
@media (max-width: 700px) { .subbar { padding: 8px 12px; font-size: 13px; } .pw-card { padding: 20px 16px; } .pw-card h1 { font-size: 22px; } }

/* ---------- Backup & recovery page: one verdict, three checks, three buttons ---------- */
.bk-hero { display: flex; gap: 14px; align-items: center; padding: 16px 18px; border-radius: var(--radius, 12px); margin-bottom: 14px; border: 1px solid transparent; }
.bk-hero h2 { margin: 0 0 2px; font-size: 20px; }
.bk-hero .bk-shield { font-size: 30px; line-height: 1; flex: none; }
.bk-hero.ok { background: var(--green-l, #dcfce7); color: #14532d; border-color: #86efac; }
.bk-hero.warn { background: var(--amber-l, #fef3c7); color: #78350f; border-color: #fcd34d; }
.bk-hero.err { background: var(--red-l, #fee2e2); color: #7f1d1d; border-color: #fca5a5; }
.bk-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.bk-row:last-of-type { border-bottom: 0; }
.bk-txt { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.bk-dot { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; margin-top: 1px; }
.bk-dot.ok { background: var(--green, #15803d); } .bk-dot.warn { background: var(--amber, #b45309); } .bk-dot.bad { background: var(--red, #b91c1c); }
.bk-det { margin-bottom: 12px; }
.bk-det > summary { cursor: pointer; font-weight: 600; font-size: 15px; list-style: none; padding: 2px 0; }
.bk-det > summary::-webkit-details-marker { display: none; }
.bk-det > summary::before { content: '▸'; display: inline-block; width: 18px; color: var(--muted); }
.bk-det[open] > summary::before { content: '▾'; }
.bk-det[open] > summary { margin-bottom: 12px; }
.btn.danger-outline { color: var(--red, #b91c1c); border-color: #fca5a5; background: transparent; }
.btn.danger-outline:hover { background: var(--red-l, #fee2e2); }
@media (max-width: 700px) { .bk-hero { padding: 12px 14px; } .bk-hero h2 { font-size: 17px; } }

/* ---------- dropdowns and menus never leave the screen ---------- */
.combo-list { max-width: calc(100vw - 16px); }
.menu { max-width: calc(100vw - 16px); }

/* =========================================================== tablets and phones: the bottom bar (shown up to 900 px) */
@media (max-width: 900px) {
  .bottombar { padding: 2px 6px calc(2px + var(--ui-safe-b)); min-height: calc(var(--ui-bar) + var(--ui-safe-b)); }
  .bb-tab { min-height: 48px; padding: 5px 2px 4px; font-size: 10.5px; border-radius: 12px; }
  .bb-tab .bi { font-size: 18px; }
  .bb-plus { width: 48px; height: 48px; margin: -14px 6px 4px; border-width: 3px; box-shadow: 0 4px 12px rgba(37, 99, 235, .4); }
  /* the page can always be scrolled until its last card is clear of the bar and of the round Create button */
  .content { padding-bottom: calc(var(--ui-bar) + 28px + var(--ui-safe-b)); }
  .action-bar { bottom: calc(var(--ui-bar) + var(--ui-safe-b)); }
  .toasts { bottom: calc(var(--ui-bar) + 14px + var(--ui-safe-b)); }
}

/* =========================================================== phones */
@media (max-width: 700px) {
  /* header: menu, business, search, account - compact but still touch-friendly */
  .topbar { min-height: 52px; padding: calc(6px + var(--ui-safe-t)) 10px 6px; gap: 6px; }
  .topbar .burger { display: inline-grid; place-items: center; width: var(--ui-tap); height: var(--ui-tap); padding: 0; }
  .topbar .quick-find { width: var(--ui-tap); height: var(--ui-tap); min-height: var(--ui-tap); padding: 0; }
  .topbar .co-name { flex: 1 1 auto; min-width: 0; max-width: none; font-size: 15px; }
  .topbar .co-select { min-width: 0; max-width: 100%; min-height: var(--ui-tap); height: var(--ui-tap); padding-top: 0; padding-bottom: 0; font-size: 15px; }
  .topbar .user-chip { padding: 0; }
  .topbar .avatar { width: var(--ui-tap); height: var(--ui-tap); }

  .content { padding-left: 12px; padding-right: 12px; padding-top: 12px; }

  /* Home: greeting -> everyday actions -> the money -> what needs attention -> charts and the rest */
  .hero { margin: 0 0 8px; } .hero h1 { font-size: 19px; line-height: 1.25; } .hero .sub { font-size: 12.5px; margin-top: 1px; }
  .dash .start-grid { order: 1; } .dash .kpis { order: 2; } .dash .attention { order: 3; margin-bottom: 12px; }

  /* quick actions: a tidy two-column grid, every label readable, nothing cut off */
  .start-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; overflow: visible; margin: 0 0 12px; padding: 0; scroll-snap-type: none; }
  .start-grid .ctile { flex: initial; min-width: 0; min-height: 48px; padding: 7px 10px 7px 8px; gap: 8px; }
  .start-grid .ctile .ci { width: 32px; height: 32px; flex: none; }
  .start-grid .ctile b { min-width: 0; font-size: 13px; line-height: 1.2; overflow-wrap: anywhere; }

  /* the four money cards: equal height, compact, the full amount always shown */
  .cards.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; grid-auto-rows: 1fr; gap: 8px; margin-bottom: 12px; align-items: stretch; }
  .cards.kpis .stat { display: flex; flex-direction: column; padding: 11px 11px 10px; min-width: 0; }
  .cards.kpis .stat .lbl { font-size: 10.5px; letter-spacing: .06em; line-height: 1.25; padding-right: 30px; }
  .cards.kpis .stat .val { font-size: clamp(16px, 5.2vw, 22px); line-height: 1.15; margin-top: 4px; overflow-wrap: anywhere; }
  .cards.kpis .stat .sub { font-size: 11px; line-height: 1.3; margin-top: 2px; }
  .cards.kpis .stat .stat-ico { width: 28px; height: 28px; top: 9px; right: 9px; border-radius: 8px; }
  .cards.kpis .stat .stat-ico svg { width: 16px; height: 16px; }
  .cards.kpis .stat-foot { margin-top: auto; padding-top: 6px; }

  /* attention: compact rows, the whole row is the action */
  .attention { padding: 10px 12px; } .attention .alert-row { min-height: 48px; }

  /* charts and panels */
  .card-pad { padding: 12px; } .chart-card { padding: 12px; }
  .chart-card .card-title h3, .card-title h3 { font-size: 14px; }
  .chart .legend { gap: 12px; font-size: 12px; margin-top: 4px; }
  .chart-row { grid-template-columns: minmax(0, 1fr); gap: 10px; }

  /* forms and pages */
  .form-grid, .kv { grid-template-columns: minmax(0, 1fr); }
  .page-head { gap: 8px; }
  .modal-body { max-height: calc(100dvh - 170px); }
}

/* very narrow phones (320 px class): the money cards go one per row so every amount keeps its full size */
@media (max-width: 340px) {
  .cards.kpis { grid-template-columns: minmax(0, 1fr) !important; grid-auto-rows: auto; }
  .start-grid .ctile b { font-size: 12.5px; }
}

/* larger phones: three quick actions per row */
@media (min-width: 480px) and (max-width: 700px) {
  .start-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* =========================================================== tablets, laptops and desktops: even quick actions, no orphan tile */
@media (min-width: 701px) {
  .start-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
  .start-grid .ctile { min-width: 0; }
  .cards.kpis { align-items: stretch; grid-auto-rows: 1fr; }
  .start-grid .ctile b { overflow-wrap: anywhere; }
}
@media (min-width: 1101px) {
  .content { padding: 22px 26px 40px; }
  .cards.kpis { gap: 16px; }
}
