/* fiscalnpd admin. Light and dark themes via CSS variables; no inline styles (CSP). */

:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #17191c;
  --muted: #5f6670;
  --border: #dde1e6;
  --accent: #2357d6;
  --accent-text: #ffffff;
  --ok: #157f3c;
  --ok-bg: #e5f5ea;
  --warn: #9a6200;
  --warn-bg: #fff3d6;
  --danger: #b42318;
  --danger-bg: #fde8e6;
  --info: #2357d6;
  --info-bg: #e7eefc;
  --neutral-bg: #eceff3;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111317;
    --surface: #1a1d22;
    --surface-2: #22262c;
    --text: #e8eaed;
    --muted: #9aa1ab;
    --border: #2e333a;
    --accent: #6f9bff;
    --accent-text: #0b1220;
    --ok: #5fd28a;
    --ok-bg: #16301f;
    --warn: #f0b84d;
    --warn-bg: #33270f;
    --danger: #ff8a7f;
    --danger-bg: #3a1a17;
    --info: #8fb0ff;
    --info-bg: #1b2640;
    --neutral-bg: #2a2f36;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111317;
  --surface: #1a1d22;
  --surface-2: #22262c;
  --text: #e8eaed;
  --muted: #9aa1ab;
  --border: #2e333a;
  --accent: #6f9bff;
  --accent-text: #0b1220;
  --ok: #5fd28a;
  --ok-bg: #16301f;
  --warn: #f0b84d;
  --warn-bg: #33270f;
  --danger: #ff8a7f;
  --danger-bg: #3a1a17;
  --info: #8fb0ff;
  --info-bg: #1b2640;
  --neutral-bg: #2a2f36;
  --shadow: none;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

code, pre, .mono { font-family: var(--mono); font-size: 13px; }

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }

/* Header */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 52px;
  flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a {
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.counter {
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  padding: 0 7px;
  line-height: 18px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); display: inline-block; }
.userbox { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.userbox form { margin: 0; }

main { max-width: 1240px; margin: 0 auto; padding: 24px 16px 64px; }

/* Blocks */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}
.card > h2:first-child { margin-top: 0; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.stat-sub { color: var(--muted); font-size: 13px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Notices */
.flash, .notice {
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.flash-ok, .notice-ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.flash-error, .notice-error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.notice-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.notice-info { background: var(--info-bg); color: var(--info); border-color: var(--info); }
.notice a { color: inherit; text-decoration: underline; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; word-break: break-word; }

/* Badges */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--neutral-bg);
  color: var(--muted);
}
.s-registered, .s-fiscalized, .s-delivered, .s-connected, .s-active, .s-ok, .s-sent { background: var(--ok-bg); color: var(--ok); }
.s-pending, .s-sending, .s-received, .s-verified, .s-cancel_pending { background: var(--info-bg); color: var(--info); }
.s-unknown, .s-manual, .s-warn, .s-partially_refunded, .s-refunded { background: var(--warn-bg); color: var(--warn); }
.s-rejected, .s-failed, .s-disconnected, .s-error { background: var(--danger-bg); color: var(--danger); }
.s-test { background: var(--neutral-bg); color: var(--muted); border: 1px dashed var(--border); }

/* Forms */
form { margin: 0; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
input[type="text"], input[type="password"], input[type="search"], input[type="date"], input[type="tel"],
input[type="url"], select, textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
textarea { min-height: 70px; font-family: var(--mono); font-size: 13px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.checkbox { display: flex; gap: 8px; align-items: flex-start; color: var(--text); font-size: 14px; }
.checkbox input { margin-top: 3px; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; align-items: end; }
.filters .wide { grid-column: span 2; }
.filters-actions { display: flex; gap: 8px; }
.row select { width: auto; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline-form input[type="text"] { width: auto; min-width: 200px; }

button, .button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .button:hover { background: var(--surface-2); text-decoration: none; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.primary:hover { background: var(--accent); filter: brightness(1.08); }
.danger { color: var(--danger); border-color: var(--danger); }
.danger:hover { background: var(--danger-bg); }
.link-button { border: 0; background: none; padding: 0; color: var(--accent); }
.link-button:hover { background: none; text-decoration: underline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; }
details.action { display: inline-block; }
details.action > summary { list-style: none; cursor: pointer; }
details.action > summary::-webkit-details-marker { display: none; }
details.action[open] > summary { margin-bottom: 8px; }
details.action .card { margin: 0; padding: 12px; min-width: 280px; }

/* Secrets shown once */
.secret {
  font-family: var(--mono);
  font-size: 14px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 6px;
  word-break: break-all;
  user-select: all;
}

/* Limit meter */
meter.limit { width: 100%; height: 14px; }

pre.json {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  overflow: auto;
  max-height: 360px;
  margin: 0;
}
details.json > summary { cursor: pointer; color: var(--accent); margin: 6px 0; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--border); position: relative; }
.timeline li::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 14px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
}
.timeline .when { color: var(--muted); font-size: 13px; }

.pagination { display: flex; gap: 8px; align-items: center; margin-top: 14px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { text-align: center; }

.theme-toggle { padding: 5px 9px; }

@media (max-width: 760px) {
  .topbar-inner { gap: 8px 16px; padding-top: 8px; }
  .userbox { margin-left: auto; }
  .nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; }
  .nav a { white-space: nowrap; }
  .filters .wide { grid-column: auto; }
}

@media (max-width: 640px) {
  .stat-value { font-size: 20px; }
  .userbox .who { display: none; }
}
