:root {
  color-scheme: dark;
  font-family: Arial, "Segoe UI", sans-serif;
  color: #d7dce2;
  background: #111418;
  --bg: #111418;
  --sidebar: #15191e;
  --surface: #191e24;
  --surface-hover: #20262d;
  --border: #2a3139;
  --muted: #89929d;
  --text: #d7dce2;
  --accent: #3b82c4;
  --green: #42b883;
  --red: #d86770;
  --amber: #d2a855;
}

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

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(360px, 100%); display: grid; gap: 16px; padding: 28px; border: 1px solid var(--border); background: var(--surface); border-radius: 4px; }
.login-panel h1 { margin: 0; font-size: 21px; font-weight: 600; }
.login-panel p { margin: 7px 0 0; color: var(--muted); line-height: 1.4; }

label { display: grid; gap: 6px; color: #aeb5be; font-size: 13px; }
input, select, textarea { width: 100%; padding: 9px 10px; color: var(--text); background: #12161b; border: 1px solid var(--border); border-radius: 3px; outline: none; }
textarea { min-height: 86px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #557a9d; }

button { border: 0; border-radius: 3px; }
.primary, .danger { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; padding: 0 14px; font-weight: 600; }
.primary { color: #fff; background: var(--accent); }
.primary:hover { background: #477fad; }
.danger { color: #fff; background: #a94e56; }
.danger:hover { background: #b85861; }
.danger.ghost { color: #df7b83; background: transparent; border: 1px solid #784047; }
.full { width: 100%; }
.form-error { min-height: 17px; margin: 0 !important; color: #df7b83 !important; font-size: 13px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 196px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 10px 12px; background: var(--sidebar); border-right: 1px solid var(--border); }
.brand { padding: 2px 10px 22px; }
.brand strong { font-size: 15px; font-weight: 600; color: #f0f2f4; }
nav { display: grid; gap: 3px; }
.nav-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; color: #9da6b0; background: transparent; text-align: left; }
.nav-item svg { width: 17px; height: 17px; }
.nav-item:hover { color: var(--text); background: #1d2329; }
.nav-item.active { color: #fff; background: #29313a; }
.logout { margin-top: auto; }

main { min-width: 0; padding: 0 26px 36px; }
.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; border-bottom: 1px solid var(--border); }
.topbar h2 { margin: 0; font-size: 20px; font-weight: 600; }
.status-line { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.status-line strong { margin-left: 12px; color: var(--text); font-weight: 500; }
.status-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: var(--green); }
.page { display: none; }
.page.active { display: block; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric-grid article { min-height: 88px; display: grid; align-content: center; gap: 8px; padding: 15px 16px; border: 1px solid var(--border); background: var(--surface); border-radius: 4px; }
.metric-grid span { color: var(--muted); font-size: 12px; }
.metric-grid strong { font-size: 25px; font-weight: 600; }

.panel { border: 1px solid var(--border); background: var(--surface); border-radius: 4px; }
.panel.compact { padding: 16px; }
.panel-heading { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.panel-heading h3 { margin: 0; font-size: 15px; font-weight: 600; }
.health-row { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.health-row strong { color: var(--text); font-weight: 600; }
.icon-button { width: 31px; height: 31px; display: grid; place-items: center; color: #aab3bd; background: transparent; border: 1px solid var(--border); }
.icon-button:hover { color: #fff; background: var(--surface-hover); }
.icon-button svg { width: 15px; height: 15px; }

.split-layout { display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
.stack { display: grid; gap: 16px; }
.form-panel { display: grid; gap: 13px; padding: 16px; }
.form-panel .panel-heading { margin: -2px 0 0; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.file-picker { min-height: 64px; display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); background: #14191e; border: 1px dashed #39434d; border-radius: 3px; cursor: pointer; }
.file-picker:hover { color: var(--text); border-color: #596775; }
.file-picker input { display: none; }
.file-picker svg { width: 17px; }

.table-panel { overflow: hidden; }
.table-panel > .panel-heading { margin: 0; padding: 0 15px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 14px; border-bottom: 1px solid #272e36; text-align: left; vertical-align: middle; white-space: nowrap; }
th { color: #8b949f; font-size: 11px; font-weight: 600; background: #171b20; }
td { color: #c1c7ce; }
tbody tr:hover { background: #1c2228; }
tbody tr:last-child td { border-bottom: 0; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; }
.muted { color: var(--muted); }
.badge { display: inline-flex; align-items: center; min-height: 22px; padding: 0 7px; border-radius: 3px; font-size: 11px; font-weight: 600; }
.badge.green { color: #77c8a3; background: #1b392e; }
.badge.red { color: #e58a91; background: #3a2226; }
.badge.amber { color: #d9ba76; background: #3a3220; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.row-actions button { min-height: 28px; padding: 0 8px; color: #adb6c0; background: #20262d; border: 1px solid var(--border); }
.row-actions button:hover { color: #fff; background: #28313a; }
.empty { padding: 28px; color: var(--muted); text-align: center; }

.generated-keys { margin: 14px; padding: 12px; border: 1px solid #365b4c; background: #182820; border-radius: 3px; }
.generated-keys header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.generated-keys pre { margin: 0; white-space: pre-wrap; word-break: break-all; color: #8ccdb0; }
.search-heading { flex-wrap: wrap; padding-top: 8px !important; padding-bottom: 8px !important; }
.search { width: min(430px, 100%); display: grid; grid-template-columns: auto 1fr auto; align-items: center; background: #12161b; border: 1px solid var(--border); border-radius: 3px; }
.search svg { width: 15px; margin-left: 10px; color: var(--muted); }
.search input { border: 0; box-shadow: none; }
.search button { height: 31px; margin-right: 3px; padding: 0 12px; color: #dfe4e9; background: #29313a; }
.client-details { margin-top: 16px; padding: 16px; }
.identity-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.identity-grid div { padding: 11px; background: #151a1f; border: 1px solid var(--border); border-radius: 3px; }
.identity-grid span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; }

dialog { width: min(540px, calc(100% - 32px)); padding: 0; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 4px; }
dialog::backdrop { background: rgba(0, 0, 0, .72); }
.dialog-form { display: grid; gap: 13px; padding: 18px; }
.dialog-form .panel-heading { margin: 0; }
.dialog-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 4px; }
.dialog-actions button { min-width: 120px; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 20; max-width: 420px; padding: 10px 13px; color: var(--text); background: #222930; border: 1px solid var(--border); border-left: 3px solid var(--green); border-radius: 3px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .15s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-left-color: var(--red); }

@media (max-width: 980px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .split-layout { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .app-shell { grid-template-columns: 58px minmax(0, 1fr); }
  .sidebar { padding: 14px 7px 10px; }
  .brand { height: 36px; padding: 0; }
  .brand strong, .nav-item span { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  main { padding: 0 12px 26px; }
  .topbar { height: 64px; }
  .status-line > span:not(.status-dot), .status-line strong { display: none; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .identity-grid { grid-template-columns: 1fr; }
}
