/* Antfast Transportation - TMS
   Brand: red / white / black                                              */

:root {
  --red: #D7141A;
  --red-dark: #A50F14;
  --red-soft: #FDECEC;
  --black: #0E0F11;
  --char: #17191D;
  --char-2: #22252B;
  --line: #E2E5EA;
  --ink: #14161A;
  --ink-2: #545B66;
  --ink-3: #8A93A0;
  --bg: #F5F6F8;
  --white: #FFFFFF;
  --green: #157F3D;
  --green-soft: #E8F6ED;
  --amber: #B45309;
  --amber-soft: #FEF3E2;
  --sidebar: 224px;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(14,15,17,.06), 0 8px 24px rgba(14,15,17,.08);
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--red); }

/* ---------------------------------------------------------------- layout */
#app { display: flex; height: 100vh; overflow: hidden; }

#sidebar {
  width: var(--sidebar); flex: none; background: var(--black); color: #EFF1F4;
  display: flex; flex-direction: column; overflow-y: auto;
}
#sidebar::-webkit-scrollbar { width: 8px; }
#sidebar::-webkit-scrollbar-thumb { background: #2B2F36; border-radius: 4px; }

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 16px 14px; border-bottom: 1px solid #24272D;
}
.brand svg { width: 34px; height: 34px; flex: none; border-radius: 6px; }
/* Uploaded logos sit on a white chip: the Antfast mark is black line art and
   would vanish against the black sidebar. Landscape marks stay uncropped. */
.brand img {
  width: 46px; height: 36px; flex: none; border-radius: 6px;
  object-fit: contain; background: #fff; padding: 3px;
}
.brand-text { line-height: 1.15; min-width: 0; }
.brand-name {
  font-weight: 700; font-size: 14px; letter-spacing: .06em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-sub { font-size: 10px; letter-spacing: .16em; color: var(--red); font-weight: 700; }

.nav-group {
  padding: 14px 16px 6px; font-size: 10px; letter-spacing: .14em;
  text-transform: uppercase; color: #6B727D; font-weight: 700;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  color: #C9CFD8; cursor: pointer; border-left: 3px solid transparent;
  user-select: none; white-space: nowrap;
}
.nav-item:hover { background: #191C21; color: #fff; }
.nav-item.active { background: #1C2026; color: #fff; border-left-color: var(--red); }
.nav-item .ico { width: 16px; height: 16px; flex: none; opacity: .85; }
.nav-item.active .ico { opacity: 1; }
.nav-count {
  margin-left: auto; font-size: 11px; color: #6B727D;
  background: #1F2229; padding: 1px 7px; border-radius: 10px;
}
.nav-item.active .nav-count { background: var(--red); color: #fff; }

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ---------------------------------------------------------------- topbar */
#topbar {
  display: flex; align-items: center; gap: 12px; padding: 0 18px; height: 56px;
  background: var(--white); border-bottom: 1px solid var(--line); flex: none;
}
#page-title { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
#page-sub { color: var(--ink-3); font-size: 12px; }
.spacer { flex: 1; }

.search {
  position: relative; display: flex; align-items: center;
}
.search input {
  width: 240px; padding: 7px 10px 7px 30px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--bg); outline: none;
}
.search input:focus { border-color: var(--red); background: #fff; }
.search svg { position: absolute; left: 9px; width: 14px; height: 14px; color: var(--ink-3); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px;
  border: 1px solid var(--line); background: var(--white); border-radius: var(--radius);
  cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn-dark { background: var(--char); border-color: var(--char); color: #fff; }
.btn-dark:hover { background: #000; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 4px 9px; font-size: 12px; }

/* ---------------------------------------------------------------- content */
#content { flex: 1; overflow: auto; padding: 18px; }
#content.flush { padding: 0; display: flex; flex-direction: column; }

.toolbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 18px;
  background: var(--white); border-bottom: 1px solid var(--line); flex: none;
  flex-wrap: wrap;
}
.toolbar select, .toolbar input {
  padding: 6px 9px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--white); outline: none;
}
.toolbar select:focus, .toolbar input:focus { border-color: var(--red); }
.chip-count { color: var(--ink-3); font-size: 12px; }

/* ---------------------------------------------------------------- grid */
.grid-wrap { flex: 1; overflow: auto; background: var(--white); }
table.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
table.grid th {
  position: sticky; top: 0; z-index: 3; background: #FAFBFC; text-align: left;
  font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2);
  font-weight: 700; padding: 9px 10px; border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line); cursor: pointer; white-space: nowrap;
}
table.grid th:hover { background: #F1F3F5; color: var(--ink); }
table.grid th .sort { color: var(--red); margin-left: 3px; }
table.grid td {
  padding: 0; border-bottom: 1px solid #EEF0F3; border-right: 1px solid #F2F4F6;
  vertical-align: top; background: var(--white);
}
table.grid tr:hover td { background: #FCFCFD; }
table.grid tr.sel td { background: var(--red-soft); }
.cell {
  padding: 7px 10px; min-height: 33px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; cursor: text;
}
.cell.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell.computed { background: #FBFBFC; color: var(--ink-2); cursor: default; font-weight: 600; }
.cell.empty { color: #C3C9D2; }
.cell.editing { padding: 0; }
.cell input, .cell select, .cell textarea {
  width: 100%; padding: 6px 9px; border: 2px solid var(--red); border-radius: 3px;
  outline: none; background: #fff; font: inherit;
}
.cell textarea { min-height: 70px; resize: vertical; }

.rownum {
  position: sticky; left: 0; z-index: 2; width: 46px; text-align: center;
  color: var(--ink-3); font-size: 11px; background: #FAFBFC !important;
  border-right: 1px solid var(--line); padding: 8px 0; user-select: none;
}
th.rownum { z-index: 4; }
.rownum .open {
  display: none; cursor: pointer; color: var(--red); font-weight: 700;
}
tr:hover .rownum .num { display: none; }
tr:hover .rownum .open { display: inline; }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px;
  font-weight: 700; white-space: nowrap; line-height: 1.5;
}
.pill.grey  { background: #EDEFF2; color: #4A515C; }
.pill.blue  { background: #E8F0FE; color: #1A4FA0; }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.red   { background: var(--red-soft); color: var(--red-dark); }
.pill.black { background: #E4E6EA; color: #1B1E23; }

.money-pos { color: var(--red-dark); font-weight: 700; }
.money-neg { color: var(--green); font-weight: 700; }
.money-zero { color: var(--ink-3); }
.overdue { color: var(--red-dark); font-weight: 700; }

.linkchip {
  color: var(--ink); border-bottom: 1px dotted var(--ink-3);
}
.stars { color: var(--red); letter-spacing: 1px; }

/* ---------------------------------------------------------------- drawer */
#drawer-back {
  position: fixed; inset: 0; background: rgba(14,15,17,.42); z-index: 40;
  display: none;
}
#drawer-back.open { display: block; }
#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 520px; max-width: 92vw;
  background: var(--white); z-index: 41; transform: translateX(100%);
  transition: transform .18s ease; display: flex; flex-direction: column;
  box-shadow: -8px 0 30px rgba(0,0,0,.18);
}
#drawer.open { transform: none; }
.drawer-head {
  padding: 14px 18px; background: var(--black); color: #fff; flex: none;
  display: flex; align-items: center; gap: 10px;
}
.drawer-head h3 { margin: 0; font-size: 15px; }
.drawer-head .sub { font-size: 11px; color: #9AA2AD; }
.drawer-body { flex: 1; overflow: auto; padding: 16px 18px; }
.drawer-foot {
  padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px;
  align-items: center; flex: none; background: #FAFBFC;
}
.iconbtn {
  background: none; border: 0; color: inherit; cursor: pointer; padding: 4px;
  border-radius: 5px; display: inline-flex;
}
.iconbtn:hover { background: rgba(255,255,255,.14); }

.field { margin-bottom: 13px; }
.field label {
  display: block; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--ink-2); margin-bottom: 4px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--white); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--red); box-shadow: 0 0 0 3px rgba(215,20,26,.10);
}
.field textarea { min-height: 80px; resize: vertical; }
.field .readonly {
  padding: 8px 10px; background: var(--bg); border: 1px dashed var(--line);
  border-radius: var(--radius); font-weight: 700;
}
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input { width: auto; }
.sec-title {
  font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--red); margin: 20px 0 10px; padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
}
.sec-title:first-child { margin-top: 0; }

/* ---------------------------------------------------------------- cards */
.cards { display: grid; gap: 14px; }
.card {
  background: var(--white); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px; box-shadow: var(--shadow);
}
.card h3 {
  margin: 0 0 12px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-2);
}
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; }
.kpi {
  background: var(--white); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 15px; position: relative; overflow: hidden;
}
.kpi::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--red);
}
.kpi .label {
  font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3);
  font-weight: 700;
}
.kpi .value {
  font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.kpi .value.pos { color: var(--green); }
.kpi .value.neg { color: var(--red); }
.kpi .hint { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.kpi.dark { background: var(--black); border-color: var(--black); color: #fff; }
.kpi.dark .label { color: #8A93A0; }
.kpi.dark .hint { color: #8A93A0; }

.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; margin-top: 14px; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } }

table.mini { width: 100%; border-collapse: collapse; }
table.mini th {
  text-align: left; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-3); padding: 5px 8px; border-bottom: 1px solid var(--line);
}
table.mini td { padding: 6px 8px; border-bottom: 1px solid #F1F3F5; }
table.mini td.num, table.mini th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.mini tr:last-child td { border-bottom: 0; }
table.mini tr.total td { font-weight: 700; border-top: 2px solid var(--black); }
.bar-track { background: var(--bg); border-radius: 3px; height: 7px; overflow: hidden; }
.bar-fill { background: var(--red); height: 100%; }

.chart { width: 100%; height: 230px; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-right: 5px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-3); }
.empty-state h3 { color: var(--ink); margin: 0 0 6px; }

/* ---------------------------------------------------------------- toast */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--char); color: #fff; padding: 10px 18px; border-radius: 8px;
  box-shadow: var(--shadow); z-index: 60; opacity: 0; transition: all .2s ease;
  max-width: 80vw;
}
#toast.show { transform: translateX(-50%); opacity: 1; }
#toast.err { background: var(--red-dark); }

.help {
  font-size: 12px; color: var(--ink-3); margin-top: 6px; line-height: 1.5;
}
kbd {
  background: var(--bg); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 5px; font-size: 11px; font-family: inherit;
}
.settings-wrap { max-width: 720px; }
.file-drop {
  border: 2px dashed var(--line); border-radius: 10px; padding: 22px; text-align: center;
  color: var(--ink-3); cursor: pointer; background: var(--white);
}
.file-drop.over { border-color: var(--red); background: var(--red-soft); color: var(--red-dark); }

@media print {
  #sidebar, #topbar, .toolbar { display: none !important; }
  #content { overflow: visible; padding: 0; }
}

/* ================================================================ accounts */
.auth-mode { background: var(--black); }
.auth-wrap {
  min-height: 100vh; width: 100%; display: flex; align-items: center;
  justify-content: center; padding: 20px; background: var(--black);
}
.auth-card {
  width: 100%; max-width: 390px; background: var(--white); border-radius: 14px;
  padding: 30px 28px 26px; box-shadow: 0 24px 60px rgba(0,0,0,.45);
  border-top: 4px solid var(--red);
}
.auth-logo { display: flex; justify-content: center; margin-bottom: 12px; }
.auth-logo svg { width: 54px; height: 54px; }
.auth-logo img {
  /* the RIZE wordmark is roughly 3:1, so let it keep its shape rather than
     forcing it into the square box the old logo used */
  width: auto; height: auto; max-width: 240px; max-height: 78px;
  object-fit: contain; display: block;
}
.auth-name {
  text-align: center; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  font-size: 15px;
}
.auth-sub { text-align: center; color: var(--ink-3); font-size: 13px; margin-bottom: 20px; }
.auth-form .field { margin-bottom: 14px; }
.auth-submit { width: 100%; justify-content: center; padding: 11px; margin-top: 4px; }
.auth-error {
  background: var(--red-soft); color: var(--red-dark); border: 1px solid var(--red);
  border-radius: var(--radius); padding: 9px 12px; font-size: 13px; margin-bottom: 14px;
}
.auth-warn {
  margin-top: 16px; background: var(--amber-soft); color: var(--amber);
  border-radius: var(--radius); padding: 9px 12px; font-size: 12px; line-height: 1.5;
}

#user-box { border-top: 1px solid #24272D; padding: 12px 14px; }
#user-box .who { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; }
#user-box .avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--red); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  font-size: 13px; flex: none;
}
#user-box .who-name {
  font-size: 12.5px; font-weight: 600; color: #EFF1F4; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
#user-box .who-role { font-size: 10px; color: #6B727D; text-transform: uppercase; letter-spacing: .1em; }
#user-box .signout {
  width: 100%; background: #1C2026; border: 1px solid #2B2F36; color: #C9CFD8;
  padding: 6px; border-radius: 6px; cursor: pointer; font-size: 12px;
}
#user-box .signout:hover { background: var(--red); border-color: var(--red); color: #fff; }

/* ================================================================== mobile */
.menu-btn { display: none; color: var(--ink); margin-left: -6px; }
.menu-btn:hover { background: var(--bg); }
#nav-back {
  position: fixed; inset: 0; background: rgba(14,15,17,.5); z-index: 29; display: none;
}

/* phone card list (replaces the wide grid) */
.cardlist { padding: 12px; display: grid; gap: 10px; }
.reccard {
  background: var(--white); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; box-shadow: 0 1px 2px rgba(14,15,17,.05); cursor: pointer;
}
.reccard:active { border-color: var(--red); background: #FFF9F9; }
.reccard-head {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  margin-bottom: 9px; padding-bottom: 9px; border-bottom: 1px solid #F1F3F5;
}
.reccard-title { font-weight: 700; font-size: 15px; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.reccard-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 14px; }
.reccard-field { min-width: 0; }
.reccard-field .k {
  display: block; font-size: 10px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 700;
}
.reccard-field .v {
  display: block; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 820px) {
  .menu-btn { display: inline-flex; }
  #sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 30; width: 270px;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  body.nav-open #sidebar { transform: none; box-shadow: 6px 0 30px rgba(0,0,0,.35); }
  body.nav-open #nav-back { display: block; }
  .nav-item { padding: 12px 16px; }        /* bigger tap targets */

  #topbar { padding: 0 12px; gap: 8px; height: 54px; }
  #page-title { font-size: 15px; }
  #page-sub { display: none; }
  .titles { min-width: 0; overflow: hidden; }
  #topbar-actions .search input { width: 130px; }
  #topbar-actions .btn span { display: none; }

  #content { padding: 12px; }
  .toolbar { padding: 9px 12px; gap: 6px; }
  .toolbar select { flex: 1; min-width: 0; }
  .toolbar .btn { padding: 7px 10px; }

  .dash-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 9px; }
  .kpi .value { font-size: 19px; }
  .card { padding: 13px; }
  .chart { height: 200px; }

  #drawer { width: 100%; max-width: 100%; }
  .drawer-body { padding: 14px; }
  .field input, .field select, .field textarea { padding: 11px 10px; font-size: 16px; }
  .field-row { flex-direction: column; gap: 0; }
  .drawer-foot { padding: 10px 14px; }

  /* reports and mini tables scroll rather than squeeze */
  table.mini { font-size: 13px; }
  .card > table.mini, #ifta-body, #pl-body, #ar-body { overflow-x: auto; }
}

@media (max-width: 420px) {
  .reccard-fields { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  #topbar-actions .search input { width: 104px; }
}

.auth-links { margin-top: 16px; text-align: center; font-size: 13px; color: var(--ink-3); }
.auth-links a { color: var(--red); text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }
.auth-note {
  background: var(--green-soft); color: var(--green); border: 1px solid var(--green);
  border-radius: var(--radius); padding: 9px 12px; font-size: 13px; margin-bottom: 14px;
  line-height: 1.5;
}

/* reassurance + optional/advanced sections */
.reassure {
  background: var(--green-soft); border: 1px solid var(--green); color: var(--green);
  border-radius: var(--radius); padding: 11px 13px; font-size: 13px; line-height: 1.55;
  margin-bottom: 12px;
}
details.advanced { padding: 0; }
details.advanced > summary {
  cursor: pointer; padding: 14px 16px; display: flex; align-items: baseline;
  gap: 10px; flex-wrap: wrap; list-style: none; user-select: none;
}
details.advanced > summary::-webkit-details-marker { display: none; }
details.advanced > summary::before {
  content: "▸"; color: var(--ink-3); font-size: 12px; margin-right: 2px;
}
details.advanced[open] > summary::before { content: "▾"; }
details.advanced > summary:hover { background: #FAFBFC; }
details.advanced > *:not(summary) { padding-left: 16px; padding-right: 16px; }
details.advanced > *:last-child { padding-bottom: 16px; }
.adv-title { font-size: 12px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-2); }
.adv-hint { font-size: 11.5px; color: var(--ink-3); }

.auth-help { color: var(--ink-3); font-size: 12.5px; }

/* platform wordmark on the sign-in screen */

/* a signup form and a login form look alike - shout about the difference */
.auth-badge {
  display: inline-block; background: var(--red); color: #fff;
  font-size: 10.5px; font-weight: 800; letter-spacing: .12em;
  text-transform: uppercase; padding: 4px 12px; border-radius: 20px;
  margin: 0 auto 10px; text-align: center;
}
.auth-card:has(.auth-badge) { border-top-width: 6px; }
.auth-logo + .auth-badge { display: block; width: fit-content; }

/* the secondary action under the sign-in form */
.auth-alt {
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line);
  font-size: 13.5px; color: var(--ink-2);
}
.auth-alt a { font-weight: 700; }

/* ======================================================= phone safe areas
   With viewport-fit=cover the page reaches under the notch and the home
   indicator, so every fixed edge pads itself back out. On a phone without a
   notch env() is 0 and nothing changes.                                   */

body { background: var(--black); }        /* fills the notch strip, not white */

#topbar {
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
  padding-top: env(safe-area-inset-top);
  height: calc(56px + env(safe-area-inset-top));
}

#sidebar {
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-bottom: env(safe-area-inset-bottom);
}

#content {
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
  padding-bottom: max(18px, env(safe-area-inset-bottom));
}

.toolbar {
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
}

#drawer { padding-top: env(safe-area-inset-top); }
.drawer-foot { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.auth-wrap {
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

@media (max-width: 820px) {
  #topbar {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  #content, .toolbar {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .cardlist {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  /* ---- touch polish ---- */
  .btn { min-height: 42px; }              /* comfortable thumb target */
  .btn-sm { min-height: 34px; }
  .toolbar select, .toolbar input { min-height: 40px; }
  .search input { min-height: 40px; }

  .reccard { padding: 14px 16px; }
  .reccard:active { transform: scale(.995); }
  .reccard-title { font-size: 16px; }
  .reccard-head { margin-bottom: 10px; padding-bottom: 10px; }

  /* the record panel behaves like a sheet rather than a cramped page */
  #drawer { border-radius: 0; }
  .drawer-head { padding: 14px 16px; }
  .drawer-foot {
    position: sticky; bottom: 0;          /* actions stay reachable */
    background: #FAFBFC;
  }
  .drawer-body { padding-bottom: 8px; }

  /* stop iOS zooming when a field is focused */
  input, select, textarea { font-size: 16px; }

  /* one-handed reach: the new-record button is the important one */
  #topbar-actions .btn-primary { padding: 9px 14px; }
  .kpi { padding: 12px 13px; }
}

@media (max-width: 420px) {
  .drawer-foot { flex-wrap: wrap; gap: 6px; }
  .drawer-foot .help { width: 100%; order: 3; }
  .section-title { font-size: 24px; }
}

/* honour a phone set to reduce motion */
@media (prefers-reduced-motion: reduce) {
  #sidebar, #drawer, .card, .btn { transition: none !important; }
}
