:root {
  --bone: #faf7f2;
  --bone-deep: #f3eee5;
  --paper: #fffdfa;
  --ink: #26221e;
  --ink-soft: #5c554c;
  --moss: #4e6b54;
  --moss-deep: #3e5745;
  --sage: #e9eee8;
  --dark: #1b211c;
  --dark-soft: #9ba69b;
  --wax: #8c3b2e;
  --rule: rgba(38, 34, 30, .12);
  --shadow: 0 18px 50px rgba(45, 35, 23, .08);
  --display: 'Cabinet Grotesk', system-ui, sans-serif;
  --body: 'Instrument Sans', system-ui, sans-serif;
  --ease: cubic-bezier(.16, 1, .3, 1);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bone); }
body { margin: 0; color: var(--ink); background: var(--bone); font: 15px/1.5 var(--body); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.rail { position: sticky; top: 0; height: 100vh; padding: 26px 18px 20px; background: var(--dark); color: #e8eae4; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 26px; color: inherit; text-decoration: none; }
.courier-mark { position: relative; width: 30px; height: 21px; flex: 0 0 auto; }
.courier-mark .plane { width: 100%; height: 100%; transform: rotate(-10deg); }
.courier-mark .plane path { fill: none; stroke: #b0563f; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.brand-copy { min-width: 0; display: grid; }
.wm { font: 700 17px/1.15 var(--display); letter-spacing: -.01em; white-space: nowrap; }
.wm .pn { color: #7e9b84; }
.product-name { margin-top: 4px; color: var(--dark-soft); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }

.primary-nav { display: grid; gap: 5px; }
.primary-nav a { min-height: 43px; display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 9px; padding: 0 12px; border-radius: 10px; color: var(--dark-soft); text-decoration: none; font-weight: 500; transition: 160ms ease; }
.primary-nav a:hover { color: #e8eae4; background: rgba(255, 255, 255, .05); }
.primary-nav a.active { color: #fff; background: rgba(233, 238, 232, .1); }
.nav-mark { width: 20px; text-align: center; font-size: 17px; color: #7e9b84; }
.nav-count { min-width: 22px; padding: 1px 7px; border-radius: 999px; background: rgba(255, 255, 255, .08); color: #bdc7bd; font-size: 11px; text-align: center; }
.nav-count:empty { display: none; }
.rail-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 16px 10px 0; border-top: 1px solid rgba(255, 255, 255, .08); color: #788479; font-size: 11px; }
.privacy-dot { width: 7px; height: 7px; border-radius: 50%; background: #7e9b84; box-shadow: 0 0 0 4px rgba(126, 155, 132, .1); }

main { min-width: 0; }
.topbar { min-height: 104px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 26px clamp(24px, 4vw, 58px) 22px; border-bottom: 1px solid var(--rule); background: rgba(250, 247, 242, .92); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 10; }
.eyebrow, .kicker { margin: 0 0 3px; color: var(--moss); font-size: 11px; font-weight: 600; letter-spacing: .11em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font: 700 clamp(27px, 3vw, 36px)/1 var(--display); letter-spacing: -.025em; }
h2 { margin-bottom: 0; font: 700 21px/1.1 var(--display); letter-spacing: -.015em; }
h3 { margin-bottom: 0; font: 700 16px/1.2 var(--display); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.signed-in { max-width: 190px; overflow: hidden; text-overflow: ellipsis; color: var(--ink-soft); font-size: 12px; white-space: nowrap; }
.button, .icon-button { border: 0; cursor: pointer; transition: transform 180ms var(--ease), background 180ms ease, border-color 180ms ease; }
.button:hover, .icon-button:hover { transform: translateY(-1px); }
.button { min-height: 39px; padding: 8px 16px; border-radius: 999px; font-weight: 600; }
.button.primary { color: var(--bone); background: var(--moss); }
.button.primary:hover { background: var(--moss-deep); }
.button.secondary { color: var(--ink); background: transparent; border: 1px solid var(--rule); }
.button.secondary:hover { background: var(--bone-deep); border-color: rgba(38, 34, 30, .2); }
.button.small { min-height: 31px; padding: 5px 11px; font-size: 12px; }
.button.danger { color: var(--wax); }
.icon-button { width: 39px; height: 39px; border: 1px solid var(--rule); border-radius: 50%; color: var(--ink-soft); background: transparent; font-size: 18px; }

.content { max-width: 1480px; margin: 0 auto; padding: 34px clamp(24px, 4vw, 58px) 64px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { min-height: 132px; padding: 19px 20px; border: 1px solid var(--rule); border-radius: 15px; background: var(--paper); box-shadow: var(--shadow); }
.stat-label { color: var(--ink-soft); font-size: 12px; }
.stat-value { margin-top: 10px; font: 700 34px/1 var(--display); letter-spacing: -.03em; }
.stat-note { margin-top: 9px; color: var(--ink-soft); font-size: 11px; }
.stat-card.accent { color: #f0f2ed; background: var(--moss); border-color: transparent; }
.stat-card.accent .stat-label, .stat-card.accent .stat-note { color: rgba(255, 255, 255, .7); }

.setup-note { display: flex; align-items: center; gap: 15px; margin-bottom: 22px; padding: 15px 18px; border: 1px solid rgba(140, 59, 46, .2); border-radius: 13px; background: #f8ebe6; }
.setup-note p { margin: 2px 0 0; color: #6f4d45; font-size: 13px; }
.seal-icon { width: 38px; height: 38px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: var(--bone); background: var(--wax); font: 800 29px/1 var(--display); }
.overview-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.panel { border: 1px solid var(--rule); border-radius: 16px; background: var(--paper); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 20px 22px 16px; border-bottom: 1px solid var(--rule); }
.panel-head a { color: var(--moss); font-size: 12px; font-weight: 600; text-decoration: none; }
.panel-head a:hover { text-decoration: underline; }
.summary-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; align-items: center; padding: 15px 22px; border-top: 1px solid var(--rule); }
.summary-row:first-child { border-top: 0; }
.summary-row.clickable { cursor: pointer; }
.summary-row.clickable:hover { background: #fbf8f3; }
.summary-button { width: 100%; border-right: 0; border-bottom: 0; border-left: 0; color: inherit; background: transparent; font: inherit; text-align: left; cursor: pointer; }
.summary-button:first-child { border-top: 0; }
.summary-button:hover { background: #fbf8f3; }
.summary-button:focus-visible, .row-title-button:focus-visible { outline: 2px solid var(--moss); outline-offset: -3px; }
.summary-title { overflow: hidden; text-overflow: ellipsis; font-weight: 600; white-space: nowrap; }
.summary-meta { margin-top: 3px; color: var(--ink-soft); font-size: 12px; }
.summary-side { color: var(--ink-soft); font-size: 12px; text-align: right; }

.toolbar { min-height: 48px; display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.search { min-width: 260px; max-width: 440px; height: 43px; display: flex; align-items: center; flex: 1; gap: 8px; padding: 0 13px; border: 1px solid var(--rule); border-radius: 12px; background: var(--paper); }
.search:focus-within { border-color: rgba(78, 107, 84, .55); box-shadow: 0 0 0 3px rgba(78, 107, 84, .08); }
.search span { color: var(--ink-soft); font-size: 17px; }
.search input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; }
.search input::placeholder { color: #9b948b; }
.toolbar select { height: 43px; max-width: 220px; padding: 0 34px 0 12px; border: 1px solid var(--rule); border-radius: 12px; color: var(--ink); background: var(--paper); }
.result-count { margin-left: auto; color: var(--ink-soft); font-size: 12px; white-space: nowrap; }
.table-panel { overflow: visible; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { padding: 12px 17px; border-bottom: 1px solid var(--rule); color: #877f76; font-size: 10px; font-weight: 600; letter-spacing: .08em; text-align: left; text-transform: uppercase; white-space: nowrap; }
.data-table td { padding: 15px 17px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover { background: #fbf8f3; }
.name-cell { min-width: 190px; }
.cell-title { max-width: 390px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; white-space: nowrap; }
.cell-sub { margin-top: 3px; color: var(--ink-soft); font-size: 12px; }
.row-title-button { max-width: 100%; display: grid; padding: 0; border: 0; color: inherit; background: transparent; font: inherit; text-align: left; cursor: pointer; }
.row-title-button:hover .cell-title { color: var(--moss); text-decoration: underline; text-underline-offset: 2px; }
.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-soft); }
.right { text-align: right !important; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px; background: var(--bone-deep); color: var(--ink-soft); font-size: 11px; font-weight: 600; text-transform: capitalize; }
.status::before { width: 6px; height: 6px; border-radius: 50%; background: #a49c92; content: ''; }
.status.ready::before, .status.accepted::before, .status.joined::before { background: var(--moss); }
.status.invited::before, .status.pilot::before { background: #b88a40; }
.status.expired::before, .status.revoked::before { background: var(--wax); }
.usage { min-width: 108px; }
.usage-line { display: flex; justify-content: space-between; gap: 10px; color: var(--ink-soft); font-size: 11px; }
.usage-bar { height: 5px; margin-top: 6px; overflow: hidden; border-radius: 999px; background: var(--bone-deep); }
.usage-bar span { display: block; height: 100%; border-radius: inherit; background: var(--moss); }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.text-button { padding: 5px 8px; border: 0; color: var(--moss); background: transparent; cursor: pointer; font-weight: 600; }
.text-button:hover { text-decoration: underline; }
.text-button.danger { color: var(--wax); }
.pager { min-height: 50px; display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--rule); }
.pager:empty { display: none; }
.pager button:disabled { opacity: .4; pointer-events: none; }

.empty-state, .loading-state, .error-state { min-height: 250px; display: grid; place-items: center; padding: 36px; text-align: center; }
.empty-state strong, .error-state strong { display: block; font: 700 20px/1.2 var(--display); }
.empty-state p, .error-state p { max-width: 430px; margin: 8px auto 0; color: var(--ink-soft); }
.empty-glyph { width: 42px; height: 42px; display: grid; place-items: center; margin: 0 auto 12px; border-radius: 50%; color: var(--moss); background: var(--sage); font-size: 20px; }
.loading-state { color: var(--ink-soft); }
.loader { width: 22px; height: 22px; margin: 0 auto 10px; border: 2px solid var(--rule); border-top-color: var(--moss); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.dialog { width: min(680px, calc(100vw - 30px)); max-height: calc(100vh - 36px); padding: 0; border: 1px solid var(--rule); border-radius: 18px; color: var(--ink); background: var(--paper); box-shadow: 0 30px 90px rgba(20, 17, 12, .28); }
.dialog::backdrop { background: rgba(17, 20, 17, .58); backdrop-filter: blur(3px); }
.compact-dialog { width: min(500px, calc(100vw - 30px)); padding: 24px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.dialog-head.sticky { position: sticky; top: 0; z-index: 2; padding: 23px 25px 17px; border-bottom: 1px solid var(--rule); background: rgba(255, 253, 250, .95); backdrop-filter: blur(12px); }
.close-button { width: 34px; height: 34px; flex: 0 0 auto; border: 0; border-radius: 50%; color: var(--ink-soft); background: var(--bone-deep); cursor: pointer; font-size: 21px; }
.dialog-lede { margin: 15px 0 18px; color: var(--ink-soft); }
.dialog label { display: grid; gap: 6px; margin-top: 14px; font-size: 12px; font-weight: 600; }
.dialog input, .dialog select { width: 100%; height: 43px; padding: 0 12px; border: 1px solid var(--rule); border-radius: 10px; color: var(--ink); background: #fff; outline: 0; }
.dialog input:focus, .dialog select:focus { border-color: var(--moss); box-shadow: 0 0 0 3px rgba(78, 107, 84, .08); }
.optional { color: var(--ink-soft); font-weight: 400; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 23px; }
.form-error { margin: 12px 0 0; padding: 9px 11px; border-radius: 9px; color: #75362d; background: #f8e7e2; font-size: 12px; }
.dialog-meta { margin: 5px 0 0; color: var(--ink-soft); font-size: 12px; }
.delivery-dialog { width: min(900px, calc(100vw - 30px)); }
#deliveryDetail { padding: 0 25px 28px; }
.detail-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin: 20px 0; }
.detail-stat { padding: 13px; border-radius: 11px; background: var(--bone-deep); }
.detail-stat span { color: var(--ink-soft); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.detail-stat strong { display: block; margin-top: 5px; font: 700 18px/1 var(--display); }
.detail-section { margin-top: 24px; }
.detail-section > h3 { margin-bottom: 10px; }
.recipient-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.recipient-card { padding: 12px 13px; border: 1px solid var(--rule); border-radius: 10px; }
.event-list { border-top: 1px solid var(--rule); }
.event-row { display: grid; grid-template-columns: 120px 1fr auto; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--rule); font-size: 12px; }
.event-type { font-weight: 600; text-transform: capitalize; }
.event-who { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--ink-soft); white-space: nowrap; }
.event-time { color: var(--ink-soft); text-align: right; white-space: nowrap; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; max-width: min(390px, calc(100vw - 44px)); padding: 11px 15px; border-radius: 11px; color: #fff; background: var(--dark); box-shadow: 0 16px 40px rgba(0, 0, 0, .22); opacity: 0; transform: translateY(10px); pointer-events: none; transition: 220ms var(--ease); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--wax); }

@media (max-width: 1060px) {
  .app-shell { grid-template-columns: 205px minmax(0, 1fr); }
  .rail { padding-left: 12px; padding-right: 12px; }
  .wm { font-size: 15px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-grid { grid-template-columns: 1fr; }
  .signed-in { display: none; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .rail { position: sticky; z-index: 20; width: 100%; height: auto; padding: 11px 15px 0; }
  .brand { padding: 0 2px 10px; }
  .courier-mark { width: 24px; height: 17px; }
  .product-name, .rail-foot { display: none; }
  .primary-nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
  .primary-nav::-webkit-scrollbar { display: none; }
  .primary-nav a { min-width: max-content; min-height: 38px; grid-template-columns: auto auto auto; padding: 0 10px; border-radius: 9px 9px 0 0; font-size: 12px; }
  .nav-mark { display: none; }
  .nav-count { padding: 0 5px; }
  .topbar { min-height: 82px; top: 92px; padding: 17px 18px 14px; }
  .top-actions .primary { display: none; }
  .content { padding: 22px 14px 48px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .stat-card { min-height: 112px; padding: 15px; }
  .stat-value { font-size: 28px; }
  .toolbar { align-items: stretch; flex-wrap: wrap; }
  .search { max-width: none; min-width: 100%; }
  .result-count { margin: auto 0 auto auto; }
  .table-panel { overflow-x: auto; }
  .data-table { min-width: 720px; }
  .recipient-grid { grid-template-columns: 1fr; }
  .detail-stats { grid-template-columns: repeat(2, 1fr); }
  .event-row { grid-template-columns: 88px 1fr; }
  .event-time { grid-column: 2; text-align: left; }
}

@media (max-width: 430px) {
  .primary-nav a { padding: 0 8px; }
  .topbar { top: 90px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat-note { display: none; }
  .stat-card { min-height: 96px; }
  .setup-note { align-items: flex-start; }
}

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