:root {
  --gold: #b88a2f;
  --gold-dark: #8d671e;
  --gold-soft: #f7f0df;
  --ink: #201d18;
  --muted: #706b62;
  --line: #e7e1d6;
  --surface: #ffffff;
  --canvas: #f7f6f3;
  --success: #287a4b;
  --danger: #b54343;
  --warning: #9b6912;
  --shadow: 0 12px 34px rgba(43, 35, 21, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 5%, #fff 0, var(--canvas) 55%); }
.login-card { width: min(430px, 100%); padding: 42px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); text-align: center; }
.login-card .brand-mark { margin: 0 auto 20px; }
.login-card h1 { margin: 4px 0 8px; font-size: 30px; letter-spacing: -0.03em; }
.login-card .stack-form { margin-top: 28px; text-align: left; }

.brand-mark { width: 54px; height: 54px; border-radius: 17px; display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, #d4ad57, #987020); font-weight: 800; letter-spacing: -0.04em; box-shadow: 0 8px 20px rgba(184, 138, 47, 0.25); }
.brand-mark.small { width: 42px; height: 42px; border-radius: 13px; font-size: 14px; box-shadow: none; }
.eyebrow { margin: 0 0 5px; color: var(--gold-dark); font-size: 11px; font-weight: 800; letter-spacing: 0.14em; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 245px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 22px 16px; background: #211e19; color: #fff; }
.brand-area { display: flex; gap: 12px; align-items: center; padding: 0 8px 25px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand-area strong, .brand-area span { display: block; }
.brand-area strong { font-size: 15px; }
.brand-area span { margin-top: 2px; color: #c2bbae; font-size: 12px; }
.sidebar nav { display: grid; gap: 6px; margin-top: 24px; }
.nav-item { border: 0; border-radius: 10px; padding: 11px 13px; background: transparent; color: #cbc4b8; text-align: left; font-weight: 600; transition: .18s ease; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: linear-gradient(90deg, rgba(184,138,47,.38), rgba(184,138,47,.12)); box-shadow: inset 3px 0 var(--gold); }
.sidebar-footer { margin-top: auto; display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 18px 8px 0; border-top: 1px solid rgba(255,255,255,.1); }
.socket-status { color: #aca498; font-size: 10px; }
.socket-status.online { color: #7ed6a2; }
.text-button { padding: 4px; border: 0; background: transparent; color: #d9d2c6; font-size: 12px; }

.content { min-width: 0; padding: 28px 34px 50px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.topbar h1 { margin: 0; font-size: 28px; letter-spacing: -0.035em; }
.topbar-actions, .section-actions, .panel-actions, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tab-panel { animation: appear .18s ease; }
@keyframes appear { from { opacity: 0; transform: translateY(3px); } }

.button { min-height: 39px; border: 1px solid transparent; border-radius: 9px; padding: 9px 14px; font-weight: 700; font-size: 13px; transition: .18s ease; }
.button:hover { transform: translateY(-1px); }
.button.primary { background: var(--gold); color: #fff; }
.button.primary:hover { background: var(--gold-dark); }
.button.secondary { border-color: var(--line); background: #fff; color: var(--ink); }
.button.secondary:hover { border-color: #c9bda7; }
.button.danger-outline { border-color: #e3bcbc; background: #fff; color: var(--danger); }
.button.small { min-height: 31px; padding: 5px 9px; font-size: 11px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; margin-bottom: 18px; }
.metric-card { padding: 19px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); box-shadow: 0 4px 18px rgba(43,35,21,.04); }
.metric-card span { color: var(--muted); font-size: 12px; font-weight: 600; }
.metric-card strong { display: block; margin-top: 8px; font-size: 27px; letter-spacing: -0.04em; }
.panel-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, .8fr); gap: 18px; }
.panel { padding: 23px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 4px 18px rgba(43,35,21,.04); }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.panel h2 { margin: 0; font-size: 19px; letter-spacing: -0.02em; }
.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 99px; padding: 5px 10px; font-size: 11px; font-weight: 800; }
.badge.success { color: var(--success); background: #e7f5ed; }
.badge.danger { color: var(--danger); background: #faeaea; }
.badge.warning { color: var(--warning); background: #fff3d7; }
.badge.neutral { color: #655f56; background: #eeeae4; }
.connection-content { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 25px; align-items: center; }
.qr-container { aspect-ratio: 1; display: grid; place-items: center; padding: 12px; border: 1px dashed #d9cfbf; border-radius: 14px; background: #fbfaf8; }
.qr-container img { display: block; width: 100%; height: 100%; object-fit: contain; }
.qr-placeholder { max-width: 150px; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: center; }
.details-list { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; margin: 0; }
.details-list div { min-width: 0; }
.details-list dt { margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.details-list dd { margin: 0; overflow: hidden; font-size: 13px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.panel-actions { justify-content: flex-end; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.queue-summary { display: grid; gap: 10px; }
.queue-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.queue-row:last-child { border-bottom: 0; }
.queue-row span { color: var(--muted); font-size: 13px; }
.queue-row strong { font-size: 18px; }
.help-text { margin: 20px 0 0; padding: 14px; border-radius: 10px; background: var(--gold-soft); color: #6f5729; font-size: 12px; line-height: 1.55; }

.section-actions { margin-bottom: 14px; }
.section-actions p { margin: 0; font-size: 13px; }
.table-panel { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { padding: 13px 15px; border-bottom: 1px solid var(--line); background: #fbfaf8; color: var(--muted); font-size: 10px; letter-spacing: .07em; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { max-width: 330px; padding: 14px 15px; border-bottom: 1px solid #eeeae3; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fffdf9; }
.cell-title { display: block; font-weight: 750; }
.cell-subtitle { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-cell { padding: 40px 20px; color: var(--muted); text-align: center; }
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { border-radius: 5px; padding: 3px 6px; background: #f1eee8; color: #635d53; font-size: 9px; font-weight: 700; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.subtabs { display: flex; gap: 4px; margin-bottom: 18px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.subtab { border: 0; border-radius: 8px; padding: 8px 13px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; }
.subtab.active { background: var(--gold-soft); color: var(--gold-dark); }

.stack-form { display: grid; gap: 10px; }
.stack-form label { color: #514d46; font-size: 12px; font-weight: 700; }
.stack-form input, .stack-form select, .stack-form textarea { width: 100%; border: 1px solid #dcd5c9; border-radius: 9px; padding: 10px 11px; background: #fff; color: var(--ink); outline: none; }
.stack-form textarea { min-height: 90px; resize: vertical; }
.stack-form input:focus, .stack-form select:focus, .stack-form textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(184,138,47,.12); }
.form-error { min-height: 18px; margin: 2px 0 0; color: var(--danger); font-size: 12px; }
.checkbox-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 9px; }
.checkbox-grid label { display: flex; gap: 7px; align-items: flex-start; font-size: 11px; font-weight: 600; }
.checkbox-grid input { width: auto; margin-top: 1px; }

.dialog { width: min(560px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 17px; padding: 23px; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(25,22,17,.55); backdrop-filter: blur(2px); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; }
.dialog-header h2 { margin: 0; font-size: 21px; }
.icon-button { width: 32px; height: 32px; border: 0; border-radius: 8px; background: #f3f0eb; color: #615a4f; font-size: 21px; line-height: 1; }
.dialog-actions { justify-content: flex-end; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.small-dialog { width: min(620px, calc(100vw - 32px)); }
.secret-box { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; align-items: center; margin-top: 18px; }
.secret-box code { overflow: auto; padding: 13px; border: 1px solid var(--line); border-radius: 9px; background: #f8f6f2; font-size: 11px; white-space: nowrap; }
.toast { position: fixed; right: 25px; bottom: 25px; z-index: 10; max-width: 380px; border-radius: 10px; padding: 12px 16px; background: #24211c; color: #fff; box-shadow: var(--shadow); font-size: 12px; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 780px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 14px; }
  .brand-area { padding-bottom: 12px; }
  .sidebar nav { display: flex; overflow-x: auto; margin-top: 12px; padding-bottom: 4px; }
  .nav-item { flex: 0 0 auto; }
  .sidebar-footer { display: none; }
  .content { padding: 22px 16px 40px; }
  .topbar { align-items: flex-end; }
  .topbar h1 { font-size: 24px; }
  #lastUpdate { display: none; }
  .connection-content { grid-template-columns: 1fr; }
  .qr-container { width: min(260px, 100%); margin: auto; }
}

@media (max-width: 520px) {
  .login-card { padding: 28px 22px; }
  .metric-grid { grid-template-columns: 1fr; }
  .details-list { grid-template-columns: 1fr; }
  .section-actions { align-items: flex-start; flex-direction: column; }
  .section-actions .button { width: 100%; }
  .checkbox-grid { grid-template-columns: 1fr; }
  .secret-box { grid-template-columns: 1fr; }
}
