/* Kovexy. One stylesheet, no framework, styles based on Dirl. Light and dark follow the system setting. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --fg: #16181d;
  --muted: #5f6672;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --accent: #2f6fed;
  --accent-fg: #ffffff;
  --accent-soft: #e8effd;
  --ok: #138a52;
  --ok-soft: #e3f5ec;
  --warn: #b35c00;
  --warn-soft: #fdf0e1;
  --error: #c8322a;
  --error-soft: #fbe9e8;
  --code: #f1f3f6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
  --mono: ui-monospace, "JetBrains Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  /* Strength of the glow in the corners of every page, see body::before. */
  --glow: .05;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1c2027;
    --fg: #e7e9ee;
    --muted: #9aa2b1;
    --border: #272c35;
    --border-strong: #353b47;
    --accent: #5b8dff;
    --accent-fg: #0b1020;
    --accent-soft: #1b2640;
    --ok: #3ccf8e;
    --ok-soft: #12291f;
    --warn: #f2a54a;
    --warn-soft: #2d2113;
    --error: #ff6b61;
    --error-soft: #331716;
    --code: #11141a;
    --shadow: none;
    --glow: .16;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 24px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 0 0 12px; }
code, pre, .mono { font-family: var(--mono); font-size: 13px; }

/* Shell: a fixed sidebar with the grouped navigation on the left, the page on the right. On phones a top bar
   with a menu that opens the same list (details/summary, no JavaScript). */
.shell { display: flex; flex: 1; min-height: 100vh; min-height: 100dvh; }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 22px;
  width: 228px;
  height: 100vh;
  height: 100dvh;
  flex-shrink: 0;
  padding: 18px 12px 14px;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.sidebar .brand { padding: 0 8px; }
.topbar { display: none; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--fg); }
.brand:hover { text-decoration: none; }
.brand .logo {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-fg);
  font-family: var(--mono);
  font-size: 14px;
}
.side-nav { display: grid; gap: 18px; }
.nav-group { display: grid; gap: 1px; align-content: start; }
.nav-heading { padding: 0 10px 4px; color: var(--muted); font-size: 11px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; }
.side-nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.side-nav a:hover { background: var(--surface-2); color: var(--fg); text-decoration: none; }
.side-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.logout { margin: auto 0 0; padding-top: 12px; border-top: 1px solid var(--border); }
.logout .btn { width: 100%; }
.shell.bare { flex-direction: column; }
.topbar.plain { display: flex; align-items: center; min-height: 56px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { display: none; }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 52px;
    padding: 8px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
  .menu { margin: 0; padding: 0; border: 0; }
  .menu > summary { list-style: none; cursor: pointer; margin: 0; color: var(--fg); }
  .menu > summary::-webkit-details-marker { display: none; }
  .menu > summary::before {
    content: "";
    width: 14px;
    height: 10px;
    background: linear-gradient(currentColor 0 0) top / 100% 2px no-repeat, linear-gradient(currentColor 0 0) center / 100% 2px no-repeat,
      linear-gradient(currentColor 0 0) bottom / 100% 2px no-repeat;
  }
  .menu[open] > summary { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
  .menu-panel {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: calc(100dvh - 52px);
    overflow-y: auto;
    padding: 14px 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(16, 24, 40, .12);
  }
  .menu-panel .side-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; align-items: start; }
}

/* Page */
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 24px 20px 48px; flex: 1; }
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-header .subtitle { color: var(--muted); margin: 4px 0 0; }
.page-header .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.stack { display: grid; gap: 16px; }
.columns { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }
footer { flex-shrink: 0; text-align: center; color: var(--muted); font-size: 12px; padding: 8px 16px 24px; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  min-width: 0;
}
.card > h2 { margin-bottom: 12px; }
.card .card-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card.danger { border-color: color-mix(in srgb, var(--error) 35%, var(--border)); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.break { overflow-wrap: anywhere; }
.strike { text-decoration: line-through; }

/* Centered pages: login */
.center-wrap { min-height: calc(100vh - 120px); display: grid; place-items: center; padding: 24px 16px; }
.center-card { width: 100%; max-width: 440px; }
.center-card .brand { justify-content: center; margin-bottom: 20px; font-size: 22px; }
.center-card .brand .logo { width: 36px; height: 36px; font-size: 18px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--error); border-color: color-mix(in srgb, var(--error) 40%, var(--border)); }
.btn.danger:hover { background: var(--error-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--fg); }
.btn.sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-row > input, .btn-row > .field { flex: 1 1 200px; width: auto; }
.btn-row > .field { margin: 0; }
.kv + p, .kv + .code, .kv + .form { margin-top: 14px; }
form.inline { display: inline; }

/* Forms */
.form { display: grid; gap: 14px; }
.form .grid-2 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 550; font-size: 14px; }
.field .hint { color: var(--muted); font-size: 12.5px; }
input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  width: 100%;
  padding: 8px 11px;
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 1px;
}
textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { margin-top: 4px; }
input[type=file] { font: inherit; }

/* Notices */
.notice { display: flex; gap: 10px; padding: 11px 14px; border-radius: 10px; margin-bottom: 16px; border: 1px solid transparent; }
.notice.info { background: var(--accent-soft); color: var(--accent); }
.notice.success { background: var(--ok-soft); color: var(--ok); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.error { background: var(--error-soft); color: var(--error); }

/* Pills, chips */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 550;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.pill.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.pill.error { color: var(--error); background: var(--error-soft); border-color: transparent; }
/* Key value lists */
.kv { display: grid; grid-template-columns: minmax(110px, max-content) 1fr; gap: 8px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-weight: 600; color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
th.num { text-align: right; }
td.nowrap { white-space: nowrap; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { text-align: right; white-space: nowrap; }
td.actions > * + * { margin-left: 6px; }

/* Code with copy button */
.code { position: relative; }
.code pre {
  margin: 0;
  padding: 12px 84px 12px 14px;
  background: var(--code);
  border: 1px solid var(--border);
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-all;
}
.code .btn { position: absolute; top: 7px; right: 7px; }
code.inline { background: var(--code); padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere; }

/* Group headings */
.group-title { margin: 10px 2px 0; font-size: 14px; color: var(--muted); }
.group-title .muted { font-weight: 400; }

/* Disclosure */
details { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
details summary { cursor: pointer; color: var(--muted); font-weight: 550; margin-bottom: 12px; }
/* A faint glow in the corners of every page, in blue, cyan and violet. Fixed behind everything, static,
   stronger in dark mode. Green, yellow and red stay free for the status. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(42rem 32rem at 0% 0%, rgb(91 141 255 / var(--glow)), transparent 70%),
    radial-gradient(42rem 32rem at 100% 0%, rgb(167 139 250 / calc(var(--glow) * .85)), transparent 70%),
    radial-gradient(42rem 32rem at 0% 100%, rgb(34 211 238 / calc(var(--glow) * .7)), transparent 70%),
    radial-gradient(42rem 32rem at 100% 100%, rgb(91 141 255 / calc(var(--glow) * .7)), transparent 70%);
}

/* The logo as a tile with a gradient frame, on the pages before the work. */
.center-card .brand .logo {
  position: relative;
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 0 24px rgb(91 141 255 / .35);
}
.center-card .brand .logo::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 10px;
  padding: 2px;
  background: linear-gradient(135deg, #22d3ee, var(--accent), #a78bfa);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}
/* The login card gets a light edge running along its top. */
.center-card > .card { position: relative; overflow: hidden; }
.center-card > .card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #22d3ee, var(--accent), #a78bfa, #22d3ee) 0 0 / 200% 100%;
  animation: edge-run 8s linear infinite;
}
@keyframes edge-run { to { background-position: 200% 0; } }


/* Kovexy additions */
.banner {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 9px 20px;
  background: var(--warn-soft);
  color: var(--warn);
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 30%, var(--border));
  font-weight: 550;
  font-size: 14px;
}
.stats-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .label { color: var(--muted); font-size: 13px; }
.top-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.top-grid .card { margin: 0; }
.top-list { width: 100%; }
.top-list td { padding: 4px 0; border-top: 1px solid var(--border); font-size: 13px; }
.top-list .top-key { overflow-wrap: anywhere; padding-right: 12px; }
.chart { display: block; width: 100%; height: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filters .field { flex: 1 1 160px; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px 14px; margin: 0; display: grid; gap: 12px; }
legend { padding: 0 6px; color: var(--muted); font-weight: 600; font-size: 13px; }
.server-table input[type=text], .server-table input[type=number] { min-width: 90px; }
.problems { margin: 0; padding-left: 20px; }
/* Only the fields of the chosen target type, without JavaScript */
.target-fields { display: none; }
form:has(select[name=targetType] option[value=upstream]:checked) .target-upstream,
form:has(select[name=targetType] option[value=static]:checked) .target-static,
form:has(select[name=targetType] option[value=redirect]:checked) .target-redirect,
form:has(select[name=targetType] option[value=deny]:checked) .target-deny { display: grid; }
@supports not selector(:has(*)) { .target-fields { display: grid; } }

/* Tables stack on phones: every cell becomes a row with its column name in front. */
@media (max-width: 720px) {
  table.stack-mobile thead { display: none; }
  table.stack-mobile, table.stack-mobile tbody, table.stack-mobile tr, table.stack-mobile td { display: block; width: 100%; }
  table.stack-mobile tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  table.stack-mobile td { border: 0; padding: 3px 0; text-align: left; white-space: normal; }
  table.stack-mobile td[data-label]::before { content: attr(data-label); display: inline-block; min-width: 110px; color: var(--muted); font-size: 12.5px; }
  table.stack-mobile td.actions { text-align: left; }
  .container { padding: 16px 12px 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .center-card > .card::before { animation: none; }
}
.gap-top { margin-top: 16px; }
pre.diff { margin: 0; padding: 8px 10px; background: var(--code); border: 1px solid var(--border); border-radius: 8px; font-size: 12px; white-space: pre-wrap; word-break: break-all; max-height: 320px; overflow: auto; }
select[multiple] { min-height: 140px; }
