:root {
  color-scheme: only light;
  --bg: #f0f2f5;
  --surface: #fff;
  --surface-2: #f8f9fa;
  --line: #ebeef2;
  --line-strong: #d2d6da;
  --ink: #344767;
  --text: #67748e;
  --muted: #7b809a;
  --faint: #a1a9bd;
  --primary: #344767;
  --primary-hover: #1f2d4a;
  --primary-soft: #eceff5;
  --success: #4caf50;
  --success-soft: #e8f5e9;
  --success-ink: #2e7d32;
  --warning: #f6b100;
  --warning-soft: #fff6dd;
  --warning-ink: #a87800;
  --danger: #f44335;
  --danger-soft: #fdeceb;
  --danger-ink: #d32f2f;
  --info: #7239ea;
  --info-soft: #f4effe;
  --radius: 12px;
  --shadow: 0 .25rem .375rem -.0625rem rgba(20, 20, 20, .08), 0 .125rem .25rem -.0625rem rgba(20, 20, 20, .04);
  --dark-grad: linear-gradient(195deg, #42424a, #191919);
  --dark-shadow: 0 .25rem .375rem -.0625rem rgba(20, 20, 20, .25), 0 .125rem .25rem -.0625rem rgba(20, 20, 20, .15);
  --sidebar: 288px;
  color: var(--text);
  font: 16px/1.7 Cairo, "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
}

* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
body { min-height: 100vh; margin: 0; background: var(--bg); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p, dl, dd, ul { margin: 0; }
ul { padding: 0; list-style: none; }
h1 { color: var(--ink); font-size: 1.6rem; font-weight: 700; line-height: 1.3; }
h2 { color: var(--ink); font-size: .92rem; font-weight: 650; }
a { color: inherit; }
code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .9rem; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.icon { flex: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: .88rem; }
.kicker { color: var(--muted); font-size: .8rem; font-weight: 600; letter-spacing: .02em; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 40px; padding: .45rem 1rem; border: 1px solid transparent; border-radius: 8px; font-size: .94rem; font-weight: 600; text-decoration: none; white-space: nowrap; transition: background .15s ease, border-color .15s ease, color .15s ease; }
.btn-sm { min-height: 32px; padding: .25rem .75rem; font-size: .86rem; }
.btn-primary { background: var(--dark-grad); color: #fff; box-shadow: var(--dark-shadow); }
.btn-primary:hover { filter: brightness(1.25); }
.btn-light { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn-light:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.btn-danger-light { background: var(--danger-soft); color: var(--danger-ink); }
.btn-danger-light:hover { background: var(--danger); color: #fff; }
.btn-icon { display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); }
.btn-icon:hover { background: var(--bg); color: var(--ink); }

/* App shell */
.app { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sidebar { position: sticky; top: 0; align-self: flex-start; display: flex; flex-direction: column; flex: 0 0 var(--sidebar); width: var(--sidebar); height: calc(100vh - 2rem); margin: 1rem; padding: 1.25rem 1rem; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); overflow-y: auto; z-index: 30; }
.sidebar-brand { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; padding: .25rem .5rem 1.1rem; border-bottom: 1px solid var(--line); text-decoration: none; }
.sidebar-brand span { display: grid; line-height: 1.25; }
.sidebar-brand strong { color: var(--ink); font-size: 1.05rem; }
.sidebar-brand small { color: var(--muted); font-size: .82rem; }
.brand-mark { display: block; flex: 0 0 40px; width: 40px !important; height: 40px !important; max-width: 40px; max-height: 40px; object-fit: contain; }
.menu { display: grid; gap: .15rem; align-content: start; flex: 1; }
.menu-label { margin: 1.1rem .75rem .4rem; color: var(--ink); font-size: .74rem; font-weight: 700; opacity: .7; }
.menu-label:first-child { margin-top: 0; }
.menu-item { display: flex; align-items: center; gap: .75rem; width: 100%; padding: .6rem .75rem; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: .92rem; font-weight: 550; text-align: start; text-decoration: none; transition: background .15s ease, color .15s ease; }
.menu-item:hover { background: var(--bg); color: var(--ink); }
.menu-item.is-active { background: var(--dark-grad); color: #fff; font-weight: 650; box-shadow: var(--dark-shadow); }
.menu-item.is-current { color: var(--ink); font-weight: 650; }
.menu-item .count { margin-inline-start: auto; min-width: 26px; padding: 0 .45rem; border-radius: 999px; background: var(--bg); color: var(--muted); font-size: .8rem; font-style: normal; font-weight: 650; text-align: center; font-variant-numeric: tabular-nums; }
.menu-item.is-current .count { background: var(--primary-soft); color: var(--ink); }
.sidebar-foot { display: grid; gap: .15rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.sidebar-scrim { display: none; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem; min-height: 68px; padding: .6rem 2rem; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); }
.menu-toggle { display: none; }
.crumbs { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .94rem; }
.crumbs a { display: inline-flex; align-items: center; gap: .3rem; color: var(--ink); font-weight: 600; text-decoration: none; }
.crumbs a:hover { color: var(--primary); }
.crumbs .sep { color: var(--faint); }
.crumbs [aria-current] { color: var(--ink); font-weight: 650; }
.topsearch { position: relative; display: flex; align-items: center; margin-inline-start: auto; width: min(360px, 100%); }
.topsearch .icon { position: absolute; inset-inline-start: .85rem; color: var(--faint); pointer-events: none; }
.topsearch input { padding-inline-start: 2.4rem; background: var(--surface); border-color: var(--line-strong); }
.user { display: flex; align-items: center; gap: .6rem; padding-inline-start: 1rem; color: var(--ink); font-weight: 600; }
.avatar { display: inline-grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--dark-grad); color: #fff; font-size: .88rem; font-weight: 700; }
.avatar-lg { width: 38px; height: 38px; border-radius: 10px; }

/* Content */
.content { width: min(1440px, 100%); margin: 0 auto; padding: 1.25rem 1.5rem 3rem; display: grid; gap: 1rem; align-content: start; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.page-sub { margin-top: .2rem; color: var(--muted); }
.page-sub:empty { display: none; }
.page-actions { display: flex; gap: .6rem; }
.card { background: var(--surface); border: 0; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.15rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .65rem; }

/* KPI cards */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .75rem; }
.kpi { position: relative; display: flex; align-items: flex-end; justify-content: space-between; gap: .65rem; min-height: 88px; padding: 1rem 1.1rem 1.2rem; margin-top: 0; background: var(--surface); border: 0; border-radius: var(--radius); box-shadow: var(--shadow); text-decoration: none; transition: transform .15s ease, box-shadow .15s ease; }
.kpi:hover { transform: translateY(-2px); }
.kpi.is-active { box-shadow: 0 0 0 2px var(--ink), var(--shadow); }
.kpi-icon { position: absolute; inset-block-start: -.9rem; inset-inline-end: 1rem; display: grid; place-items: center; flex: none; width: 52px; height: 52px; border-radius: 12px; background: var(--dark-grad); color: #fff; box-shadow: var(--dark-shadow); }
.kpis .kpi-icon { display: none; }
.kpi-body { display: grid; min-width: 0; text-align: start; }
.kpi-label { color: var(--muted); font-size: .8rem; font-weight: 500; }
.kpi-value { color: var(--ink); font-size: 1.5rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-bar { position: absolute; inset: auto 1rem .45rem; height: 2px; background: var(--line); border-radius: 2px; }
.kpi-bar span { display: block; height: 100%; background: var(--tone); border-radius: 2px; }
.tone-neutral { --tone: #7b809a; --tone-soft: var(--bg); }
.tone-primary { --tone: var(--primary); --tone-soft: var(--primary-soft); }
.tone-success { --tone: var(--success); --tone-soft: var(--success-soft); }
.tone-info { --tone: var(--info); --tone-soft: var(--info-soft); }
.tone-warning { --tone: var(--warning); --tone-soft: var(--warning-soft); }
.tone-danger { --tone: var(--danger); --tone-soft: var(--danger-soft); }

/* Layout of dashboard body */
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.keys-card { padding-bottom: .5rem; }

/* Table */
.table-wrap { overflow-x: auto; margin: 0 -1.4rem; }
table { width: 100%; min-width: 620px; border-collapse: collapse; }
th, td { text-align: start; padding: .65rem .75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th:first-child, td:first-child { padding-inline-start: 1.4rem; }
th:last-child, td:last-child { padding-inline-end: 1.4rem; }
th { background: transparent; color: var(--muted); font-size: .72rem; font-weight: 700; white-space: nowrap; border-bottom: 1px solid var(--line); }
td { color: var(--text); font-size: .85rem; }
td .badge, td .pill { font-size: .76rem; }
td .btn-sm { min-height: 28px; padding: .15rem .6rem; font-size: .8rem; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tr.is-new { background: var(--primary-soft); }
.cell-user { display: flex; align-items: center; gap: .6rem; }
.cell-user .avatar-lg { width: 30px; height: 30px; border-radius: 8px; font-size: .8rem; }
.cell-name { max-width: 16rem; overflow: hidden; color: var(--ink); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
td:not(:first-child) { white-space: nowrap; }
td.actions { text-align: end; }
.pill { display: inline-block; padding: .05rem .6rem; border-radius: 6px; background: var(--info-soft); color: var(--info); font-size: .82rem; font-weight: 650; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: .4rem; border-radius: 6px; padding: .15rem .6rem; font-size: .82rem; font-weight: 650; white-space: nowrap; background: var(--bg); color: var(--muted); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-unused, .status-created { color: var(--primary); background: var(--primary-soft); }
.status-activated, .status-renewed, .status-approved, .status-backup_approved { color: var(--success-ink); background: var(--success-soft); }
.status-released { color: var(--info); background: var(--info-soft); }
.status-revoked, .status-rejected { color: var(--danger-ink); background: var(--danger-soft); }
.status-requested, .status-backup_requested { color: var(--warning-ink); background: var(--warning-soft); }
.status-backup_rejected, .status-backup_stopped { color: var(--danger-ink); background: var(--danger-soft); }
.status-backup_takeover { color: var(--info); background: var(--info-soft); }
.status-expired { color: var(--warning-ink); background: var(--warning-soft); }
.status-published { color: var(--success-ink); background: var(--success-soft); }
.status-withdrawn, .status-paused { color: var(--danger-ink); background: var(--danger-soft); }
.status-app_updated { color: var(--info); background: var(--info-soft); }

/* Empty */
.empty { display: grid; justify-items: center; gap: .6rem; padding: 2.5rem 1rem 2rem; color: var(--muted); }
.empty-icon { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: var(--bg); color: var(--faint); }
.empty-text { color: var(--muted); padding-bottom: .5rem; }

/* Timeline */
.timeline { position: relative; display: grid; gap: 1.1rem; max-height: 440px; overflow-y: auto; padding-inline-end: .35rem; }
.timeline li:not(:last-child)::before { content: ""; position: absolute; inset-block: 1rem -1.1rem; inset-inline-start: 5px; width: 2px; background: var(--line); }
.timeline li { position: relative; display: flex; gap: .85rem; }
.timeline-dot { position: relative; z-index: 1; flex: none; width: 12px; height: 12px; margin-top: .35rem; border-radius: 50%; border: 2px solid var(--surface); background: var(--muted); box-shadow: 0 0 0 1px var(--line-strong); }
.ev-created .timeline-dot { background: var(--primary); }
.ev-activated .timeline-dot, .ev-renewed .timeline-dot { background: var(--success); }
.ev-released .timeline-dot { background: var(--info); }
.ev-revoked .timeline-dot { background: var(--danger); }
.ev-rejected .timeline-dot, .ev-backup_requested .timeline-dot { background: var(--warning); }
.ev-backup_approved .timeline-dot { background: var(--success); }
.ev-backup_rejected .timeline-dot, .ev-backup_stopped .timeline-dot { background: var(--danger); }
.ev-backup_takeover .timeline-dot { background: var(--info); }
.timeline li > div { min-width: 0; }
.timeline-detail { margin-top: .2rem; color: var(--text); font-size: .9rem; overflow-wrap: anywhere; }
.timeline time { color: var(--faint); font-size: .82rem; }

/* Banners */
.banner { border-radius: 10px; padding: .75rem 1rem; font-size: .94rem; }
.banner.warn { background: var(--warning-soft); color: var(--warning-ink); border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent); }
.banner.notice { background: var(--success-soft); color: var(--success-ink); border: 1px solid color-mix(in srgb, var(--success) 30%, transparent); }
.banner.error { background: var(--danger-soft); color: var(--danger-ink); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
.banner-card { border-color: color-mix(in srgb, var(--success) 40%, var(--line)); }
.new-keys { display: grid; gap: .5rem; }
.new-keys li { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.key-chip { display: inline-flex; align-items: center; gap: .5rem; padding: .3rem .8rem; border-radius: 8px; background: var(--bg); color: var(--muted); }
.masked-key { direction: ltr; unicode-bidi: plaintext; letter-spacing: .06em; }

/* Forms */
label { display: grid; gap: .35rem; font-size: .88rem; font-weight: 650; color: var(--text); }
input, select { width: 100%; min-height: 40px; border: 1px solid var(--line-strong); border-radius: 8px; padding: .45rem .75rem; background: var(--surface); transition: border-color .15s ease, box-shadow .15s ease; }
input::placeholder { color: var(--faint); }
input:focus, select:focus { border-color: #8f9bb3; box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); outline: 0; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .9rem; }
.form-grid .span-3 { grid-column: 1 / -1; }
.form-grid .span-2 { grid-column: span 2; }
.optional-fields { margin-top: 1rem; }
.optional-fields summary { width: max-content; cursor: pointer; color: var(--muted); font-size: .9rem; font-weight: 650; }
.optional-fields summary:hover, .optional-fields[open] summary { color: var(--primary); }
.optional-fields[open] summary { margin-bottom: .9rem; }

/* Modals */
.modal { width: min(440px, calc(100% - 2rem)); padding: 1.5rem; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: 0 24px 64px rgba(7, 20, 55, .22); }
.modal-wide { width: min(680px, calc(100% - 2rem)); }
.modal::backdrop { background: rgba(7, 20, 55, .5); backdrop-filter: blur(2px); }
.modal form { display: grid; gap: 1rem; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.modal-actions { display: flex; gap: .6rem; margin-top: .25rem; }
.download-error { color: var(--danger-ink); }

/* Key detail */
.key-hero { display: flex; align-items: center; gap: .9rem; padding: 1rem 1.15rem; }
.key-hero .kpi-icon { width: 56px; height: 56px; }
.key-hero-main { flex: 1; min-width: 0; display: grid; gap: .2rem; }
.key-code { display: block; direction: ltr; text-align: end; font-size: clamp(1rem, 3vw, 1.5rem); font-weight: 700; letter-spacing: .08em; color: var(--ink); overflow-wrap: anywhere; }
.key-hero-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.details-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.details-list div { min-width: 0; padding: .45rem .75rem; border-bottom: 1px dashed var(--line); }
.details-list div:nth-last-child(-n+2) { border-bottom: 0; }
.details-list div:nth-child(odd) { border-inline-start: 1px dashed var(--line); }
.details-list div:nth-child(odd):last-child, .details-list .wide { grid-column: span 2; border-inline-start: 0; }
.details-list dt { color: var(--muted); font-size: .72rem; font-weight: 650; }
.details-list dd { margin-top: .05rem; overflow-wrap: anywhere; color: var(--ink); font-size: .84rem; font-weight: 550; line-height: 1.5; }
.details-list .machine { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .78rem; }
.detail-actions { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.detail-actions .actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.backup-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.download-form { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }
.download-form input { width: auto; min-width: 240px; flex: 1; max-width: 340px; }
.renew-form { display: flex; gap: .5rem; }
.renew-form select { width: auto; min-width: 120px; }
.months-form { display: flex; align-items: center; gap: .5rem; padding: .25rem; border: 1px solid var(--line); border-radius: 10px; }
.months-form input[type=number] { width: 4.5rem; min-height: 36px; text-align: center; }
.months-form .unit { white-space: nowrap; color: var(--muted); font-size: .88rem; }
.stop-message-form input { flex: 1; min-width: 0; }
.update-policy-form { display: grid; gap: .9rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.policy-choices { display: grid; gap: .55rem; border: 0; margin: 0; padding: 0; }
.policy-choices label { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.policy-choices input[type=radio] { width: 1.05rem; height: 1.05rem; min-height: 0; padding: 0; margin: 0; flex: none; accent-color: var(--primary); }
.policy-choices label > span { font-weight: 600; }
.policy-choices select { width: auto; min-width: 7rem; min-height: 34px; padding-block: .2rem; }
.policy-message { display: grid; gap: .35rem; font-size: .9rem; }
.policy-message input { width: 100%; }
.update-policy-form .btn { justify-self: start; }
.version-bars { list-style: none; margin: 0 0 .5rem; padding: 0; display: grid; gap: .6rem; }
.version-group + .version-group { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.version-group-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .6rem; }
.version-group-head h3 { margin: 0; font-size: 1rem; }
.version-bars li { display: grid; grid-template-columns: minmax(7rem, auto) 1fr auto; align-items: center; gap: .75rem; }
.version-bar { width: 100%; height: 10px; display: block; }
.version-bar .track { fill: var(--bg); }
.version-bar .fill { fill: var(--muted); }
.version-bar.is-latest .fill { fill: var(--success-ink); }
.version-count { white-space: nowrap; font-variant-numeric: tabular-nums; }
.rollout-form input[type=number] { width: 4.5rem; }
.platform-tabs { display: inline-flex; width: max-content; max-width: 100%; justify-self: start; align-self: start; gap: .25rem; padding: .25rem; margin-bottom: 1rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.platform-tabs .tab { padding: .35rem 1rem; border-radius: 7px; color: var(--muted); font-weight: 600; text-decoration: none; }
.platform-tabs .tab:hover { color: inherit; background: var(--bg); }
.platform-tabs .tab.is-active { color: var(--surface); background: var(--primary); }

/* Multi-branch merchant page */
.kpis.group-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.group-kpis .kpi-value .badge { font-size: .9rem; }
.kpi-date { font-size: 1rem; }
.row-actions { display: inline-flex; align-items: center; gap: .15rem; }
.row-actions .btn-icon { width: 30px; height: 30px; }
.btn-icon-danger:hover { background: var(--danger-soft); color: var(--danger-ink); }
.console-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.console-actions .months-form input:not([type=number]) { min-height: 32px; width: 11rem; }
.owner-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.owner-form { display: grid; gap: .75rem; align-content: start; padding: 1rem; border: 1px solid var(--line); border-radius: 10px; }
.modal details.optional-fields { margin-top: 0; }
@media (max-width: 760px) { .kpis.group-kpis { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 760px) { .owner-grid { grid-template-columns: minmax(0, 1fr); } }

/* Auth pages */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: var(--bg); }
.login-card { width: min(420px, 100%); display: grid; gap: .6rem; padding: 2.2rem; box-shadow: 0 16px 48px rgba(7, 20, 55, .1); }
.login-card h1 { font-size: 1.4rem; }
.login-card .lede { margin-bottom: .6rem; color: var(--muted); }
.login-card .eyebrow { color: var(--muted); font-size: .84rem; font-weight: 700; }
.login-card .primary { min-height: 42px; margin-top: .6rem; border: 0; border-radius: 8px; background: var(--dark-grad); color: #fff; font-weight: 650; box-shadow: var(--dark-shadow); }
.login-card .primary:hover { filter: brightness(1.25); }
.login-card .crumb { width: max-content; color: var(--muted); font-size: .92rem; font-weight: 600; text-decoration: none; }
.login-card .crumb:hover { color: var(--primary); }
.login-card .banner { margin: 0; }
.brand-logo { display: block; width: 56px !important; height: 56px !important; max-width: 56px; max-height: 56px; object-fit: contain; justify-self: start; margin-bottom: .4rem; }

@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
  .sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; height: 100vh; margin: 0; border-radius: 0; transform: translateX(100%); transition: transform .22s ease; box-shadow: 0 0 40px rgba(7, 20, 55, .2); }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-open .sidebar-scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(7, 20, 55, .45); }
  .menu-toggle { display: inline-grid; }
  .topbar, .content { padding-inline: 1.25rem; }
}
@media (max-width: 760px) {
  .crumbs { display: none; }
  .topsearch { margin-inline-start: 0; flex: 1; }
  .user-name { display: none; }
  .user { padding-inline-start: 0; border: 0; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .page-head { align-items: stretch; flex-direction: column; }
  .page-actions .btn { width: 100%; }
  .card-head { align-items: flex-start; flex-direction: column; gap: .75rem; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: 1 / -1; }
  .key-hero { flex-wrap: wrap; }
  .key-code { text-align: start; }
  .details-list { grid-template-columns: minmax(0, 1fr); }
  .details-list div, .details-list .wide, .details-list div:nth-child(odd):last-child { grid-column: auto; border-inline-start: 0 !important; border-bottom: 1px dashed var(--line) !important; }
  .details-list div:last-child { border-bottom: 0 !important; }
  .renew-form { width: 100%; }
  .renew-form select { flex: 1; }
  .months-form { width: 100%; }
  .months-form .btn { margin-inline-start: auto; }
}

/* A row that opens its page when clicked anywhere */
tr.row-link { cursor: pointer; }

/* Names and keys that open a page are links without the underline */
td > a:not(.btn), .cell-user a { color: inherit; text-decoration: none; }
td > a:not(.btn):hover, .cell-user a:hover { color: var(--primary); }

/* Key cards: one per key, with every detail and control of the key page */
.key-list { display: grid; gap: .85rem; }
.key-card { display: grid; gap: .75rem; padding: 0; overflow: hidden; }
.key-card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; padding: .8rem 1.15rem; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.key-card-title { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.key-card-title .kpi-icon { position: static; width: 36px; height: 36px; border-radius: 10px; box-shadow: none; }
.key-card-title h3 { color: var(--ink); font-size: .98rem; font-weight: 700; line-height: 1.3; }
.key-card-code { display: flex; align-items: center; gap: .25rem; }
.key-card-code a { color: var(--ink); text-decoration: none; font-weight: 650; }
.key-card-code a:hover { color: var(--primary); text-decoration: underline; }
.key-card-tags { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.btn-xs { width: 30px; height: 30px; }
.key-card-body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; padding: 0 1.15rem; }
.key-card-body h4 { display: flex; align-items: center; gap: .5rem; margin: 0 0 .4rem; color: var(--ink); font-size: .82rem; font-weight: 700; }
.key-card-body h4:not(:first-child) { margin-top: .75rem; }
.mini-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .1rem .9rem; margin: 0; }
.mini-list div { min-width: 0; padding: .3rem 0; border-bottom: 1px dashed var(--line); }
.mini-list .wide { grid-column: span 2; }
.mini-list dt { color: var(--muted); font-size: .7rem; font-weight: 650; }
.mini-list dd { margin: 0; overflow-wrap: anywhere; color: var(--ink); font-size: .82rem; font-weight: 550; line-height: 1.45; }
.mini-list .machine { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .74rem; }
.danger-text { color: var(--danger-ink) !important; }
.key-card-actions { display: grid; gap: .5rem; padding: .75rem 1.15rem; border-top: 1px solid var(--line); background: var(--surface-2); }
.key-card-actions:empty { display: none; }
.action-group { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.action-group:empty { display: none; }
.action-group .months-form { padding: .15rem; background: var(--surface); }
.action-group .months-form input[type=number] { min-height: 30px; width: 3.6rem; }
.action-group .months-form select, .action-group .download-inline input[type=password] { height: 32px; min-height: 32px; padding-block: 0; width: auto; min-width: 8rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: .4rem 0 -.2rem; }
.section-head h2 { font-size: 1rem; }
@media (max-width: 760px) {
  .key-card-body { grid-template-columns: minmax(0, 1fr); }
  .action-group { align-items: stretch; }
  .action-group > form, .action-group .months-form { width: 100%; }
  .action-group > form > .btn { width: 100%; }
}
.action-set { min-width: 0; margin: 0; padding: .55rem .7rem .65rem; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); }
.action-set legend { display: inline-flex; align-items: center; gap: .35rem; padding: 0 .4rem; color: var(--ink); font-size: .8rem; font-weight: 700; }
.action-set .months-form { background: var(--surface-2); }
/* The boxes of one key sit side by side, and wrap under each other on narrow screens */
.key-card-actions { display: flex; flex-wrap: wrap; align-items: stretch; gap: .6rem; }
.key-card-actions .action-set { flex: 1 1 340px; }

/* Subscriptions card: every paid service of the merchant, side by side */
.sub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: .75rem; }
.sub-tile { display: grid; align-content: start; gap: .5rem; min-width: 0; padding: .8rem .9rem; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface-2); }
.sub-tile header { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.sub-tile h3 { display: inline-flex; align-items: center; gap: .4rem; color: var(--ink); font-size: .9rem; font-weight: 700; }
.sub-for { margin-top: -.35rem; color: var(--muted); font-size: .8rem; font-weight: 600; }
.sub-tile .months-form { background: var(--surface); }
@media (max-width: 760px) { .sub-grid { grid-template-columns: minmax(0, 1fr); } }
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: auto; }
.btn-danger-light:disabled:hover { background: var(--danger-soft); color: var(--danger-ink); }

/* Click an end date to edit it */
.expiry-show { display: inline-flex; align-items: center; gap: .3rem; padding: 0 .25rem; border: 0; border-bottom: 1px dashed var(--faint); background: transparent; color: inherit; font: inherit; cursor: pointer; }
.expiry-show:hover { color: var(--primary); border-bottom-color: var(--primary); }
.expiry-form { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.expiry-form[hidden], .expiry-show[hidden] { display: none; }
.expiry-form input[type=date] { min-height: 32px; width: auto; padding-block: 0; }
