*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --border:   #2a2d3e;
  --primary:  #6366f1;
  --primary2: #818cf8;
  --success:  #22c55e;
  --warning:  #f59e0b;
  --danger:   #ef4444;
  --text:     #e2e8f0;
  --muted:    #64748b;
  --sidebar:  180px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 10;
  overflow-y: auto;             /* scroll pokud nav links nestihnou na výšku */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--muted); }

.sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo span {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-logo small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}

.sidebar nav { padding: 8px 0; flex: 1; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;       /* zmenšeno z 10px → 7px aby se vešlo víc menu položek */
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
  border-left: 3px solid transparent;
}

.nav-link:hover { color: var(--text); background: rgba(255,255,255,.04); }
.nav-link.active { color: var(--primary2); border-left-color: var(--primary); background: rgba(99,102,241,.1); }
.nav-link .icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
}

/* ── Main ── */
.main {
  margin-left: var(--sidebar);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar h1 { font-size: 16px; font-weight: 600; }

.token-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.dot.green  { background: var(--success); box-shadow: 0 0 6px var(--success); }
.dot.red    { background: var(--danger);  box-shadow: 0 0 6px var(--danger); }
.dot.yellow { background: var(--warning); box-shadow: 0 0 6px var(--warning); }

.content { padding: 28px; flex: 1; }

/* ── Cards / Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.stat-card .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat-card .value.green  { color: var(--success); }
.stat-card .value.red    { color: var(--danger); }
.stat-card .value.yellow { color: var(--warning); }
.stat-card .value.blue   { color: var(--primary2); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 20px;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2 { font-size: 14px; font-weight: 600; }
.card-body { padding: 20px; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }

.mono { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green  { background: rgba(34,197,94,.15);  color: var(--success); }
.badge-red    { background: rgba(239,68,68,.15);   color: var(--danger); }
.badge-yellow { background: rgba(245,158,11,.15);  color: var(--warning); }
.badge-blue   { background: rgba(99,102,241,.15);  color: var(--primary2); }
.badge-gray   { background: rgba(100,116,139,.15); color: var(--muted); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
}

.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary2); }
.btn-success  { background: rgba(34,197,94,.15); color: var(--success); border: 1px solid rgba(34,197,94,.3); }
.btn-success:hover  { background: rgba(34,197,94,.25); }
.btn-danger   { background: rgba(239,68,68,.15); color: var(--danger); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover   { background: rgba(239,68,68,.25); }
.btn-ghost    { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover    { color: var(--text); border-color: var(--muted); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Forms ── */
.form-group { margin-bottom: 20px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.form-hint  { font-size: 11px; color: var(--muted); margin-top: 4px; }

input[type=text], input[type=password], select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  transition: border-color .15s;
  outline: none;
}

input[type=text]:focus, input[type=password]:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

select option { background: var(--surface); }

/* ── Toggle switch ── */
.toggle {
  position: relative;
  display: inline-block;
  width: 40px; height: 22px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 99px;
  cursor: pointer;
  transition: .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: var(--muted);
  border-radius: 50%;
  transition: .2s;
}
.toggle input:checked + .toggle-slider { background: rgba(99,102,241,.3); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); background: var(--primary); }

/* ── Rules list ── */
.rule-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.rule-row:last-child { border-bottom: none; }
.rule-info { flex: 1; }
.rule-name { font-weight: 600; font-size: 13px; }
.rule-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.rule-meta { font-size: 11px; color: var(--muted); }

/* ── Log filters ── */
.filters {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.filters input, .filters select { width: auto; }

/* ── Error text ── */
.error-text {
  color: var(--danger);
  font-size: 12px;
  font-family: 'SF Mono', monospace;
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px; right: 24px;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  z-index: 999;
  transform: translateY(80px);
  opacity: 0;
  transition: all .25s;
  pointer-events: none;
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.success { background: rgba(34,197,94,.9);  color: #fff; }
#toast.error   { background: rgba(239,68,68,.9);   color: #fff; }
#toast.info    { background: rgba(99,102,241,.9);  color: #fff; }

/* ── Output modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 600px;
  max-width: 95vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-body pre {
  background: var(--bg);
  border-radius: 8px;
  padding: 14px;
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  overflow-x: auto;
  white-space: pre-wrap;
  color: var(--text);
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-state .icon { font-size: 36px; margin-bottom: 12px; }

/* ── Hamburger (jen mobil) ── */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 38px; height: 38px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  flex: 0 0 auto;
}
.hamburger span {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--text);
  border-radius: 2px;
  transition: .2s;
}

/* backdrop za vysunutým menu */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 9;
}
.sidebar-backdrop.show { display: block; }

/* ── Mobilní layout ── */
@media (max-width: 768px) {
  body { display: block; }

  /* sidebar mimo obrazovku, vysune se přes .open */
  .sidebar {
    width: 260px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 2px 0 16px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }

  /* hlavní obsah na plnou šířku */
  .main { margin-left: 0; }

  /* hamburger viditelný v topbaru */
  .hamburger { display: flex; }

  /* zákaz scrollu pozadí, když je menu otevřené */
  body.sidebar-open { overflow: hidden; }

  /* kompaktnější odsazení */
  .topbar { padding: 10px 14px; gap: 10px; }
  .topbar h1 { font-size: 15px; flex: 1; }
  .content { padding: 16px 14px; }

  /* token-status menší a zalomitelný */
  .token-status { gap: 8px !important; font-size: 11px; flex-wrap: wrap; justify-content: flex-end; }

  /* karty a gridy */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
  .stat-card { padding: 14px; }
  .stat-card .value { font-size: 22px; }
  .card-body { padding: 14px; }
  .card-header { padding: 12px 14px; }

  /* tabulky: vodorovný scroll místo rozbití layoutu */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 560px; }

  /* modal přes celou šířku */
  .modal { width: 100%; max-width: 100%; max-height: 90vh; border-radius: 14px 14px 0 0; }
  .modal-overlay { align-items: flex-end; }

  /* rule-row zalomení */
  .rule-row { flex-wrap: wrap; gap: 10px; padding: 12px 14px; }

  /* toast přes šířku */
  #toast { left: 14px; right: 14px; bottom: 14px; text-align: center; }
}

/* ── Velmi malé telefony ── */
@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr; }
}
