:root {
  --bg: #f5f6f8; --panel: #ffffff; --panel2: #f0f2f5; --text: #18202b; --muted: #677285; --line: #e2e5ea;
  --accent: #2563eb; --accent-weak: #e7eefd;
  --used: #16a34a; --assigned: #7fb88f; --host: #7c3aed; --reserved: #0284c7; --blocked: #4b5563;
  --vmac: #f59e0b; --free: #eef0f3; --free-line: #dfe3e8;
  --error: #dc2626; --warning: #d97706; --info: #2563eb;
  --ok: #16a34a; --idle: #d97706; --down: #dc2626;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b; --panel: #161d27; --panel2: #1c2532; --text: #e6eaf0; --muted: #8b96a8; --line: #273142;
    --accent: #5b8def; --accent-weak: #1d2b45;
    --used: #22c55e; --assigned: #4f8a62; --host: #a78bfa; --reserved: #38bdf8; --blocked: #6b7280;
    --vmac: #fbbf24; --free: #1b2330; --free-line: #263041;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 13px; margin: 16px 0 8px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: 340px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.err { color: var(--error); min-height: 1em; margin: 0; }

/* Layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100%; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: .02em; padding: 0 8px 18px; }
.brand b { color: var(--accent); }
.brand.big { font-size: 18px; padding: 0 0 8px; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent);
  background-image: radial-gradient(#fff 1.4px, transparent 1.6px); background-size: 6px 6px; background-position: 2px 2px; }
nav { display: grid; gap: 2px; }
nav a { color: var(--text); padding: 8px 10px; border-radius: 8px; }
nav a:hover { background: var(--panel2); text-decoration: none; }
nav a.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
nav a .badge { float: right; }
.side-foot { margin-top: auto; display: grid; gap: 4px; padding: 0 8px; }
main { min-width: 0; }
.top { display: flex; align-items: center; gap: 16px; padding: 16px 28px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.search { flex: 1; max-width: 460px; margin-left: auto; }
.search input { width: 100%; }
.view { padding: 24px 28px 48px; max-width: 1500px; }

/* Bausteine */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .cols-4 { grid-template-columns: repeat(2, 1fr); } .cols-2, .cols-3 { grid-template-columns: 1fr; } }
.kpi .v { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 4px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label input, label select, label textarea { color: var(--text); }
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; }
.btn:hover { background: var(--panel2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--error); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 0; text-align: left; font: inherit; }
.link:hover { color: var(--accent); }
.x { position: absolute; right: 12px; top: 10px; border: 0; background: none; font-size: 24px; color: var(--muted); cursor: pointer; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel2); }
.table-wrap { overflow-x: auto; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--panel2); white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; font-size: 11px; font-weight: 700; text-align: center; color: #fff; }
.badge.error { background: var(--error); } .badge.warning { background: var(--warning); } .badge.info { background: var(--info); }
.sev { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; flex: none; transform: translateY(5px); }
.sev.error { background: var(--error); } .sev.warning { background: var(--warning); } .sev.info { background: var(--info); }
.sev.ok { background: var(--ok); } .sev.off { background: var(--idle); }
.st-used { background: var(--used); } .st-assigned { background: var(--assigned); } .st-host { background: var(--host); }
.st-reserved { background: var(--reserved); } .st-blocked { background: var(--blocked); } .st-vmac { background: var(--vmac); }
.st-free { background: var(--free); border: 1px solid var(--free-line); }

/* IP-Karte */
.ipgrid { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 3px; }
.ipgrid.mini { gap: 2px; }
.cell { aspect-ratio: 1.6; border-radius: 4px; display: grid; place-items: center; font: 600 11px/1 var(--mono); color: #fff; cursor: pointer; position: relative; border: 1px solid transparent; user-select: none; }
.ipgrid.mini .cell { aspect-ratio: 1.2; font-size: 0; border-radius: 2px; cursor: default; }
.cell.st-free { color: var(--muted); font-weight: 500; }
.cell.st-assigned { color: #fff; }
.cell.c-error { box-shadow: 0 0 0 2px var(--error); z-index: 1; }
.cell.c-warning { box-shadow: 0 0 0 2px var(--warning); }
.cell.dim { opacity: .18; }
.cell .site { position: absolute; top: 1px; right: 3px; font-size: 8px; opacity: .85; }
.ipgrid.mini .cell .site { display: none; }
.cell:hover { outline: 2px solid var(--text); outline-offset: 1px; z-index: 2; }
.ipgrid.mini .cell:hover { outline: none; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend i.ring { background: transparent; box-shadow: inset 0 0 0 2px var(--error); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 12px; cursor: pointer; font-size: 13px; color: var(--text); }
.chip.on { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); }

.bar { height: 8px; border-radius: 999px; background: var(--free); display: flex; overflow: hidden; border: 1px solid var(--free-line); min-width: 140px; }
.bar > span { height: 100%; }

/* Konflikte / Ereignisse */
.list { display: grid; }
.list .item { display: flex; gap: 4px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.list .item:last-child { border-bottom: 0; }
.list .item .meta { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

/* Drawer & Modal */
.drawer { position: fixed; inset: 0; z-index: 20; }
.drawer-bg { position: absolute; inset: 0; background: rgba(10,14,20,.35); }
.drawer-panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(560px, 100%); background: var(--panel); border-left: 1px solid var(--line); padding: 24px; overflow-y: auto; }
.modal { position: fixed; inset: 0; z-index: 30; background: rgba(10,14,20,.45); display: grid; place-items: center; padding: 20px; }
.modal-card { position: relative; background: var(--panel); border-radius: 14px; border: 1px solid var(--line); padding: 24px; width: min(520px, 100%); max-height: 90vh; overflow-y: auto; }
.form { display: grid; gap: 12px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.src { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.src .k { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 40; }
.toast.bad { background: var(--error); color: #fff; }
.tokenbox { font-family: var(--mono); background: var(--panel2); border: 1px dashed var(--accent); padding: 12px; border-radius: 8px; word-break: break-all; }
pre.code { font-family: var(--mono); font-size: 12px; background: var(--panel2); padding: 12px; border-radius: 8px; overflow-x: auto; margin: 0; }

/* Topologie */
.topo { width: 100%; height: auto; }
.topo .node rect { fill: var(--panel2); stroke: var(--line); stroke-width: 1.5; }
.topo .node.off rect { stroke: var(--down); stroke-dasharray: 4 3; }
.topo .node text { fill: var(--text); font-size: 13px; }
.topo .node text.sub { fill: var(--muted); font-size: 11px; font-family: var(--mono); }
.topo .site-label { fill: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; font-weight: 650; }
.topo line { stroke-width: 2.5; }
.topo line.up { stroke: var(--ok); } .topo line.idle { stroke: var(--idle); stroke-dasharray: 6 4; } .topo line.down { stroke: var(--down); stroke-dasharray: 3 4; }
.topo .lbl { fill: var(--muted); font-size: 10px; font-family: var(--mono); }
.state { font-weight: 600; } .state.up { color: var(--ok); } .state.idle { color: var(--idle); } .state.down { color: var(--down); }
.nodecard .hd { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.nodecard .hd b { font-size: 15px; }
.online { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--ok); }
.online.off { background: var(--down); }
.brand .tld { color: var(--muted); font-weight: 500; margin-left: -8px; }

.ptr-in.dirty { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-weak); }

/* ---------------------------------------------------------------- Handy / schmale Fenster */
.menu-btn { display: none; }
.side-bg { display: none; }
@media (max-width: 760px) {
  body { font-size: 15px; -webkit-text-size-adjust: 100%; }
  .app { display: block; }
  .side { position: fixed; z-index: 25; left: 0; top: 0; bottom: 0; height: 100%; width: min(280px, 84vw);
          transform: translateX(-102%); transition: transform .2s ease; box-shadow: 0 0 24px rgba(0,0,0,.25);
          padding: calc(18px + env(safe-area-inset-top)) 12px calc(18px + env(safe-area-inset-bottom)); overflow-y: auto; }
  .app.nav-open .side { transform: none; }
  .app.nav-open .side-bg { display: block; position: fixed; inset: 0; z-index: 24; background: rgba(10,14,20,.45); }
  nav a { padding: 12px 12px; font-size: 15px; }
  .side-foot { padding: 12px 8px 0; }
  .side-foot .link { padding: 10px 0; }

  .top { flex-wrap: wrap; gap: 8px 10px; padding: calc(8px + env(safe-area-inset-top)) 12px 10px; }
  .menu-btn { display: inline-grid; align-content: center; gap: 4px; width: 40px; height: 40px; padding: 0 10px;
              border: 1px solid var(--line); border-radius: 10px; background: var(--panel); cursor: pointer; flex: none; }
  .menu-btn span { display: block; height: 2px; border-radius: 2px; background: var(--text); }
  h1 { font-size: 18px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #updated { display: none; }
  .search { order: 3; flex: 1 0 100%; max-width: none; margin: 0; }
  .view { padding: 12px 10px calc(40px + env(safe-area-inset-bottom)); }

  .card { padding: 14px; }
  .grid { gap: 10px; }
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .v { font-size: 22px; }
  input, select, textarea { font-size: 16px; padding: 9px 10px; }   /* kein Auto-Zoom auf iOS */
  .btn { padding: 9px 14px; }
  .btn.sm { padding: 7px 12px; font-size: 14px; }
  .chip { padding: 6px 12px; }
  .legend { gap: 8px 12px; }

  .ipgrid { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
  .ipgrid.mini { grid-template-columns: repeat(16, minmax(0, 1fr)); }
  .cell { aspect-ratio: 1.5; font-size: 11px; }
  .cell:hover { outline: none; }

  /* Datentabellen als Karten: jede Zeile ein Block, Spaltentitel als Beschriftung */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; margin-bottom: 8px; background: var(--panel); }
  table.stack td { border: 0; padding: 4px 0 4px 36%; position: relative; min-height: 26px; overflow-wrap: anywhere; }
  table.stack td::before { content: attr(data-label); position: absolute; left: 0; top: 6px; width: 33%; color: var(--muted); font-size: 11px;
                           text-transform: uppercase; letter-spacing: .03em; line-height: 1.3; overflow-wrap: anywhere; }
  table.stack td[data-label=""] { padding-left: 0; }
  table.stack td[data-label=""]::before { display: none; }
  table.stack td:empty { display: none; }
  tr.click:hover td { background: none; }
  .table-wrap { overflow-x: visible; }
  .bar { min-width: 0; }

  .drawer-panel { width: 100%; border-left: 0; padding: calc(16px + env(safe-area-inset-top)) 14px calc(24px + env(safe-area-inset-bottom)); }
  .x { top: calc(6px + env(safe-area-inset-top)); right: 6px; width: 44px; height: 44px; }
  .modal { padding: 10px; align-items: end; }
  .modal-card { padding: 18px 14px; max-height: 92vh; border-radius: 14px 14px 10px 10px; }
  .kv { grid-template-columns: 110px 1fr; }
  .login-card { width: 100%; max-width: 360px; padding: 26px 20px; }
  .toast { left: 10px; right: 10px; transform: none; bottom: calc(14px + env(safe-area-inset-bottom)); text-align: center; }
}
