/* AKM Docs — new dashboard (records.html), beta. Base look: theme-v5.css. */

.shell { max-width: 1320px; margin: 0 auto; padding: 12px 16px 40px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.shell > *, #view-records > * { min-width: 0; }
#view-records { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

/* ── Top bar ── */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.brand { display: flex; align-items: center; gap: 6px; font: 800 16px var(--ui); color: var(--ink); text-decoration: none; }
.brand .wordmark { font-weight: 900; color: var(--inv); letter-spacing: .04em; }
.beta { font: 800 10px var(--ui); letter-spacing: .12em; color: #fff; background: var(--ink); padding: 3px 7px; border-radius: 999px; }
.tabs { display: flex; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; min-width: 0; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { font: 700 13px var(--ui); color: var(--muted); background: transparent; border: 0; border-radius: 9px; padding: 8px 12px; cursor: pointer; white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { background: var(--ink); color: #fff; }
.top-actions { display: flex; gap: 8px; margin-left: auto; }

/* ── Summary cards ── */
.stats { display: grid; gap: 8px; }
.stats-head { display: flex; align-items: baseline; gap: 10px; }
.stats-head h2 { margin: 0; font: 800 11px var(--ui); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.stats-head span { font-size: 12.5px; font-weight: 700; color: var(--ink); }
.stats-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; }
.stat { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: grid; gap: 4px; cursor: pointer; color: var(--ink); min-width: 0; }
.stat:hover { border-color: #b8c3cf; }
.stat[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.stat .k { display: flex; align-items: center; gap: 7px; font: 700 12px var(--ui); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat b { font: 800 24px var(--ui); font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat small { font: 600 12px var(--body); color: var(--muted); font-variant-numeric: tabular-nums; min-height: 1em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Filters ── */
.filters { padding: 12px; display: grid; gap: 10px; }
.frow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.search { flex: 1 1 320px; display: flex; align-items: center; gap: 8px; background: var(--well); border: 1px solid transparent; border-radius: 12px; padding: 0 10px 0 12px; min-height: 44px; color: var(--muted); }
.search:focus-within { border-color: var(--accent); background: #fff; }
.search svg { width: 18px; height: 18px; flex: none; }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; font: 500 14.5px var(--ui); color: var(--ink); padding: 10px 0; outline: none; }
.search input::-webkit-search-cancel-button { display: none; }
.x { border: 0; background: transparent; color: var(--faint); font-size: 20px; line-height: 1; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; flex: none; }
.x:hover { background: var(--well); color: var(--ink); }
.period select, .mini select, .mini input { font: 700 13px var(--ui); color: var(--ink); background: var(--well); border: 1px solid transparent; border-radius: 12px; padding: 0 12px; min-height: 44px; cursor: pointer; }
.mini { display: flex; align-items: center; gap: 8px; font: 700 12px var(--ui); color: var(--muted); }
.mini select, .mini input { min-height: 38px; }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; border-radius: 9px; background: var(--ink); color: #fff; font-size: 10.5px; padding: 0 5px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; background: var(--well); border-radius: 12px; padding: 4px; }
.seg button { display: inline-flex; align-items: center; gap: 7px; font: 700 13px var(--ui); color: var(--muted); background: transparent; border: 0; border-radius: 9px; padding: 7px 12px; cursor: pointer; min-height: 36px; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.1), 0 3px 10px rgba(0,0,0,.06); }
.seg .n { font: 700 11.5px var(--body); color: var(--faint); font-variant-numeric: tabular-nums; }
.seg button[aria-pressed="true"] .n { color: var(--muted); }
.seg.small button { font-size: 12.5px; padding: 6px 10px; min-height: 32px; }
.lbl { font: 800 10px var(--ui); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
#status-row.dim { opacity: .55; }
.result-row { justify-content: space-between; border-top: 1px solid var(--hair); padding-top: 10px; font-size: 13px; color: var(--muted); }
.result-row b { color: var(--ink); font-variant-numeric: tabular-nums; }
.result-row .owed { color: var(--warn); font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; font: 700 12px var(--ui); color: var(--ink); background: var(--well); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 11px; cursor: pointer; }
.chip span { font-size: 15px; line-height: 1; color: var(--faint); width: 18px; height: 18px; display: grid; place-items: center; border-radius: 50%; }
.chip:hover span { background: var(--line); color: var(--ink); }

/* ── Table ── */
.table-card { overflow: hidden; position: relative; }
.loading, .empty { padding: 40px 16px; text-align: center; color: var(--muted); font-weight: 600; margin: 0; }
.docs { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.docs th { text-align: left; font: 800 10.5px var(--ui); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 1; white-space: nowrap; user-select: none; }
.docs th[data-sort] { cursor: pointer; }
.docs th[data-sort]:hover { color: var(--ink); }
.docs th[aria-sort="descending"]::after { content: ' ↓'; color: var(--ink); }
.docs th[aria-sort="ascending"]::after { content: ' ↑'; color: var(--ink); }
.docs th.n, .docs td.c-amt { text-align: right; }
.docs td { padding: 11px 14px; border-bottom: 1px solid var(--hair); font: 13.5px var(--body); color: var(--ink); vertical-align: middle; }
.docs tbody tr { cursor: pointer; }
.docs tbody tr:hover td { background: #f7f9fb; }
.docs tbody tr.sel td { background: #eef4fb; }
.docs tbody tr:last-child td { border-bottom: 0; }
.docs td small { display: block; font-size: 12px; color: var(--faint); margin-top: 2px; }
.docs td b { font-weight: 700; }
.c-date { white-space: nowrap; color: var(--muted) !important; width: 96px; }
.c-doc { white-space: nowrap; width: 150px; }
.c-doc .dot { margin-right: 8px; vertical-align: 1px; }
.c-doc small { padding-left: 17px; }
.m-date { display: none; }
.t-invoice .c-doc .dot { background: var(--inv); } .t-quotation .c-doc .dot { background: var(--qt); }
.t-delivery .c-doc .dot { background: var(--dn); } .t-receipt .c-doc .dot { background: var(--rc); } .t-other .c-doc .dot { background: var(--faint); }
/* Letters & more: no money, one quiet violet for all four kinds */
.t-extra .c-doc .dot, .dot.xd { background: #7c5cbf; }
.drawer.t-extra { border-left-color: #7c5cbf; }
.c-cust { max-width: 340px; }
.c-cust b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-amt { font-weight: 700; white-space: nowrap; width: 130px; }
.c-status { width: 120px; }
.c-status small { font-size: 11px; }
.c-staff { width: 90px; color: var(--muted) !important; }
.c-go { width: 30px; text-align: right; color: var(--faint) !important; font-size: 20px; }
.more { display: block; width: calc(100% - 24px); margin: 12px; font: 700 13px var(--ui); color: var(--ink); background: var(--well); border: 1px dashed var(--line); border-radius: 12px; padding: 12px; cursor: pointer; }

/* ── Sections in a frame ── */
.frame-wrap { background: var(--bench); }
#frame { width: 100%; height: calc(100vh - 90px); min-height: 520px; border: 0; border-radius: 14px; background: var(--bench); display: block; }

/* ── Side panel ── */
.drawer-back { position: fixed; inset: 0; background: rgba(10,15,20,.35); z-index: 60; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100%); background: var(--panel); z-index: 61; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; box-shadow: -10px 0 40px rgba(0,0,0,.18); border-left: 4px solid var(--inv); }
.drawer.t-quotation { border-left-color: var(--qt); } .drawer.t-delivery { border-left-color: var(--dn); } .drawer.t-receipt { border-left-color: var(--rc); }
.drawer header { display: flex; align-items: center; gap: 12px; padding: 16px 16px 12px 20px; border-bottom: 1px solid var(--hair); }
.drawer header > div { flex: 1; min-width: 0; }
.drawer h2 { margin: 2px 0 0; font: 800 20px var(--ui); }
/* A column that scrolls, never squeezes. As a grid, a box with overflow:hidden
   (items, totals) could shrink to fit the panel, so the totals were cut off
   under VAT and nothing scrolled. Flex items here never shrink. */
.d-body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; min-height: 0; padding: 14px 20px 20px; display: flex; flex-direction: column; gap: 16px; }
.d-body > * { flex: none; }
.d-body dl { display: grid; grid-template-columns: 96px 1fr; gap: 6px 12px; margin: 0; font-size: 13.5px; }
.d-body dt { font: 700 12px var(--ui); color: var(--muted); }
.d-body dd { margin: 0; font-family: var(--body); overflow-wrap: anywhere; }
.d-body h3, .d-notes label { margin: 0 0 6px; font: 800 10.5px var(--ui); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); display: block; }
#d-items { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
#d-items li { display: grid; grid-template-columns: 22px 1fr auto auto; gap: 10px; padding: 9px 12px; font: 13px var(--body); align-items: baseline; }
#d-items li + li { border-top: 1px solid var(--hair); }
#d-items li.none { display: block; color: var(--faint); }
#d-items .i { color: var(--faint); font-size: 12px; }
#d-items em { display: block; font: 700 10.5px var(--body); font-style: normal; letter-spacing: .04em; color: var(--muted); }
#d-items .q { color: var(--muted); font-variant-numeric: tabular-nums; }
#d-items .a { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 70px; text-align: right; }
.d-totals { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; font-variant-numeric: tabular-nums; }
.d-totals .r { display: flex; justify-content: space-between; padding: 8px 12px; font-size: 13px; }
.d-totals .r + .r { border-top: 1px solid var(--hair); }
.d-totals .grand { background: var(--inv); color: #fff; font: 800 13px var(--ui); }
.drawer.t-quotation .grand { background: var(--qt); } .drawer.t-receipt .grand { background: var(--rc); }
.d-notes { display: grid; gap: 8px; justify-items: start; }
.d-notes textarea { width: 100%; font: 14px/1.45 var(--body); color: var(--ink); background: var(--well); border: 1px solid transparent; border-radius: 12px; padding: 10px 12px; resize: vertical; }
.d-notes textarea:focus { border-color: var(--accent); background: #fff; outline: none; }
.drawer footer { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--hair); }
.drawer footer .danger { margin-left: auto; }
.iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; flex: none; border: 1px solid var(--hair); border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; padding: 0; }
.iconbtn.danger:hover, .iconbtn.danger:focus-visible { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }

/* ── Tablet ── */
@media (max-width: 1180px) {
  .stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .c-staff, .docs th:nth-child(6) { display: none; }
}

/* ── Phone: cards instead of a table ── */
@media (max-width: 760px) {
  .shell { padding: 10px 10px 32px; gap: 12px; }
  .topbar { gap: 8px; }
  .top-actions { order: 2; width: 100%; }
  .top-actions .btn, .top-actions .linkbtn { flex: 1 1 0; min-width: 0; justify-content: center; text-align: center; white-space: nowrap; }
  .tabs { order: 3; flex-basis: 100%; }
  /* the summary becomes a strip you swipe, so the list stays near the top */
  .stats-grid { display: flex; overflow-x: auto; gap: 8px; margin: 0 -10px; padding: 0 10px 2px; scroll-snap-type: x proximity; scrollbar-width: none; }
  .stats-grid::-webkit-scrollbar { display: none; }
  .stat { padding: 10px 12px; flex: 0 0 148px; scroll-snap-align: start; }
  .stat b { font-size: 20px; }
  .search { flex-basis: 100%; }
  .search input { font-size: 16px; }   /* 16px stops iOS zooming */
  .period { flex: 1; } .period select { width: 100%; font-size: 16px; }
  .seg-row { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; margin: 0 -12px; padding: 0 12px; }
  .seg-row::-webkit-scrollbar { display: none; }
  .seg { flex-wrap: nowrap; }
  .seg button { white-space: nowrap; }
  .result-row { flex-direction: column; align-items: flex-start; }
  .docs thead { display: none; }
  .docs, .docs tbody { display: block; width: 100%; }
  .docs tbody tr { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "doc amt" "cust status" "date date"; gap: 4px 10px; padding: 12px 14px; border-bottom: 1px solid var(--hair); }
  .docs td { display: block; border: 0 !important; padding: 0; width: auto !important; max-width: none; }
  .c-doc { grid-area: doc; } .c-amt { grid-area: amt; font-size: 15px; } .c-cust { grid-area: cust; min-width: 0; }
  .c-status { grid-area: status; text-align: right; align-self: end; }
  .c-go, .c-staff, .c-date { display: none !important; }
  .m-date { display: inline; }
  .docs tbody tr { grid-template-areas: "doc amt" "cust status"; }
  .drawer { border-left: 0; border-top: 4px solid var(--inv); top: auto; max-height: 92vh; border-radius: 18px 18px 0 0; width: 100%; }
  .drawer.t-quotation { border-top-color: var(--qt); } .drawer.t-delivery { border-top-color: var(--dn); } .drawer.t-receipt { border-top-color: var(--rc); } .drawer.t-extra { border-top-color: #7c5cbf; }
  /* Two rows at most: three buttons a row, the delete icon tucked in at the end. */
  .drawer footer .btn, .drawer footer .linkbtn { flex: 1 1 26%; min-width: 0; justify-content: center; padding-left: 6px; padding-right: 6px; white-space: nowrap; font-size: 13px; }
  .drawer footer .danger { margin-left: 0; }
  .drawer footer .iconbtn { flex: 0 0 34px; align-self: center; }
  #frame { height: calc(100vh - 150px); }
}


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