/* Reset, type, and shared components */
*, *::before, *::after { box-sizing: border-box; }
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); height: 100%; }
body {
  margin: 0; min-height: 100%;
  background: var(--bg); color: var(--text);
  font: 400 16px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
[hidden] { display: none !important; }
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }
ul, ol { margin: 0; padding: 0; list-style: none; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
[data-theme="dark"] :focus-visible { outline-color: var(--blue-soft); }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--text); color: var(--bg); padding: 8px 12px; border-radius: var(--r-s); z-index: 100; }
.skip:focus { left: 8px; }
.row { display: flex; align-items: center; gap: var(--s-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.stack { display: flex; flex-direction: column; gap: var(--s-3); }
.grow { flex: 1; min-width: 0; }
.ico { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.ico-sm { width: 16px; height: 16px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: var(--r-pill); white-space: nowrap;
  border: 1px solid transparent; background: var(--btn); color: var(--on-accent);
  font: 600 15px/1 var(--font-body); cursor: pointer; text-decoration: none; position: relative;
  transition: background var(--dur) var(--ease), transform 90ms var(--ease), border-color var(--dur) var(--ease);
}
.btn:hover { background: var(--btn-hover); text-decoration: none; }
.btn:active { background: var(--btn-press); transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; background: var(--btn); }
.btn-quiet { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-quiet:hover { background: var(--surface-2); }
.btn-quiet:active { background: var(--surface-2); }
.btn-quiet:disabled { background: transparent; }
.btn-text { background: transparent; color: var(--accent-text); padding: 0 8px; }
.btn-text:hover { background: var(--accent-soft); }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn-danger:hover { background: var(--bad-bg); }
.btn-danger:active { background: var(--bad-bg); }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 13px; border-radius: var(--r-s); }
.btn-block { width: 100%; }
.btn[aria-busy="true"] { color: transparent !important; pointer-events: none; }
.btn[aria-busy="true"]::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35); border-top-color: var(--on-accent); animation: spin .7s linear infinite;
}
.btn-quiet[aria-busy="true"]::after, .btn-danger[aria-busy="true"]::after { border-color: var(--border-strong); border-top-color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: var(--s-4); }
.label { font-weight: 600; font-size: 14px; }
.hint { font-size: 13px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 10px 14px; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-m); color: var(--text);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
textarea.input { min-height: 96px; resize: vertical; }
.input::placeholder { color: var(--muted); opacity: .8; }
.input:hover { border-color: var(--muted); }
.input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 25%, transparent); }
.input:disabled { opacity: .6; background: var(--surface-2); }
.field.has-error .input { border-color: var(--bad); }
.field-error { color: var(--bad); font-size: 13px; display: none; }
.field.has-error .field-error { display: block; }
.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; min-width: 0; }
.prefix-wrap { position: relative; }
.prefix-wrap > span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; }
.prefix-wrap .input { padding-left: 28px; }
.form-error { background: var(--bad-bg); color: var(--bad); padding: 10px 12px; border-radius: var(--r-s); font-size: 14px; margin-bottom: var(--s-4); }

/* Badges: status only */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: var(--r-xs);
  font-size: 12px; font-weight: 600; line-height: 18px; white-space: nowrap; background: var(--surface-2); color: var(--muted);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge[data-s="approved"], .badge[data-s="verified"], .badge[data-s="sent"], .badge[data-s="available"], .badge[data-s="activated"] { background: var(--ok-bg); color: var(--ok); }
.badge[data-s="pending"], .badge[data-s="requested"], .badge[data-s="processing"] { background: var(--warn-bg); color: var(--warn); }
.badge[data-s="rejected"], .badge[data-s="suspended"], .badge[data-s="void"] { background: var(--bad-bg); color: var(--bad); }

/* Segmented control (theme switcher, tabs) */
.seg { display: inline-flex; padding: 4px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-pill); }
.seg button {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border: 0; background: transparent;
  border-radius: var(--r-pill); color: var(--muted); font-weight: 600; font-size: 13px; cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg.seg-icons button { padding: 0 8px; }

/* Progress */
.bar { height: 6px; background: var(--surface-2); border-radius: var(--r-pill); overflow: hidden; position: relative; }
.bar > i { display: block; height: 100%; background: var(--blue); border-radius: var(--r-pill); transition: width .5s var(--ease); }
[data-theme="dark"] .bar > i { background: var(--blue-soft); }
.bar.warn > i { background: var(--warn-solid); }
.bar.bad > i { background: var(--bad); }

/* Tables */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-l); background: var(--surface); }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 10px 12px;
  border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--item); position: sticky; top: 0;
}
.tbl th[data-sort] { cursor: pointer; user-select: none; }
.tbl th[data-sort]:hover { color: var(--text); }
.tbl tbody tr.is-sel { background: var(--accent-soft); }
.tbl th .sort-ind { opacity: .7; margin-left: 4px; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background var(--dur) var(--ease); }
.tbl tbody tr:hover { background: var(--item); }
.tbl .r { text-align: right; }
.tbl .acts { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.tbl .cell-sub { display: block; font-size: 12px; color: var(--muted); }
.tbl .trunc { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }

/* Empty, skeleton */
.empty { padding: var(--s-7) var(--s-4); text-align: center; }
.empty h3 { font-size: 18px; margin-bottom: 4px; }
.empty p { color: var(--muted); max-width: 38ch; margin: 0 auto var(--s-4); }
.sk { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sk 1.3s ease infinite; border-radius: var(--r-s); }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* Toasts */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 300; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto; background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: var(--r-pill);
  font-weight: 500; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: 420px;
  animation: toast-in .22s var(--ease) both; backdrop-filter: blur(10px);
}
.toast[data-t="error"] { background: var(--bad); color: var(--on-accent); }
.toast.out { animation: toast-out .18s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

/* Modal / sheet */
.modal-back { position: fixed; inset: 0; background: var(--scrim); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .16s ease both; }
.modal { background: var(--surface); color: var(--text); width: 100%; max-width: 480px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; overflow: hidden; border-radius: var(--r-l); border: 1px solid var(--border); box-shadow: 0 24px 60px rgba(0, 0, 0, .35); animation: pop .2s var(--ease) both; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 0; flex: none; }
.modal-head h2 { font-size: 20px; }
.modal-body { padding: 14px 20px 12px; overflow-y: auto; flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px 20px; flex-wrap: wrap; flex: none; border-top: 1px solid var(--border); }
@media (max-width: 479px) { .modal-foot .btn { flex: 1 1 auto; } }
.icon-btn { width: 40px; height: 40px; display: inline-grid; place-items: center; background: transparent; border: 0; border-radius: var(--r-s); color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } }
@media (max-width: 640px) {
  .modal-back { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: var(--r-l) var(--r-l) 0 0; max-height: 92vh; animation: sheet .24s var(--ease) both; }
  .modal-foot .btn { flex: 1; }
}
@keyframes sheet { from { transform: translateY(24px); opacity: 0; } }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.kv .total { font-weight: 700; border-top: 1px solid var(--border); padding-top: 6px; }
.kv dt.total { color: var(--text); }

.page-fade { animation: page .22s var(--ease) both; }
@keyframes page { from { opacity: 0; transform: translateY(4px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
