/* SwiNOG Admin – modern minimal UI */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

/* App layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: #1f2937;
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  padding: 20px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #374151;
}
.brand-logo {
  width: 28px; height: 28px;
  background: #fff;
  border-radius: 6px;
  padding: 3px;
  object-fit: contain;
  flex-shrink: 0;
}
.brand { min-width: 0; }
.brand-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text { font-weight: 600; font-size: 15px; }
/* `min-height: 0` is mandatory for an `overflow-y: auto` to actually
   kick in inside a flex column — without it the child wants to expand
   to its content height and the sidebar's vertical clipping wins. */
.nav {
  display: flex;
  flex-direction: column;
  padding: 12px 8px 16px;
  gap: 2px;
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  position: relative;
}
/* Thin, dark-themed scrollbar so the rail isn't visually noisy. */
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-thumb { background: #4b5563; border-radius: 3px; }
.nav::-webkit-scrollbar-thumb:hover { background: #6b7280; }
.nav { scrollbar-width: thin; scrollbar-color: #4b5563 transparent; }
.nav-link {
  display: block;
  padding: 9px 12px;
  color: #d1d5db;
  border-radius: 6px;
  font-weight: 500;
  font-size: 13.5px;
}
.nav-link:hover { background: #374151; color: #ffffff; text-decoration: none; }
.nav-link.is-active { background: var(--primary); color: #ffffff; }
.nav-sub { display: flex; flex-direction: column; padding: 2px 0 6px 16px; gap: 1px; }
.nav-sub-link {
  font-size: 12.5px;
  color: #9ca3af;
  padding: 5px 10px;
  border-radius: 5px;
  text-decoration: none;
  border-left: 2px solid #374151;
}
.nav-sub-link:hover { color: #ffffff; background: #374151; text-decoration: none; }
.nav-sub-link.is-active { color: #ffffff; border-left-color: var(--primary); background: rgba(79,70,229,0.15); }
.nav-sub-link.is-past { color: #6b7280; }
.nav-sub-link.is-past:hover { color: #d1d5db; }
.nav-sub-sep { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: #6b7280; padding: 8px 10px 2px; }
.nav-section-title {
  display: block;
  padding: 9px 12px;
  color: #d1d5db;
  border-radius: 6px;
  font-weight: 500;
  font-size: 13.5px;
  margin-top: 6px;
}
/* Version pill — lives outside .nav so it stays visible when the
   nav itself scrolls. Renders just above the user / logout footer. */
.nav-version {
  padding: 10px 18px 4px;
  flex-shrink: 0;
}

/* Bottom group (Settings / Users / API tokens / History) — sits above the
   version pill with a small gap and a divider line above it. */
.nav-bottom {
  margin-top: auto;       /* push down to the bottom of the flex column */
  padding-bottom: 14px;   /* breathing room above the version pill */
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-divider {
  border-top: 1px solid #374151;
  margin: 12px 4px 10px;
}

/* Collapsible nav group (Settings). Uses native <details>/<summary>
   so we get keyboard accessibility for free; only the chevron rotation
   and the default disclosure-triangle hiding are handled in CSS.

   Hiding the native marker takes three rules because no single
   property covers every engine:
     - `list-style: none`             -> Firefox + standards path
     - `::-webkit-details-marker`     -> older Safari / Chrome
     - `::marker { content: '' }`     -> Firefox 78+ when summary keeps
                                          its default `display: list-item`
   We also force `display: flex` on the summary itself; Webkit drops the
   triangle entirely as soon as the summary is no longer a list-item. */
.nav-group-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  color: #d1d5db;
  border-radius: 6px;
  font-weight: 500;
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.nav-group-summary::-webkit-details-marker,
.nav-group-summary::marker {
  display: none;
  content: '';
}
.nav-group-summary:hover { background: #374151; color: #ffffff; }
.nav-group-summary.is-active { background: var(--primary); color: #ffffff; }
.nav-group-chevron {
  font-size: 11px;
  color: #9ca3af;
  transition: transform 120ms ease;
}
.nav-group[open] > .nav-group-summary .nav-group-chevron {
  transform: rotate(180deg);
}
.nav-group-summary.is-active .nav-group-chevron { color: #ffffff; }

/* Tab navigation used by the Bexio plugin pages. Generic enough for
   any plugin that wants tabs at the top of its admin views. */
.bx-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  border-bottom: 2px solid #e5e7eb;
  margin: -8px -2px 18px;
  padding: 0;
}
.bx-tab {
  padding: 10px 18px;
  color: #6b7280;
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  border: 1px solid transparent;
  border-bottom: none;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
  margin-bottom: -2px;            /* pull the active border down over the .bx-tabs border */
  background: transparent;
}
.bx-tab:hover {
  color: #111827;
  background: #f3f4f6;
  text-decoration: none;
}
.bx-tab.is-active {
  color: var(--primary);
  background: #ffffff;
  border-color: #e5e7eb;
  border-bottom: 2px solid #ffffff;
}
.nav-version .version-tag {
  display: inline-block;
  padding: 2px 8px;
  background: #374151;
  color: #d1d5db;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-decoration: none;
}
.nav-version .version-tag:hover { background: var(--primary); color: #ffffff; text-decoration: none; }

.sidebar-foot { padding: 14px 18px; border-top: 1px solid #374151; font-size: 13px; }
.sidebar-foot .user { color: #ffffff; margin-bottom: 4px; font-weight: 500; }
.sidebar-foot .logout { color: #9ca3af; font-size: 12.5px; }

/* Main */
.main { flex: 1; min-width: 0; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 28px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; }
.content { padding: 24px 28px; max-width: 1400px; }

/* Flashes */
.flashes { padding: 0 28px; }
.flash {
  margin: 16px 0 0 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid;
  font-weight: 500;
}
.flash-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash-error   { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flash-info    { background: var(--primary-soft); border-color: #c7d2fe; color: var(--primary-hover); }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.card-body { padding: 16px 18px; }
.card-body.compact { padding: 0; }

/* Stats grid */
.stats-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 24px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat .label { color: var(--text-muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 6px; color: var(--text); }
.stat .sub   { color: var(--text-muted); margin-top: 4px; font-size: 12.5px; }

/* Stat card that's also a link — gets a subtle hover lift + cursor.
   The <a> takes the place of the wrapping <div class="stat"> so the
   whole tile is clickable, including the value and sub labels. */
a.stat {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: transform 80ms ease, box-shadow 80ms ease, border-color 80ms ease;
}
a.stat:hover {
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md, 0 4px 10px rgba(0, 0, 0, 0.08));
  border-color: var(--primary);
}

/* Tables */
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data thead th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
table.data tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data tbody tr:hover { background: #fafbfd; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.data .actions { text-align: right; }

/* Forms */
form .field { margin-bottom: 16px; }
form label  { display: block; font-weight: 500; margin-bottom: 6px; font-size: 13px; color: var(--text); }
form input[type=text],
form input[type=email],
form input[type=password],
form input[type=number],
form input[type=date],
form input[type=datetime-local],
form select,
form textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
form input:focus, form select:focus, form textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
}
form textarea { min-height: 100px; resize: vertical; }
form .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
form .grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 700px) {
  form .grid-2, form .grid-3 { grid-template-columns: 1fr; }
}
form .help { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }
form .errors { color: var(--danger); font-size: 13px; margin-top: 6px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--primary);
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}
.btn:hover { background: var(--primary-hover); color: #fff; text-decoration: none; }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }

/* Toolbar */
.toolbar { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.toolbar .search { flex: 1; max-width: 320px; }
.toolbar .search input { width: 100%; }

/* Pills */
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #e5e7eb;
  color: #374151;
}
.pill-success { background: #d1fae5; color: #065f46; }
.pill-warning { background: #fef3c7; color: #92400e; }
.pill-danger  { background: #fee2e2; color: #991b1b; }
.pill-info    { background: var(--primary-soft); color: var(--primary-hover); }

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
}
.login-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.12);
}
.login-card h1 { margin: 0 0 4px 0; font-size: 22px; }
.login-card .sub { color: var(--text-muted); margin: 0 0 24px 0; font-size: 14px; }
.login-card .btn { width: 100%; justify-content: center; padding: 11px; font-size: 15px; }

/* Misc */
.muted { color: var(--text-muted); }
.text-right { text-align: right; }
.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

/* Markdown-rendered docs (the in-admin API reference at /api-docs
   uses this). Designed as a single comfortable reading column,
   GitHub-ish typography with a slightly tighter scale. */
.markdown-body {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  max-width: 880px;        /* comfortable measure (~75 chars) */
  margin: 0;               /* anchor to the left edge of the card */
}
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child  { margin-bottom: 0; }

/* Heading scale */
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  margin: 36px 0 14px;
  line-height: 1.25;
  color: var(--text);
  font-weight: 600;
}
.markdown-body h1 {
  font-size: 30px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 10px;
  margin-top: 0;
}
.markdown-body h2 {
  font-size: 22px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}
.markdown-body h3 { font-size: 18px; }
.markdown-body h4 {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* Paragraphs and lists */
.markdown-body p { margin: 12px 0; }
.markdown-body ul, .markdown-body ol { margin: 12px 0; padding-left: 26px; }
.markdown-body li { margin: 4px 0; }
.markdown-body li > ul, .markdown-body li > ol { margin: 4px 0; }

/* Inline code */
.markdown-body :not(pre) > code {
  background: rgba(99, 102, 241, 0.10);
  color: #4338ca;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.88em;
  white-space: nowrap;
}

/* Fenced code blocks */
.markdown-body pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px 18px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.55;
  margin: 16px 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}
.markdown-body pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
  white-space: pre;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* Tables — wrap in a scroll container if too wide */
.markdown-body table {
  border-collapse: collapse;
  margin: 16px 0;
  display: block;
  overflow-x: auto;
  font-size: 14px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.markdown-body thead { background: rgba(0, 0, 0, 0.025); }
.markdown-body th, .markdown-body td {
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.markdown-body th {
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  white-space: nowrap;
}
.markdown-body tr:last-child td { border-bottom: 0; }
.markdown-body tbody tr:hover { background: rgba(99, 102, 241, 0.04); }

/* Callouts */
.markdown-body blockquote {
  margin: 16px 0;
  padding: 10px 18px;
  border-left: 4px solid var(--primary);
  background: rgba(79, 70, 229, 0.06);
  color: var(--text);
  border-radius: 0 6px 6px 0;
}
.markdown-body blockquote p:first-child { margin-top: 0; }
.markdown-body blockquote p:last-child  { margin-bottom: 0; }

/* Misc */
.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}
.markdown-body a { color: var(--primary); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body strong { font-weight: 600; }

/* Make the wrapping card less constrained so the column-max can do
   the layout work — otherwise the docs feel cramped. */
.card-body.markdown-body { padding: 28px 32px; }
@media (max-width: 700px) {
  .card-body.markdown-body { padding: 18px; font-size: 14px; }
  .markdown-body h1 { font-size: 24px; }
  .markdown-body h2 { font-size: 19px; }
}
