:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f8;
  --bg-hover: #f2f2f3;
  --border: #e6e6e8;
  --border-strong: #d4d4d8;
  --text: #0a0a0b;
  --text-2: #52525b;
  --text-3: #8b8b93;
  --primary: #0a0a0b;
  --primary-hover: #27272a;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --ok: #15803d;
  --ok-soft: #f0fdf4;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .08);
  --sidebar-w: 240px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
[hidden] { display: none !important; }
a { color: inherit; }
h1 { font-size: 24px; font-weight: 600; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 15px; font-weight: 600; margin: 0; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
code, .mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12px; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0;
  height: 100vh; background: var(--bg);
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { padding: 28px 32px 48px; max-width: 1200px; width: 100%; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 8px 16px; }
.brand-lg { font-size: 20px; padding: 0 0 4px; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, #111 0%, #555 100%); position: relative; }
.brand-mark::after { content: ""; position: absolute; inset: 7px 5px; border-left: 2px solid #fff; border-right: 2px solid #fff; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-group { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  text-decoration: none; color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--bg-hover); color: var(--text); }
.nav a.active { background: var(--bg-hover); color: var(--text); }
.nav-ico { width: 18px; text-align: center; font-size: 13px; }

.sidebar-foot { position: relative; border-top: 1px solid var(--border); padding-top: 10px; }
.profile-btn {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px; border: 0; background: none;
  border-radius: var(--radius-sm); cursor: pointer; font: inherit; color: var(--text); text-align: left;
}
.profile-btn:hover { background: var(--bg-hover); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--text); color: #fff;
  display: grid; place-items: center; font-weight: 600; font-size: 12px; text-transform: uppercase; flex-shrink: 0;
}
.profile-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.chev { color: var(--text-3); font-size: 11px; }
.menu {
  position: absolute; bottom: 52px; left: 0; right: 0; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 4px; z-index: 20;
}
.menu button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none;
  font: inherit; border-radius: 6px; cursor: pointer; color: var(--text);
}
.menu button:hover { background: var(--bg-hover); }

/* ---------- status bar ---------- */
.statusbar {
  display: flex; align-items: center; gap: 16px; padding: 12px 32px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px); z-index: 10;
  min-height: 57px;
}
.status-items { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; flex: 1; min-width: 0; }
.stat { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.stat-label { color: var(--text-3); font-size: 12px; }
.stat-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--text-2); font-size: 12px; }
.stat.warn .stat-value { color: var(--warn); }
.credit-meter { width: 90px; height: 6px; border-radius: 3px; background: var(--bg-hover); overflow: hidden; align-self: center; }
.credit-meter > span { display: block; height: 100%; background: var(--text); border-radius: 3px; }
.stat.warn .credit-meter > span { background: var(--warn); }
.status-error { color: var(--danger); font-size: 13px; }
.menu-toggle { display: none; }

/* ---------- elements ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 32px; height: 32px; border-radius: var(--radius-sm); border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 16px; color: var(--text-2); display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--text-2); }
input[type=text], input[type=password], input:not([type]), select, textarea {
  height: 38px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font: inherit; color: var(--text); background: var(--bg); outline: none; width: 100%;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--text); box-shadow: 0 0 0 3px rgba(0, 0, 0, .06); }
.form-error { background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 14px; font-size: 13px; }
.form-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.form-row .field { margin-bottom: 0; flex: 1; min-width: 180px; }

.card { border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; background: var(--bg); }
.card + .card { margin-top: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }

.pill {
  display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 999px;
  background: var(--bg-hover); color: var(--text-2); font-size: 12px; font-weight: 500; white-space: nowrap;
}
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-off { background: var(--bg-hover); color: var(--text-3); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-dark { background: var(--text); color: #fff; }

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 500; color: var(--text-3); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.empty { text-align: center; padding: 48px 16px; color: var(--text-2); }
.empty-ico { font-size: 28px; margin-bottom: 8px; color: var(--text-3); }

.skeleton { display: inline-block; background: linear-gradient(90deg, #f0f0f1 25%, #e7e7e9 37%, #f0f0f1 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: 6px; }
.skeleton-text { height: 14px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.secret-box { display: flex; gap: 8px; align-items: center; background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin: 12px 0; }
.secret-box code { flex: 1; font-size: 15px; letter-spacing: .02em; word-break: break-all; }

/* ---------- modal & toasts ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--bg); border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 440px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; }
.modal-body { padding: 16px 20px 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: #fff; padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow); max-width: 380px; font-size: 13px; }
.toast.error { background: var(--danger); }

/* ---------- login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; background: var(--bg-soft); padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--bg); border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); }
.login-card .muted { margin: 4px 0 24px; }

/* ---------- placeholder ---------- */
.placeholder { border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 48px 24px; text-align: center; color: var(--text-2); }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-grid; }
  .statusbar { padding: 10px 16px; }
  .content { padding: 20px 16px 40px; }
  .credit-meter { display: none; }
}
