:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #dde3ec;
  --text: #1c2733;
  --muted: #64748b;
  --primary: #1d3557;
  --primary-light: #2d5a8e;
  --accent: #2a9d8f;
  --danger: #c0392b;
  --warn: #d68910;
  --ok: #1e8449;
  --sidebar-bg: #16213a;
  --sidebar-text: #c7d2e5;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(16, 30, 54, .08), 0 1px 2px rgba(16, 30, 54, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--primary-light); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.subtitle { color: var(--muted); margin: 0 0 18px; }

/* layout */
#app { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand {
  padding: 18px 20px 14px; font-size: 19px; font-weight: 700; color: #fff; letter-spacing: .5px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand span { color: #7fd1c7; }
.nav-section { padding: 14px 12px 2px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.2px; color: #6b7a99; }
.nav-item {
  display: block; padding: 8px 20px; color: var(--sidebar-text); border-left: 3px solid transparent;
  cursor: pointer; user-select: none;
}
.nav-item:hover { background: rgba(255,255,255,.05); text-decoration: none; }
.nav-item.active { background: rgba(255,255,255,.08); border-left-color: var(--accent); color: #fff; }
.sidebar .spacer { flex: 1; }
.sidebar .footer { padding: 14px 20px; font-size: 11.5px; color: #6b7a99; border-top: 1px solid rgba(255,255,255,.08); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--panel); border-bottom: 1px solid var(--border); padding: 10px 24px;
  display: flex; align-items: center; gap: 14px; position: sticky; top: 0; z-index: 5;
}
.topbar .grow { flex: 1; }
.topbar .userbox { text-align: right; line-height: 1.25; }
.topbar .userbox .name { font-weight: 600; }
.topbar .userbox .role { font-size: 11.5px; color: var(--muted); }
.content { padding: 24px; max-width: 1280px; width: 100%; }

/* cards & tables */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card.tight { padding: 0; overflow: hidden; }
.card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-header h2 { margin: 0; flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
@media (max-width: 1000px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: 10px 12px; border-bottom: 2px solid var(--border); }
td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f0f4fa; }

/* stats */
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; }
.stat .value { font-size: 26px; font-weight: 700; }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat.red .value { color: var(--danger); }
.stat.amber .value { color: var(--warn); }
.stat.green .value { color: var(--ok); }

/* forms */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
label.field .req { color: var(--danger); }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=url], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(45, 90, 142, .35); border-color: var(--primary-light); }
textarea { resize: vertical; min-height: 64px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px;
  border: 1px solid transparent; background: var(--primary); color: #fff; font: inherit; font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--primary-light); }
.btn.secondary { background: #fff; color: var(--primary); border-color: var(--border); }
.btn.secondary:hover { background: #f0f4fa; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #a93226; }
.btn.small { padding: 4px 10px; font-size: 12.5px; font-weight: 500; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; background: #e8edf5; color: var(--primary); white-space: nowrap; }
.badge.green { background: #d9f2e3; color: var(--ok); }
.badge.amber { background: #fdf0d8; color: var(--warn); }
.badge.red { background: #fadbd8; color: var(--danger); }
.badge.gray { background: #eef1f5; color: var(--muted); }
.badge.accent { background: #d7efec; color: #1a7d71; }

/* zone tree */
.tree { list-style: none; margin: 0; padding: 0; }
.tree ul { list-style: none; margin: 0; padding-left: 24px; border-left: 1px dashed var(--border); margin-left: 10px; }
.tree-node { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 6px; }
.tree-node:hover { background: #f0f4fa; }
.tree-node .zname { font-weight: 600; cursor: pointer; }
.tree-node .zmeta { color: var(--muted); font-size: 12px; flex: 1; }
.tree-node .actions { visibility: hidden; display: flex; gap: 6px; }
.tree-node:hover .actions { visibility: visible; }
.site-icon { color: var(--accent); }

/* graph */
.graph-wrap { position: relative; background: #fbfcfe; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.graph-wrap svg { display: block; width: 100%; }
.graph-legend { position: absolute; top: 10px; left: 12px; background: rgba(255,255,255,.92); border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; font-size: 12px; color: var(--muted); }
.graph-node { cursor: pointer; }
.graph-node circle { fill: #fff; stroke: var(--primary-light); stroke-width: 2; }
.graph-node.focus circle { fill: #fdebd0; stroke: var(--warn); stroke-width: 3; }
.graph-node text { font-size: 11px; fill: var(--text); pointer-events: none; }
.graph-node .uid { font-size: 9.5px; fill: var(--muted); }
.graph-edge { stroke: #9fb3cd; stroke-width: 1.6; fill: none; marker-end: url(#arrow); }
.graph-edge-label { font-size: 10px; fill: var(--danger); font-weight: 600; }

/* maturity */
.maturity-opts { display: flex; gap: 6px; flex-wrap: wrap; }
.maturity-opts button {
  border: 1px solid var(--border); background: #fff; border-radius: 6px; padding: 6px 10px; cursor: pointer;
  font: inherit; font-size: 12.5px;
}
.maturity-opts button.selected { background: var(--primary); border-color: var(--primary); color: #fff; }
.maturity-opts button.na.selected { background: var(--muted); border-color: var(--muted); }
.spe-block { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.spe-head { background: #eef2f8; padding: 10px 16px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.spe-head .avg { margin-left: auto; }
.question { padding: 12px 16px; border-top: 1px solid var(--border); }
.question .qtext { margin-bottom: 8px; }
.question .guidance { font-size: 12px; color: var(--muted); margin-bottom: 8px; }

.bar-bg { background: #e8edf5; border-radius: 10px; height: 10px; overflow: hidden; width: 100%; }
.bar-fill { height: 100%; border-radius: 10px; background: var(--accent); }

/* modal */
#modal-root:empty { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(12, 22, 40, .5); display: flex;
  align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto;
}
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; padding: 22px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal.wide { max-width: 760px; }
.modal h2 { margin-bottom: 16px; }

/* toast */
#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--primary); color: #fff; padding: 10px 18px; border-radius: 8px; box-shadow: var(--shadow); animation: fadein .2s; }
.toast.error { background: var(--danger); }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

/* login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #16213a 0%, #1d3557 100%); width: 100%; }
.login-card { background: #fff; border-radius: 12px; padding: 34px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-card .brand { font-size: 26px; font-weight: 800; color: var(--primary); margin-bottom: 2px; }
.login-card .brand span { color: var(--accent); }
.login-card .tagline { color: var(--muted); margin-bottom: 22px; font-size: 13px; }

.empty { color: var(--muted); padding: 24px; text-align: center; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.sys-image { width: 100%; max-height: 260px; object-fit: contain; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.field-list-row { display: grid; grid-template-columns: 1fr 1fr 110px 90px 34px; gap: 8px; align-items: center; margin-bottom: 8px; }
.inline-actions { display: flex; gap: 6px; }
.breadcrumb { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }

/* impersonation */
.impersonation-banner {
  display: flex; align-items: center; gap: 10px;
  background: #fdf3e2; border-bottom: 2px solid var(--warn);
  color: #7a4e07; padding: 10px 24px; font-size: 13px;
}
.impersonation-banner .imp-dot { color: var(--warn); font-size: 11px; }
.impersonation-banner .grow { flex: 1; }
.impersonation-banner .btn { background: var(--warn); }
.impersonation-banner .btn:hover { background: #b8770d; }
.sidebar.impersonating { background: #2a2113; }
.sidebar.impersonating .nav-item.active { border-left-color: var(--warn); }
