/* MikroTik VPN Backoffice */
:root {
  --ink: #18222d;
  --ink-2: #4d5b68;
  --muted: #7b8894;
  --paper: #eef2f5;
  --surface: #ffffff;
  --line: #d5dce2;
  --line-2: #e6ebef;
  --steel: #1f2c39;
  --steel-2: #2a3a4a;
  --steel-ink: #c9d4de;
  --accent: #1d5bbd;
  --accent-ink: #ffffff;
  --accent-soft: #e5edfa;
  --led-on: #34c25f;
  --led-off: #d8463a;
  --led-warn: #e5a31b;
  --led-idle: #9aa6b1;
  --danger: #b8352b;
  --font: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --r: 5px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--ink); background: var(--paper); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .86em; }
code { background: var(--line-2); padding: 1px 5px; border-radius: 3px; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: .75rem; }
h3 { font-size: .95rem; font-weight: 600; margin: 1rem 0 .5rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .8em; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--steel); color: var(--steel-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; }
.brand strong { display: block; color: #fff; font-size: .95rem; line-height: 1.2; }
.brand small { display: block; color: var(--steel-ink); opacity: .75; font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.brand-mark { display: inline-flex; gap: 3px; padding: 6px; background: #121b24; border-radius: 4px; }
.brand-mark i { width: 7px; height: 7px; border-radius: 50%; background: var(--led-on); box-shadow: 0 0 6px var(--led-on); }
.brand-mark i:nth-child(2) { background: var(--led-warn); box-shadow: 0 0 6px var(--led-warn); }
.brand-mark i:nth-child(3) { background: #4a5a69; box-shadow: none; }
.brand-mark.big { padding: 9px; gap: 5px; margin-bottom: 14px; }
.brand-mark.big i { width: 10px; height: 10px; }
nav a { display: block; padding: 8px 12px; color: var(--steel-ink); border-radius: 4px; font-weight: 500; font-size: .93rem; }
nav a:hover { background: var(--steel-2); color: #fff; text-decoration: none; }
nav a.on { background: var(--steel-2); color: #fff; box-shadow: inset 3px 0 0 var(--led-on); }
.nav-sep { height: 1px; background: var(--steel-2); margin: 12px 8px; }
.nav-user { margin-top: 18px; padding: 12px; border-top: 1px solid var(--steel-2); font-size: .85rem; display: flex; justify-content: space-between; gap: 8px; }
.nav-user a { display: inline; padding: 0; color: #fff; }
.nav-toggle { display: none; }
.main { padding: 26px 32px 60px; min-width: 0; max-width: 1400px; }

/* ---------- page head ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { margin: 4px 0 0; color: var(--ink-2); max-width: 72ch; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); border-radius: var(--r); font: 500 .9rem var(--font); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #b8c3cc; text-decoration: none; background: #f8fafb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #174ea3; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; padding: 10px; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.linkbtn:hover { text-decoration: underline; }
.linkbtn.danger { color: var(--danger); }
.link-quiet { color: var(--muted); }
form.inline { display: inline; }
label { display: block; font-weight: 500; font-size: .88rem; color: var(--ink-2); margin-bottom: 12px; }
label small { display: block; font-weight: 400; color: var(--muted); margin-top: 3px; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r);
  font: 400 .93rem var(--font); color: var(--ink); background: #fff; }
textarea.mono, input.mono { font-family: var(--mono); font-size: .85rem; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; color: var(--ink); }
label.check input { width: auto; margin: 0; }
.pad-top { padding-top: 26px; }
.input-group { display: flex; gap: 6px; align-items: stretch; margin-top: 4px; }
.input-group input { margin-top: 0; }
fieldset { border: 1px solid var(--line-2); border-radius: var(--r); padding: 12px 14px 2px; margin: 0 0 14px; }
legend { font-weight: 600; font-size: .85rem; padding: 0 6px; color: var(--ink); }
.row2, .row3 { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.row3 { grid-template-columns: 1fr 1fr 1fr; }
.align-end { align-items: end; }
.align-end .btn { margin-bottom: 12px; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.form-grid { display: grid; gap: 18px; max-width: 900px; }
.inline-label { display: flex; align-items: center; gap: 8px; margin: 0; }
.inline-label select { width: auto; margin: 0; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 18px 20px; margin-bottom: 18px; }
.panel.narrow { max-width: 820px; }
.panel > summary { cursor: pointer; font-weight: 600; }
.hint { color: var(--ink-2); font-size: .88rem; margin: 0 0 12px; }
.empty { color: var(--ink-2); padding: 6px 0; }
.empty-state { text-align: left; padding: 28px; }
.empty-state p { margin: 0; color: var(--ink-2); max-width: 64ch; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

.flash { padding: 10px 14px; border-radius: var(--r); margin-bottom: 14px; border: 1px solid; font-size: .92rem; }
.flash-ok { background: #ebf7ef; border-color: #b9e2c6; color: #1c5e33; }
.flash-error { background: #fbecea; border-color: #efc1bc; color: #8a271f; }
.flash-warn { background: #fdf5e4; border-color: #f0d9a3; color: #74520b; }
.errbox { background: #fbecea; border: 1px solid #efc1bc; border-left: 4px solid var(--led-off); border-radius: var(--r); padding: 12px 16px; margin-bottom: 16px; color: #6e1f18; }
.errbox p { margin: 6px 0 0; color: #6e3a35; }

/* ---------- LEDs ---------- */
.led { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: middle; background: var(--led-idle); flex: none; }
.led-on { background: var(--led-on); box-shadow: 0 0 0 2px rgba(52, 194, 95, .18); }
.led-off { background: var(--led-off); box-shadow: 0 0 0 2px rgba(216, 70, 58, .15); }
.led-warn { background: var(--led-warn); box-shadow: 0 0 0 2px rgba(229, 163, 27, .18); }
.led-label { margin-left: 6px; vertical-align: middle; }
.legend { display: flex; gap: 14px; font-size: .82rem; color: var(--steel-ink); }

/* ---------- port strip (dashboard) ---------- */
.strip-panel { background: var(--steel); color: #fff; border-radius: 8px; padding: 18px 20px 20px; margin-bottom: 18px;
  background-image: linear-gradient(#26364a 1px, transparent 1px); background-size: 100% 4px; }
.strip-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.strip-head h2 { font-size: 1.15rem; margin: 0 0 14px; }
.strip-panel .empty, .strip-panel .empty a { color: var(--steel-ink); }
.strip-panel .empty a { text-decoration: underline; }
.strip { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.port { display: flex; flex-direction: column; align-items: center; gap: 7px; padding: 10px 6px 8px; background: #121b24; border: 1px solid #33465a;
  border-radius: 4px; color: var(--steel-ink); text-decoration: none; position: relative; }
.port::before { content: ""; width: 34px; height: 22px; border: 2px solid #3c5064; border-top-width: 5px; border-radius: 2px; background: #0b1218; }
.port:hover { border-color: #6d8399; text-decoration: none; color: #fff; }
.port-led { position: absolute; top: 9px; right: 9px; width: 7px; height: 7px; border-radius: 50%; background: #3a4855; }
.port-online .port-led { background: var(--led-on); box-shadow: 0 0 7px var(--led-on); }
.port-offline .port-led { background: var(--led-off); box-shadow: 0 0 5px rgba(216,70,58,.6); }
.port-disabled { opacity: .5; }
.port-name { font-size: .74rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (prefers-reduced-motion: no-preference) {
  .port-online .port-led { animation: blink 3.2s steps(1) infinite; }
  .strip li:nth-child(3n) .port-online .port-led { animation-delay: -1.1s; }
  .strip li:nth-child(4n+1) .port-online .port-led { animation-delay: -2.3s; }
  @keyframes blink { 0%, 92% { opacity: 1; } 94% { opacity: .35; } 96% { opacity: 1; } 98% { opacity: .4; } }
}

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; margin-bottom: 18px; }
.stat { background: var(--surface); padding: 14px 18px; display: flex; flex-direction: column; gap: 2px; font-size: .84rem; color: var(--ink-2); }
.stat-n { font-size: 1.5rem; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-top: 1px solid var(--line-2); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }
.list li:first-child { border-top: 0; }
.list small { color: var(--muted); flex-basis: 100%; padding-left: 17px; }

/* ---------- tabs & toolbars ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--ink-2); font-weight: 500; font-size: .92rem; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); }
.tabs.small a { padding: 6px 12px; font-size: .85rem; }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 9px; background: var(--line-2); color: var(--ink-2); font-size: .74rem; text-align: center; font-variant-numeric: tabular-nums; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 300px; margin: 0; }
.toolbar.tight { margin-bottom: 8px; }
.spacer { flex: 1; }
.sel-info { font-size: .82rem; color: var(--muted); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; background: var(--line-2); font-size: .78rem; color: var(--ink-2); margin-right: 4px; }
.chip-btn { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 3px 10px; font: .8rem var(--font); cursor: pointer; color: var(--ink-2); }
.chip-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; margin-bottom: 14px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: .8rem; padding: 9px 12px; border-bottom: 1px solid var(--line); background: #f7f9fa; white-space: nowrap; }
.tbl td { padding: 8px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: #f8fafc; }
.tbl tr.is-disabled td { color: var(--muted); }
.tbl.compact td, .tbl.compact th { padding: 6px 10px; }
.tbl.ros td { font-family: var(--mono); font-size: .8rem; white-space: nowrap; }
.tbl input[type=checkbox] { width: auto; margin: 0; }
.panel .tbl { border: 1px solid var(--line-2); }
.row-actions { white-space: nowrap; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
td.row-actions { display: table-cell; }
td.row-actions > * { margin-right: 10px; }
code.kv { display: block; white-space: pre; background: none; padding: 4px 0; }
details summary { cursor: pointer; }

/* ---------- device view ---------- */
.facts { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; margin-bottom: 18px; }
.facts > div { background: var(--surface); padding: 10px 14px; }
.facts span { display: block; font-size: .78rem; color: var(--muted); }
.facts strong { font-weight: 600; font-size: .92rem; }
.cfg { display: grid; grid-template-columns: 200px 1fr; gap: 18px; align-items: start; }
.cfg-nav { position: sticky; top: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 10px; max-height: calc(100vh - 32px); overflow-y: auto; }
.cfg-nav strong { display: block; font-size: .8rem; color: var(--ink); margin: 10px 6px 4px; }
.cfg-nav strong:first-child { margin-top: 2px; }
.cfg-nav a { display: flex; justify-content: space-between; padding: 3px 6px; font-size: .84rem; color: var(--ink-2); border-radius: 3px; }
.cfg-nav a:hover { background: var(--accent-soft); text-decoration: none; color: var(--ink); }
.cfg-body { min-width: 0; }
.cfg-sec { scroll-margin-top: 16px; }
.cfg-sec h3 { margin-top: 4px; }
.kvlist { display: grid; grid-template-columns: max-content 1fr; gap: 4px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 12px 16px; margin: 0 0 14px; font-size: .85rem; }
.kvlist dt { color: var(--muted); }
.kvlist dd { margin: 0; font-family: var(--mono); font-size: .82rem; word-break: break-all; }

pre.console, .code-block pre { background: #151f29; color: #d6e1ea; font: .82rem/1.55 var(--mono); padding: 14px 16px; border-radius: 6px; overflow-x: auto; margin: 0 0 14px; white-space: pre; }
pre.console.small { font-size: .76rem; max-height: 140px; overflow: hidden; margin: 8px 0; }
.code-block { position: relative; }
.code-block .copy { position: absolute; top: 8px; right: 8px; background: #2a3a4a; color: #fff; border-color: #3d5064; }
.code-block pre { padding-right: 90px; white-space: pre-wrap; word-break: break-all; }
pre.diff { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 12px 14px; font: .8rem/1.6 var(--mono); overflow-x: auto; white-space: pre; }
pre.diff del { color: #96281f; background: #fcebe9; text-decoration: none; display: inline-block; min-width: 100%; }
pre.diff ins { color: #1a6034; background: #e8f6ec; text-decoration: none; display: inline-block; min-width: 100%; }
.result { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 10px 14px; margin-bottom: 8px; }
.result summary { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.result pre { margin-top: 10px; }

/* ---------- push & templates ---------- */
.push-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; align-items: start; }
.tpl-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.tpl { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 16px 18px; display: flex; flex-direction: column; }
.tpl header { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.tpl h2 { margin: 0; }
.tpl p { margin: 6px 0 0; color: var(--ink-2); font-size: .9rem; }
.tpl footer { margin-top: auto; padding-top: 8px; }

/* ---------- auth ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; background: var(--steel); }
.auth-card { background: var(--surface); width: 100%; max-width: 380px; padding: 28px; border-radius: 9px; }
.auth-card h1 { font-size: 1.3rem; }
.auth-card .sub { color: var(--ink-2); margin: 4px 0 18px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .facts { grid-template-columns: repeat(3, 1fr); }
  .push-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 12px 16px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; }
  .brand { padding: 0; }
  .nav-toggle { display: inline-block; background: var(--steel-2); color: #fff; border: 0; border-radius: 4px; padding: 7px 12px; font: 500 .9rem var(--font); }
  .side nav { display: none; flex-basis: 100%; padding-top: 10px; }
  .side nav.open { display: block; }
  .main { padding: 18px 16px 40px; }
  .row2, .row3, .cols, .stats { grid-template-columns: 1fr; }
  .cfg { grid-template-columns: 1fr; }
  .cfg-nav { position: static; max-height: 220px; }
  .facts { grid-template-columns: repeat(2, 1fr); }
  .toolbar input[type=search] { max-width: none; }
}
[hidden] { display: none !important; }
.tbl td strong, .tbl td.mono, .tbl td:nth-child(-n+4) { white-space: nowrap; }
td.row-actions .linkbtn { margin-right: 10px; }
td.row-actions form.inline:empty { display: none; }
.shell { background: linear-gradient(90deg, var(--steel) 236px, var(--paper) 236px); }
.facts strong { white-space: nowrap; }
@media (max-width: 860px) { .shell { background: var(--paper); } }

/* ---------- installer ---------- */
.installer { display: grid; grid-template-columns: 240px 1fr; width: 100%; max-width: 920px; background: var(--surface); border-radius: 10px; overflow: hidden; }
.inst-side { background: #18232e; color: var(--steel-ink); padding: 28px 24px; }
.inst-side h1 { color: #fff; font-size: 1.35rem; }
.inst-lead { margin: 2px 0 24px; font-size: .88rem; opacity: .8; }
.inst-steps { list-style: none; margin: 0; padding: 0; counter-reset: s; }
.inst-steps li { counter-increment: s; display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: .92rem; }
.inst-steps li::before { content: counter(s); width: 24px; height: 24px; flex: none; display: grid; place-items: center; border-radius: 50%; border: 1px solid #3b4d5f; font-size: .78rem; font-variant-numeric: tabular-nums; }
.inst-steps li.cur { color: #fff; font-weight: 600; }
.inst-steps li.cur::before { border-color: var(--led-on); color: var(--led-on); }
.inst-steps li.ok::before { content: "✓"; background: var(--led-on); border-color: var(--led-on); color: #0e1a12; }
.inst-steps a { color: var(--steel-ink); }
.inst-main { padding: 30px 34px; min-width: 0; }
.inst-title { font-size: 1.3rem; margin-bottom: 14px; }
.inst-main h3 { margin-top: 18px; }
.checks { list-style: none; padding: 0; margin: 0 0 18px; }
.checks li { padding: 8px 0; border-top: 1px solid var(--line-2); display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.checks li:first-child { border-top: 0; }
.checks small { flex-basis: 100%; padding-left: 19px; color: var(--ink-2); }
.inst-summary { list-style: none; padding: 0; margin: 0 0 16px; border: 1px solid var(--line); border-radius: 7px; }
.inst-summary li { display: grid; grid-template-columns: 110px 1fr; padding: 9px 14px; border-top: 1px solid var(--line-2); font-size: .92rem; }
.inst-summary li:first-child { border-top: 0; }
.inst-summary span { color: var(--muted); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
@media (max-width: 760px) {
  .installer { grid-template-columns: 1fr; }
  .inst-steps { display: flex; flex-wrap: wrap; gap: 4px 14px; }
  .inst-steps li span, .inst-steps li a { display: none; }
  .inst-steps li.cur span { display: inline; }
  .inst-main { padding: 22px 18px; }
}
.inst-main .code-block pre { padding-right: 16px; word-break: normal; overflow-wrap: anywhere; }
