:root {
  --canvas: #f7f5f2;
  --surface: #ffffff;
  --surface-muted: #f1efeb;
  --sidebar: #22211f;
  --sidebar-muted: #aaa59c;
  --text: #26231f;
  --muted: #6e6961;
  --border: #dedad3;
  --accent: #a64b2a;
  --accent-hover: #873c21;
  --danger: #a33232;
  --success: #33705a;
  --radius: 8px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body { margin: 0; min-height: 100vh; color: var(--text); font-family: Aptos, "Helvetica Neue", sans-serif; font-size: 15px; line-height: 1.45; }
button, input, select { font: inherit; }
a { color: inherit; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: 26px; line-height: 1.2; font-weight: 600; letter-spacing: -0.02em; }
h2 { margin-bottom: 4px; font-size: 17px; line-height: 1.3; font-weight: 600; }
p { margin-bottom: 0; color: var(--muted); }
code { font-family: "Cascadia Mono", Consolas, monospace; font-size: 13px; }

.portal-body { background: var(--canvas); }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 248px; display: flex; flex-direction: column; padding: 24px 16px 18px; color: #f6f3ee; background: var(--sidebar); border-right: 1px solid #33312e; }
.wordmark { display: flex; align-items: center; gap: 11px; padding: 0 8px; color: inherit; font-weight: 600; text-decoration: none; }
.wordmark-mark { width: 18px; height: 18px; display: inline-block; background: var(--accent); border-radius: 4px; box-shadow: inset 0 0 0 4px rgba(255,255,255,.18); }
.wordmark-light { padding: 0; color: #fff; }
.primary-nav { display: grid; gap: 4px; margin-top: 38px; }
.primary-nav a { padding: 9px 10px; color: var(--sidebar-muted); border-radius: 6px; text-decoration: none; transition: color 150ms ease, background 150ms ease; }
.primary-nav a:hover { color: #fff; background: #2d2b28; }
.primary-nav a.active { color: #fff; background: #35322e; }
.sidebar-account { margin-top: auto; padding: 16px 8px 0; border-top: 1px solid #3a3733; }
.sidebar-account strong, .sidebar-account span { display: block; }
.sidebar-account strong { font-weight: 600; }
.sidebar-account span { margin-top: 2px; color: var(--sidebar-muted); font-size: 13px; }
.sidebar-account form { margin-top: 12px; }
.portal-main { min-height: 100vh; margin-left: 248px; padding: 32px clamp(24px, 4vw, 56px) 64px; }
.portal-main > * { max-width: 1280px; margin-right: auto; margin-left: auto; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 24px; }

.button { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; padding: 7px 13px; border: 1px solid transparent; border-radius: 7px; background: transparent; font-weight: 600; cursor: pointer; transition: background 150ms ease, border-color 150ms ease; }
.button-primary { color: #fff; background: var(--accent); }
.button-primary:hover { background: var(--accent-hover); }
.button-secondary { color: var(--text); background: var(--surface); border-color: var(--border); }
.button-secondary:hover { background: var(--surface-muted); }
.button-danger { min-height: 32px; padding: 5px 10px; color: var(--danger); border-color: #e6c9c4; }
.button-danger:hover { background: #fff3f1; }
.button-quiet { min-height: 30px; padding: 4px 0; color: #ddd8cf; font-weight: 400; }
.button-quiet:hover { color: #fff; }
.button-full { width: 100%; }

.summary-strip { display: flex; align-items: stretch; margin-bottom: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.summary-strip div { min-width: 150px; flex: 1; padding: 17px 20px; }
.summary-strip div + div { border-left: 1px solid var(--border); }
.summary-strip span, .summary-strip strong { display: block; }
.summary-strip span { color: var(--muted); font-size: 13px; }
.summary-strip strong { margin-top: 4px; font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }

.section-block { margin-bottom: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: visible; }
.section-header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.section-header p { font-size: 13px; }
.search-field input { width: 220px; }

label { display: grid; gap: 6px; color: #4b4741; font-size: 13px; font-weight: 600; }
input, select { width: 100%; min-height: 38px; padding: 8px 10px; color: var(--text); background: var(--surface); border: 1px solid #cfcac1; border-radius: 7px; outline: none; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(166,75,42,.12); }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 16px; text-align: left; vertical-align: middle; border-bottom: 1px solid #ebe8e3; white-space: nowrap; }
th { color: var(--muted); background: #fbfaf8; font-size: 12px; font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fcfbf9; }
td strong, .cell-secondary { display: block; }
td strong { font-weight: 600; }
.cell-secondary { margin-top: 2px; color: var(--muted); font-size: 12px; }
.actions-cell { width: 1%; text-align: right; }
.empty-row { padding: 32px; color: var(--muted); text-align: center; }
.filename-cell { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.status { display: inline-block; padding: 2px 7px; color: #59544d; background: #eeece8; border-radius: 6px; font-size: 12px; text-transform: capitalize; }
.status-active { color: #275c49; background: #e8f2ed; }
.status-disabled, .status-failed { color: #833232; background: #f7eaea; }

.action-menu { position: relative; }
.action-menu summary { color: var(--accent); cursor: pointer; list-style: none; font-weight: 600; }
.action-menu summary::-webkit-details-marker { display: none; }
.action-menu-panel { position: absolute; z-index: 10; top: 28px; right: 0; width: 250px; display: grid; gap: 12px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 2px 8px rgba(36,32,28,.12); text-align: left; }
.action-menu-panel form { display: grid; gap: 9px; }

.dialog { width: min(540px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(32,29,25,.18); }
.dialog::backdrop { background: rgba(25,23,21,.52); }
.dialog form { display: grid; gap: 20px; padding: 22px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.dialog-header p { font-size: 13px; }
.dialog-close { padding: 2px; color: var(--muted); background: none; border: 0; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }

.new-key-panel { display: grid; gap: 16px; margin-bottom: 24px; padding: 18px 20px; background: #fff8ef; border: 1px solid #e7caa8; border-radius: var(--radius); }
.key-copy-row { display: flex; gap: 10px; }
.key-copy-row code { min-width: 0; flex: 1; padding: 10px 12px; overflow-x: auto; background: #fff; border: 1px solid #dfd3c3; border-radius: 7px; white-space: nowrap; }
.settings-block { padding: 16px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.settings-block summary { cursor: pointer; font-weight: 600; }
.settings-form { max-width: 680px; display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 12px; margin-top: 16px; }

.flash { margin-bottom: 20px; padding: 11px 14px; color: #275c49; background: #e8f2ed; border: 1px solid #c9dfd4; border-radius: 7px; }
.flash-error { color: #833232; background: #f7eaea; border-color: #e9c9c9; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.login-body, .login-main { min-height: 100vh; }
.login-main { display: grid; place-items: center; padding: 32px; background: var(--canvas); }
.login-main .flash { position: fixed; top: 20px; left: 50%; z-index: 2; transform: translateX(-50%); }
.login-shell { width: min(900px, 100%); min-height: 540px; display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 2px 8px rgba(32,29,25,.08); }
.login-brand { display: flex; flex-direction: column; padding: 42px; color: #fff; background: #282622; }
.login-brand-copy { margin: auto 0; }
.login-brand h1 { max-width: 330px; margin-bottom: 12px; font-size: 34px; color: #fff; }
.login-brand p { max-width: 340px; color: #bbb5ab; }
.login-address { font-size: 13px; }
.login-form-panel { display: grid; place-items: center; padding: 42px; }
.login-form { width: min(320px, 100%); display: grid; gap: 18px; }
.form-heading { margin-bottom: 8px; }
.form-heading h2 { font-size: 24px; }
.form-heading p { font-size: 14px; }

@media (max-width: 800px) {
  .sidebar { position: static; width: 100%; min-height: auto; flex-direction: row; align-items: center; gap: 20px; padding: 14px 18px; }
  .primary-nav { display: flex; margin: 0; }
  .sidebar-account { display: flex; align-items: center; gap: 12px; margin: 0 0 0 auto; padding: 0; border: 0; }
  .sidebar-account > div { display: none; }
  .sidebar-account form { margin: 0; }
  .portal-main { margin-left: 0; padding: 24px 16px 48px; }
  .summary-strip { overflow-x: auto; }
  .summary-strip div { min-width: 145px; }
  .form-grid { grid-template-columns: 1fr; }
  .settings-form { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .login-main { padding: 16px; }
  .login-shell { min-height: auto; grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .login-form-panel { min-height: 500px; padding: 30px; }
  .page-header { align-items: flex-start; }
  .page-header .button { flex: 0 0 auto; }
  .section-header { align-items: flex-start; flex-direction: column; }
  .search-field, .search-field input { width: 100%; }
  .sidebar .wordmark { padding: 0; }
  .primary-nav a { padding: 7px 8px; font-size: 13px; }
}
