*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e6ed;
  --text: #1a1d23;
  --text-secondary: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #f59e0b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.1);
}

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.page {
  display: none;
}
.page.active {
  display: block;
}
#dashboard-page.active {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}

/* ---- Login ---- */
#login-page {
  display: none;
  place-items: center;
  min-height: 100vh;
  padding: 1rem;
}
#login-page.active {
  display: grid;
}

/* ---- Boot splash ---- */
#boot-page {
  display: none;
  place-items: center;
  min-height: 100vh;
  padding: 1rem;
  background: var(--bg);
}
#boot-page.active {
  display: grid;
}
.boot-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  color: var(--text-secondary);
  font-size: 0.9375rem;
}
.spinner {
  width: 1.5rem;
  height: 1.5rem;
  border: 2.5px solid #e5e7eb;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner-lg {
  width: 2.25rem;
  height: 2.25rem;
  border-width: 3px;
}

/* ---- Panel loaders ---- */
.panel,
.table-wrap[data-loading-panel] {
  position: relative;
  min-height: 8rem;
}
.panel-loader {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(2px);
  color: var(--text-secondary);
  font-size: 0.875rem;
  border-radius: inherit;
}
.panel.is-loading > :not(.panel-loader),
.table-wrap.is-loading > :not(.panel-loader) {
  opacity: 0.35;
  pointer-events: none;
}

.login-card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
}

.login-header {
  text-align: center;
  margin-bottom: 1.5rem;
}
.login-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}
.login-header p {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ---- Fields ---- */
.field {
  margin-bottom: 1rem;
}
.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  color: var(--text-secondary);
}
.field input,
.field select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color 0.15s;
  background: var(--surface);
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: var(--danger-hover);
}
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover {
  background: var(--bg);
}
.btn-block {
  width: 100%;
}
.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

/* ---- App header (brand + nav + account, one row) ---- */
.app-header {
  display: flex;
  align-items: center;
  gap: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1.25rem;
  box-shadow: var(--shadow);
  flex-shrink: 0;
  position: relative;
  z-index: 40;
}
.app-brand {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
  flex-shrink: 0;
}
.topbar-right span {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  margin-left: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  padding: 0;
}
.nav-toggle-bars,
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  display: block;
  width: 1.1rem;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  position: relative;
  transition: transform 0.15s, opacity 0.15s;
}
.nav-toggle-bars::before,
.nav-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
}
.nav-toggle-bars::before { top: -5px; }
.nav-toggle-bars::after { top: 5px; }
.app-header.nav-open .nav-toggle-bars {
  background: transparent;
}
.app-header.nav-open .nav-toggle-bars::before {
  top: 0;
  transform: rotate(45deg);
}
.app-header.nav-open .nav-toggle-bars::after {
  top: 0;
  transform: rotate(-45deg);
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}
.tab {
  padding: 0.45rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}
.tab.active {
  color: var(--primary);
  background: #eef2ff;
}
.tab:hover {
  color: var(--text);
  background: var(--bg);
}

.tab-content {
  display: none;
  padding: 1.5rem;
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.tab-content.active {
  display: block;
}
#tab-images.active {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0.5rem 0.75rem 0.5rem;
}
#tab-images .section-header {
  flex-shrink: 0;
  margin-bottom: 0.4rem;
}
#tab-images .section-header h3 {
  font-size: 0.9375rem;
}
#tab-images .images-upload-wrap,
#tab-images #images-upload-wrap {
  flex-shrink: 0;
  max-height: 40vh;
  overflow: auto;
  margin-bottom: 0.4rem;
  padding: 0.75rem;
}

/* ---- Section headers ---- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.section-header h3 {
  font-size: 1rem;
  font-weight: 600;
}
.section-header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

/* ---- Status pills ---- */
.status-pills {
  display: flex;
  gap: 0.375rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.pill {
  padding: 0.3125rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.pill:hover {
  border-color: var(--primary);
  color: var(--text);
}
.pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ---- Form card ---- */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 600px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}
.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* ---- Search bar ---- */
.search-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.search-bar input[type="text"] {
  flex: 1;
  min-width: 200px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--surface);
  transition: border-color 0.15s;
}
.search-bar input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
.search-bar select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--surface);
  min-width: 150px;
}

.btn-warning {
  background: var(--warning);
  color: #fff;
}
.btn-warning:hover {
  background: #d97706;
}

/* ---- Tables ---- */
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
thead th {
  text-align: left;
  padding: 0.625rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 0.625rem 0.75rem;
  font-size: 0.8125rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td {
  border-bottom: none;
}
tbody tr:hover {
  background: #f9fafb;
}

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-active {
  background: #dcfce7;
  color: #166534;
}
.badge-inactive {
  background: #fee2e2;
  color: #991b1b;
}
.badge-pending {
  background: #fef3c7;
  color: #92400e;
}
.badge-revoked {
  background: #fecaca;
  color: #991b1b;
}
.badge-expired {
  background: #e5e7eb;
  color: #374151;
}
.badge-hist-generated { background: #e0e7ff; color: #3730a3; }
.badge-hist-activated { background: #dcfce7; color: #166534; }
.badge-hist-extended { background: #dbeafe; color: #1e40af; }
.badge-hist-reduced { background: #ffedd5; color: #9a3412; }
.badge-hist-revoked,
.badge-hist-csv_revoked { background: #fecaca; color: #991b1b; }
.badge-hist-unrevoked { background: #dcfce7; color: #166534; }
.badge-hist-device_cleared { background: #f3e8ff; color: #6b21a8; }
.badge-hist-apptype_changed { background: #ccfbf1; color: #115e59; }
.badge-hist-price_changed { background: #fef3c7; color: #92400e; }
.badge-hist-version_changed { background: #e0e7ff; color: #3730a3; }
.badge-hist-bulk_extended { background: #dbeafe; color: #1e40af; }
.badge-hist-expiry_set { background: #fce7f3; color: #9d174d; }

.key-history-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.875rem;
  color: var(--text);
  word-break: break-all;
  margin: 0.25rem 0 0;
}
.key-history-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem 1rem;
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8125rem;
}
.key-history-summary .khs-label {
  display: block;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 0.1rem;
}
.hist-detail {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: 280px;
}
.hist-detail-main { font-size: 0.8125rem; }
.hist-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.35;
}
button.linkish {
  background: none;
  border: none;
  padding: 0;
  color: var(--primary);
  font: inherit;
  cursor: pointer;
  text-align: left;
  word-break: break-all;
}
button.linkish:hover { text-decoration: underline; }

/* ---- Action cells ---- */
.action-cell {
  white-space: nowrap;
  width: 1%;
  text-align: right;
  vertical-align: middle;
}
.hint-text {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  font-style: italic;
}
.check-field {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8125rem;
  color: var(--text);
  margin: 0.25rem 0 0.75rem;
}
.check-field input {
  width: auto;
}
.form-card h4 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

/* ---- Keys table polish ---- */
.keys-table-wrap {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.keys-table {
  box-shadow: none;
  border-radius: 0;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1100px;
}
.keys-table .created-cell {
  min-width: 9.5rem;
  white-space: nowrap;
}
.keys-table .created-cell .date-primary {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
}
.keys-table thead th {
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  font-size: 0.6875rem;
  white-space: nowrap;
}
.keys-table thead th.th-actions {
  width: 3rem;
}
.keys-table tbody td {
  border-bottom: 1px solid #eef1f5;
  padding: 0.85rem 1rem;
  vertical-align: middle;
}
.keys-table tbody tr:last-child td {
  border-bottom: none;
}
.keys-table tbody tr:hover {
  background: #f8fafc;
}
.keys-table .num-col {
  color: var(--text-secondary);
  width: 2.5rem;
}
.keys-table .price-cell {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.keys-table .agent-cell {
  color: var(--text-secondary);
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.days-stack,
.label-stack {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  line-height: 1.25;
}
.label-chip {
  display: inline-block;
  align-self: flex-start;
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.keys-table .label-cell {
  min-width: 7.5rem;
  max-width: 14rem;
}
body.role-agent .keys-table .th-agent,
body.role-agent .keys-table .agent-cell,
body.role-agent .keys-table .col-agent {
  display: none !important;
}
/* Only label visibility is permission-based for agents */
body.role-agent:not(.perm-key-labels) .keys-table .col-label {
  display: none !important;
}
body.role-agent .keys-table {
  min-width: 0;
  width: 100%;
}
body.role-agent .keys-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.row-actions {
  position: relative;
  display: inline-flex;
  justify-content: flex-end;
}
.btn-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.125rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-icon:hover,
.row-actions:has(.row-menu:not(.hidden)) .btn-icon {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text);
}
.row-menu {
  position: fixed;
  z-index: 1000;
  min-width: 11.5rem;
  padding: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  /* top/left set in JS so last-row menus are not clipped by table overflow */
}
.row-menu-item {
  appearance: none;
  border: none;
  background: transparent;
  text-align: left;
  padding: 0.55rem 0.75rem;
  font-size: 0.8125rem;
  font-family: inherit;
  color: var(--text);
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.row-menu-item:hover {
  background: #f3f4f6;
}
.row-menu-danger {
  color: var(--danger);
}
.row-menu-danger:hover {
  background: #fef2f2;
}

/* ---- Pagination ---- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  margin-top: 0.5rem;
}
.page-info {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}
.page-btns {
  display: flex;
  gap: 0.25rem;
}
.page-btns .btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---- Date display ---- */
.date-primary {
  display: block;
  font-size: 0.8125rem;
}
.date-ago {
  display: block;
  font-size: 0.6875rem;
  color: var(--text-secondary);
}
.text-muted {
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.num-col {
  color: var(--text-secondary);
  font-size: 0.75rem;
  width: 2rem;
  text-align: center;
}

.modal-wide {
  max-width: 720px;
  width: 94%;
}

/* Sheet modal: fixed Cancel header, scrollable body */
.modal-sheet {
  display: flex;
  flex-direction: column;
  max-height: min(92vh, 860px);
  width: min(94vw, 720px);
  max-width: 720px;
  padding: 0;
  overflow: hidden;
}
.modal-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}
.modal-sheet-header h4 {
  margin: 0;
  font-size: 1rem;
}
.modal-sheet-sub {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
}
.modal-sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0.85rem 1rem 1.25rem;
}
.modal-sheet-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}
.agent-access-sheet {
  width: min(96vw, 720px);
  max-width: 720px;
  max-height: min(94vh, 920px);
}
.agent-access-sheet .ms-list {
  max-height: 9.5rem;
}
.btn-xs {
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
  line-height: 1.2;
  border-radius: 6px;
}
.ms-toolbar .linkish {
  padding: 0.2rem 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 6px;
  word-break: normal;
  text-decoration: none;
}
.ms-toolbar .linkish:hover {
  background: #eef2ff;
  text-decoration: none;
}
.geo-access {
  margin: 0.35rem 0 1.1rem;
  padding: 0;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.geo-access-head {
  display: block;
}
.geo-kicker {
  margin: 0 0 0.15rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--primary);
}
.geo-access-title {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}
.geo-access-lead {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.45;
  max-width: 36rem;
}
.geo-path {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.geo-path-sep {
  color: #c4c9d4;
  font-weight: 500;
}
.geo-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  min-height: 2.4rem;
  align-items: center;
}
.geo-summary.is-empty {
  color: var(--text-secondary);
}
.geo-sum-empty {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.geo-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text);
  line-height: 1.2;
}
.geo-pill b {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.geo-pill.is-all {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
}
.geo-pill.is-pick {
  background: #eef2ff;
  border-color: #c7d2fe;
  color: #3730a3;
}
.geo-flow {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.geo-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.85rem 0.9rem;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  transition: border-color 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.geo-panel.is-required {
  border-color: #c7d2fe;
  box-shadow: 0 0 0 1px rgba(79, 70, 229, 0.08);
}
.geo-panel.is-ready {
  border-color: #a7f3d0;
}
.geo-panel.is-locked {
  background: #fafbfc;
}
.geo-panel.is-locked .ms,
.geo-panel.is-locked .ms-toolbar {
  display: none;
}
.geo-panel:not(.is-locked) .geo-lock-msg {
  display: none;
}
.geo-lock-msg {
  margin: 0.35rem 0 0;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  background: #f3f4f6;
  color: var(--text-secondary);
  font-size: 0.8rem;
  text-align: center;
}
.geo-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
}
.geo-panel-title {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  min-width: 0;
}
.geo-panel-title strong {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
}
.geo-panel-meta {
  display: block;
  margin-top: 0.1rem;
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 500;
}
.geo-step-num {
  flex: 0 0 auto;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #eef2ff;
  color: #4338ca;
  font-size: 0.75rem;
  font-weight: 700;
}
.geo-panel.is-ready .geo-step-num {
  background: #d1fae5;
  color: #047857;
}
.geo-panel.is-locked .geo-step-num {
  background: #e5e7eb;
  color: #6b7280;
}
.ms-toolbar {
  display: flex;
  gap: 0.15rem;
  flex-shrink: 0;
}
.req {
  color: var(--danger);
}
.ms-controls {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.geo-access .ms-chips:empty,
.geo-access .ms-chips:has(.ms-empty) {
  display: none;
}
.geo-access .ms-chips {
  margin-bottom: 0.35rem;
}
.geo-access .ms-list {
  max-height: 10rem;
  border-radius: 10px;
  background: #fbfcfe;
}
.geo-access .ms-option {
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
}
.geo-access .ms-add {
  margin-top: 0.15rem;
}
.geo-access .ms-add input {
  font-size: 0.8rem;
}
@media (max-width: 720px) {
  .geo-panel-head {
    flex-wrap: wrap;
  }
}
.key-history-table-wrap {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
}
.key-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}
.key-history-table th,
.key-history-table td {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid #eef1f5;
  text-align: left;
  vertical-align: top;
}
.keys-table .th-check,
.keys-table .check-cell {
  width: 2rem;
  text-align: center;
}
.version-cell {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.version-any {
  color: var(--text-secondary);
  font-size: 0.75rem;
}
.hidden {
  display: none !important;
}
.error-text {
  color: var(--danger);
  font-size: 0.8125rem;
  margin-top: 0.5rem;
}
.empty-msg {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
}
.key-text {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.75rem;
  word-break: break-all;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1.25rem;
  background: #1e293b;
  color: #fff;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  transition: opacity 0.3s, transform 0.3s;
  opacity: 1;
  transform: translateY(0);
}
.toast.hidden {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}
.toast.toast-error {
  background: var(--danger);
}
.toast.toast-success {
  background: var(--success);
}

/* ---- 3-column form row ---- */
.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 700px) {
  .form-row-3 {
    grid-template-columns: 1fr;
  }
}

.form-hint {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--muted, #6b7280);
  line-height: 1.4;
}

.text-danger {
  color: #b91c1c;
  font-weight: 600;
}

/* ---- appType badges ---- */
.badge-normal {
  background: #e0f2fe;
  color: #075985;
}
.badge-pro {
  background: #fdf4ff;
  color: #7e22ce;
  border: 1px solid #e9d5ff;
}
.badge-pro-max {
  background: #1e1b4b;
  color: #c7d2fe;
  border: 1px solid #4338ca;
}
.badge-upload {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}

/* ---- Copy button ---- */
.btn-copy {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn-copy:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-copy.copied {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}
.key-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}
.keys-table .key-text {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
}

/* ---- Sort bar ---- */
.sort-bar-row {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.sort-label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-right: 0.25rem;
}
.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.sort-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.sort-arrow {
  font-size: 0.75rem;
  line-height: 1;
}

/* ---- Button spinner ---- */
.btn-spinner {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* ---- Generated keys result ---- */
.gen-keys-list {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.875rem;
}
.gen-keys-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.gen-keys-list h5 {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.gen-key-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.375rem;
}
.gen-key-item .key-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.75rem;
}

/* ---- Modal ---- */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 0.75rem;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-content {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 400px;
  max-height: calc(100vh - 1.5rem);
}
.modal-content.modal-sheet {
  padding: 0;
}
.modal-content h4 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.modal-content .field {
  margin-bottom: 1rem;
}

/* ---- Applicant Images browser ---- */
.images-browser {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 0;
  margin-top: 0;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
}
.images-tree-pane {
  border-right: 1px solid var(--border);
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.images-tree-head {
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  flex-shrink: 0;
}
.images-tree-head strong { font-size: 0.8125rem; }
.images-tree-head .text-muted { font-size: 0.6875rem; }
.images-tree {
  padding: 0.25rem;
  overflow-x: hidden;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.tree-node { margin: 0; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  font: inherit;
  color: inherit;
  padding: 0.28rem 0.35rem;
  border-radius: 6px;
  cursor: pointer;
}
.tree-row:hover { background: #eef2ff; }
.tree-row.active {
  background: #e0e7ff;
  color: #312e81;
  font-weight: 600;
}
.tree-chevron {
  width: 1rem;
  color: var(--text-secondary);
  flex-shrink: 0;
  font-size: 0.7rem;
}
.tree-folder-icon {
  width: 1.1rem;
  height: 0.9rem;
  border-radius: 2px;
  background: linear-gradient(160deg, #fde68a 0%, #f59e0b 100%);
  flex-shrink: 0;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,0.08);
}
.tree-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8125rem;
}
.tree-count {
  font-size: 0.6875rem;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.tree-children {
  margin-left: 0.85rem;
  padding-left: 0.45rem;
  border-left: 1px solid #e2e8f0;
}
.tree-children.collapsed { display: none; }
.tree-loading,
.tree-empty {
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.images-main-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #fff;
}
.images-main-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 0.6rem;
  padding: 0.4rem 0.65rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.images-path {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}
.images-search-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}
.images-search-inline input {
  width: 120px;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 0.75rem;
}
.images-main-body {
  flex: 1;
  padding: 0.5rem;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
  border: none;
  box-shadow: none;
  background: transparent;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.images-main-pane .pagination {
  padding: 0.35rem 0.65rem 0.5rem;
  flex-shrink: 0;
}

.images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.5rem;
}
.image-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding-bottom: 0.45rem;
}
.image-thumb {
  display: block;
  aspect-ratio: 1;
  background: #eef1f6;
  overflow: hidden;
}
.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  image-orientation: from-image;
}
.image-meta {
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
  padding: 0 0.45rem;
  font-size: 0.6875rem;
  min-width: 0;
}
.image-meta strong {
  font-size: 0.75rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.image-meta .image-regno,
.image-meta .text-muted {
  overflow-wrap: anywhere;
  word-break: break-all;
  white-space: normal;
  line-height: 1.35;
}
.image-card .image-delete {
  margin: 0 0.45rem;
  align-self: flex-start;
  padding: 0.2rem 0.45rem;
  font-size: 0.6875rem;
}

.modal-content.modal-crop {
  max-width: min(960px, 94vw);
  max-height: 92vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.crop-ratio-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.35rem 0 0.5rem;
  flex-shrink: 0;
}
.crop-ratio-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  min-height: 2.25rem;
  padding: 0.4rem 0.75rem;
}
.crop-ratio-btn.active {
  background: #0ea5e9;
  border-color: #0284c7;
  color: #fff;
}
.crop-stage-wrap {
  position: relative;
  width: 100%;
  min-height: 280px;
  max-height: min(62vh, 640px);
  overflow: auto;
  background: #0f172a;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
}
#crop-stage {
  display: block;
  /* Keep intrinsic canvas pixel aspect — never stretch to fill width */
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
  cursor: crosshair;
  -webkit-user-drag: none;
  background: #000;
}
.crop-actions {
  position: sticky;
  bottom: 0;
  background: var(--surface, #fff);
  padding-top: 0.75rem;
  margin-top: 0.25rem;
  gap: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.crop-actions .btn {
  flex: 0 0 auto;
  min-width: 7.5rem;
  min-height: 2.5rem;
}
#crop-size-info {
  flex-shrink: 0;
  font-size: 0.8125rem;
  margin: 0.25rem 0 0;
}
body.crop-open {
  overflow: hidden;
  overscroll-behavior: none;
}
.img-crop-preview-wrap {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.img-crop-preview-wrap img {
  max-width: 220px;
  max-height: 220px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f8fafc;
}
.img-crop-preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.8rem;
  color: var(--muted, #64748b);
}
.image-card .image-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  padding: 0 0.5rem 0.5rem;
}
.image-card .image-actions .btn {
  margin: 0;
  min-height: 2.25rem;
}

@media (max-width: 768px) {
  #image-crop-modal.modal {
    align-items: stretch;
    padding: 0;
  }
  .modal-content.modal-crop {
    width: 100%;
    max-width: 100%;
    max-height: 100dvh;
    min-height: 100dvh;
    height: 100dvh;
    margin: 0;
    border-radius: 0;
    padding: 0.65rem 0.65rem calc(0.65rem + env(safe-area-inset-bottom));
    overflow: hidden;
  }
  .modal-content.modal-crop > h4,
  .modal-content.modal-crop > .hint-text {
    flex-shrink: 0;
  }
  .modal-content.modal-crop > .hint-text {
    display: none;
  }
  .crop-stage-wrap {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow: hidden;
  }
  #crop-stage {
    max-width: 100%;
    max-height: 100%;
  }
  .crop-ratio-bar {
    justify-content: stretch;
    margin: 0.25rem 0;
  }
  .crop-ratio-btn {
    flex: 1 1 calc(50% - 0.4rem);
    font-size: 0.875rem;
  }
  .crop-actions .btn {
    flex: 1 1 auto;
    font-size: 1rem;
    min-height: 2.75rem;
  }
  .image-card .image-actions {
    gap: 0.5rem;
  }
  .image-card .image-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
}

.images-tree-head-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}
.images-tree-sub {
  display: block;
  margin-top: 0.1rem;
}
.images-path-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  flex: 1;
}
.images-folders-open-btn {
  flex-shrink: 0;
}

@media (max-width: 900px) {
  #tab-images.active {
    padding: 0.4rem 0.5rem 0.5rem;
  }
  #tab-images .section-header {
    flex-wrap: wrap;
    gap: 0.4rem;
  }
  #tab-images .section-header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
  }
  #tab-images .section-header-actions .btn {
    width: 100%;
    justify-content: center;
  }
  .images-browser {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
    flex: 1;
  }
  .images-tree-pane {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: min(34vh, 260px);
    min-height: 0;
  }
  .images-browser.folders-collapsed {
    grid-template-rows: minmax(0, 1fr);
  }
  .images-browser.folders-collapsed .images-tree-pane {
    display: none;
  }
  .images-browser.folders-collapsed .images-folders-open-btn {
    display: inline-flex;
  }
  .images-folders-open-btn.hidden {
    display: none !important;
  }
  .images-main-pane {
    min-height: 50vh;
  }
  .images-main-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .images-path {
    font-size: 0.75rem;
  }
  .images-search-inline {
    width: 100%;
  }
  .images-search-inline input {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
  }
  .images-search-inline .btn {
    flex: 0 0 auto;
  }
  .images-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.4rem;
  }
}

@media (min-width: 901px) {
  .images-folders-open-btn {
    display: none !important;
  }
  #images-folders-toggle {
    display: none;
  }
}

@media (max-width: 800px) {
  .app-header {
    flex-wrap: wrap;
    padding: 0.5rem 0.85rem;
    gap: 0.5rem;
  }
  .nav-toggle {
    display: inline-flex;
  }
  .topbar-right {
    order: 2;
    margin-left: 0;
  }
  .topbar-right #admin-name {
    display: none;
  }
  .tabs {
    display: none;
    order: 3;
    flex: 1 1 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    padding: 0.5rem 0 0.25rem;
    border-top: 1px solid var(--border);
    overflow: visible;
  }
  .app-header.nav-open .tabs {
    display: flex;
  }
  .tab {
    width: 100%;
    text-align: left;
    padding: 0.7rem 0.85rem;
  }
  .tab.active {
    border-radius: 8px;
  }
}

/* ---- Role badge ---- */
.role-badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--primary);
  border: 1px solid #c7d2fe;
}

/* ---- Dashboard cards ---- */
.dash-filters {
  align-items: flex-end;
  margin-bottom: 1.25rem;
}
.dash-filters .field label {
  margin-bottom: 0.25rem;
}
.dash-filters input[type="date"],
.dash-filters select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--surface);
  min-width: 140px;
}

.dash-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.dash-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.125rem;
  box-shadow: var(--shadow);
}
.dash-card-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}
.dash-card-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}
.dash-card-revenue .dash-card-value {
  color: var(--success);
  font-size: 1.35rem;
}

.dash-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
}
@media (max-width: 900px) {
  .dash-panels {
    grid-template-columns: 1fr;
  }
}

.dash-byday {
  max-height: 320px;
  overflow-y: auto;
}
.dash-day-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
}
.dash-day-row:last-child {
  border-bottom: none;
}
.dash-day-date {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.dash-day-count {
  color: var(--text-secondary);
}
.dash-day-rev {
  font-weight: 600;
  color: var(--success);
  min-width: 4.5rem;
  text-align: right;
}

/* ---- Mobile: Keys page + shared admin chrome ---- */
@media (max-width: 768px) {
  .tab-content {
    padding: 0.85rem;
  }

  #tab-keys .section-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  #tab-keys .section-header-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  #tab-keys .section-header-actions .btn {
    width: 100%;
    justify-content: center;
    white-space: normal;
    text-align: center;
    padding: 0.55rem 0.5rem;
    font-size: 0.75rem;
    line-height: 1.25;
  }

  #tab-keys .section-header-actions #gen-key-btn {
    grid-column: 1 / -1;
  }

  #tab-keys .search-bar {
    flex-direction: column;
    align-items: stretch;
  }

  #tab-keys .search-bar input[type="text"],
  #tab-keys .search-bar select {
    width: 100%;
    min-width: 0;
  }

  #tab-keys .search-bar .btn {
    width: 100%;
  }

  #tab-keys .sort-bar-row {
    gap: 0.35rem;
  }

  #tab-keys .sort-bar-row .sort-btn {
    flex: 1 1 auto;
    justify-content: center;
    font-size: 0.75rem;
    padding: 0.45rem 0.5rem;
  }

  #tab-keys .status-pills {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.35rem;
    padding-bottom: 0.25rem;
    margin-bottom: 0.75rem;
  }

  #tab-keys .status-pills .pill {
    flex: 0 0 auto;
    font-size: 0.75rem;
    padding: 0.35rem 0.7rem;
  }

  #tab-keys .form-card {
    padding: 0.9rem;
  }

  #tab-keys .form-actions {
    flex-wrap: wrap;
  }

  #tab-keys .form-actions .btn {
    flex: 1 1 auto;
    min-width: 7rem;
  }

  .keys-table-wrap {
    border: none;
    background: transparent;
    box-shadow: none;
    overflow: visible;
  }

  .keys-table {
    min-width: 0;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 0.65rem;
  }

  .keys-table thead {
    display: none;
  }

  .keys-table tbody {
    display: block;
  }

  .keys-table tbody tr {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 0.65rem 0.75rem;
    margin: 0;
  }

  .keys-table tbody tr:hover {
    background: var(--surface);
  }

  .keys-table tbody td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    border: none;
    border-bottom: 1px solid #eef1f5;
    padding: 0.55rem 0;
    white-space: normal;
    max-width: none;
    overflow: visible;
    text-overflow: unset;
  }

  .keys-table tbody td:last-child {
    border-bottom: none;
    padding-bottom: 0.15rem;
  }

  .keys-table tbody td.col-hidden {
    display: none !important;
  }

  body.role-agent:not(.perm-key-labels) .keys-table tbody td.col-label {
    display: none !important;
  }

  body.role-agent .keys-table tbody td.col-key {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
  }

  body.role-agent .keys-table .key-text {
    text-align: left;
    font-size: 0.8125rem;
  }

  .keys-table tbody td::before {
    content: attr(data-label);
    flex: 0 0 5.25rem;
    max-width: 36%;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding-top: 0.15rem;
  }

  .keys-table tbody td > * {
    min-width: 0;
    max-width: 100%;
  }

  .keys-table .num-col {
    width: auto;
  }

  .keys-table .agent-cell {
    max-width: none;
    white-space: normal;
  }

  .keys-table .key-cell {
    flex-wrap: wrap;
    white-space: normal;
    justify-content: flex-end;
  }

  .keys-table .key-text {
    word-break: break-all;
    white-space: normal;
    font-size: 0.75rem;
    text-align: right;
  }

  .keys-table .created-cell {
    min-width: 0;
    white-space: normal;
  }

  .keys-table .action-cell {
    justify-content: flex-end;
  }

  .keys-table .action-cell::before {
    align-self: center;
    padding-top: 0;
  }

  .keys-table .row-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .gen-key-item {
    flex-wrap: wrap;
  }

  .gen-key-item .key-text {
    word-break: break-all;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
  }

  .toast {
    left: 0.75rem;
    right: 0.75rem;
    bottom: 0.75rem;
  }

  .pagination {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.35rem;
  }

  .modal {
    align-items: flex-end;
    padding: 0;
  }

  .modal-content:not(.modal-sheet) {
    margin: 0.75rem;
    max-height: 90vh;
    overflow-y: auto;
  }

  .modal-sheet,
  .key-history-sheet {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    margin: 0;
  }

  .modal-sheet-header {
    position: sticky;
    top: 0;
    z-index: 2;
  }

  .key-history-table thead {
    display: none;
  }

  .key-history-table,
  .key-history-table tbody,
  .key-history-table tr,
  .key-history-table td {
    display: block;
    width: 100%;
  }

  .key-history-table tbody tr {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.55rem 0.7rem;
    margin-bottom: 0.55rem;
  }

  .key-history-table tbody td {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    border: none;
    border-bottom: 1px solid #eef1f5;
    padding: 0.4rem 0;
  }

  .key-history-table tbody td:last-child {
    border-bottom: none;
  }

  .key-history-table tbody td::before {
    content: attr(data-label);
    flex: 0 0 5rem;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
  }

  .key-history-table-wrap {
    border: none;
    overflow: visible;
  }

  .keys-table tbody td.check-cell::before {
    content: none;
  }

  .keys-table tbody td.check-cell {
    justify-content: flex-end;
    border-bottom: 1px solid #eef1f5;
  }
}

/* Multi-select geo access (checkbox list — click to toggle many) */
.ms {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.ms-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  min-height: 1.6rem;
}
.ms-chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.78rem;
  cursor: pointer;
  line-height: 1.4;
}
.ms-chip:hover {
  border-color: var(--primary, #2563eb);
  color: var(--primary, #2563eb);
}
.ms-empty,
.ms-empty-row {
  color: var(--text-secondary);
  font-size: 0.8rem;
  padding: 0.35rem 0.25rem;
}
.ms-hint-row {
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 0.3rem 0.45rem 0.45rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.2rem;
}
.ms-filter {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
}
.ms-list {
  width: 100%;
  max-height: 10.5rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 0.25rem;
}
.ms-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.45rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  user-select: none;
}
.ms-option:hover {
  background: var(--bg);
}
.ms-option.is-on {
  background: color-mix(in srgb, var(--primary, #2563eb) 12%, transparent);
}
.ms-option input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary, #2563eb);
  flex-shrink: 0;
}
.ms-add {
  display: flex;
  gap: 0.4rem;
}
.ms-add input {
  flex: 1;
}
.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 720px) {
  .form-row-2 {
    grid-template-columns: 1fr;
  }
}
