:root {
  --bg:         #080808;
  --surface:    #101010;
  --surface2:   #181818;
  --surface3:   #202020;
  --border:     #282828;
  --red:        #c1272d;
  --red-bright: #e83e4a;
  --red-dim:    rgba(193,39,45,.15);
  --red-glow:   rgba(232,62,74,.08);
  --text:       #f0f0f0;
  --text-dim:   #888;
  --text-muted: #555;
  --radius:     10px;
  --sidebar-w:  248px;
  --green:      #22c55e;
  --yellow:     #eab308;
  --blue:       #3b82f6;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Login ────────────────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at center, #1a0505 0%, var(--bg) 70%);
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 360px;
  text-align: center;
}

.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  object-fit: cover;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.login-box h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.login-box p {
  color: var(--text-dim);
  font-size: .85rem;
  margin-bottom: 28px;
}

.login-error {
  color: var(--red-bright);
  font-size: .82rem;
  margin-top: 10px;
  min-height: 18px;
}

/* ── App layout ────────────────────────────────────────────────────────────── */
#app { display: none; height: 100vh; overflow: hidden; }
#app.visible { display: flex; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 20px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.brand-text { flex: 1; min-width: 0; }
.brand-name {
  font-weight: 700;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-sub { font-size: .72rem; color: var(--text-muted); }

nav { padding: 12px 10px; flex: 1; overflow-y: auto; }

.nav-section {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  padding: 12px 8px 6px;
}

nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: .875rem;
  transition: background .12s, color .12s;
  margin-bottom: 2px;
  cursor: pointer;
  user-select: none;
}

nav a:hover { background: var(--surface2); color: var(--text); }
nav a.active { background: var(--red-dim); color: var(--red-bright); font-weight: 600; }
nav a .nav-icon { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .82rem;
  color: var(--text-dim);
}

.sidebar-user img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color .12s, background .12s;
}
.icon-btn:hover { color: var(--text); background: var(--surface2); }

/* ── Main content ─────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  padding: 0 28px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--surface);
}

.topbar-title { font-size: 1rem; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.content {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
}

.page { display: none; }
.page.active { display: block; }

/* ── Cards stats ──────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.stat-icon {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--red-glow);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--red-bright);
  flex-shrink: 0;
}

.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .75rem; color: var(--text-dim); margin-top: 3px; }

/* ── Section header ───────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .4px;
}

/* ── Table ────────────────────────────────────────────────────────────────── */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

table { width: 100%; border-collapse: collapse; }

thead th {
  background: var(--surface2);
  padding: 10px 16px;
  text-align: left;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 11px 16px;
  border-top: 1px solid var(--border);
  font-size: .875rem;
  vertical-align: middle;
}

tbody tr:hover { background: var(--surface2); }

/* ── Badge ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
}
.badge-red    { background: var(--red-dim);              color: var(--red-bright); }
.badge-green  { background: rgba(34,197,94,.12);          color: var(--green); }
.badge-blue   { background: rgba(59,130,246,.12);         color: var(--blue); }
.badge-gray   { background: var(--surface3);              color: var(--text-dim); }
.badge-yellow { background: rgba(234,179,8,.12);          color: var(--yellow); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, background .15s;
  text-decoration: none;
}
.btn:hover { opacity: .85; }
.btn svg { width: 14px; height: 14px; }

.btn-red    { background: var(--red);     color: #fff; }
.btn-ghost  { background: transparent;    border: 1px solid var(--border); color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-sm     { padding: 5px 10px; font-size: .78rem; }
.btn-danger { background: rgba(239,68,68,.15); color: #ef4444; border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.25); opacity: 1; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
}

.form-card-title {
  font-size: .9rem;
  font-weight: 600;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid.cols-1 { grid-template-columns: 1fr; }
.form-full { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: .78rem; font-weight: 600; color: var(--text-dim); }
.form-group small { font-size: .73rem; color: var(--text-muted); }

input[type=text], input[type=password], input[type=number],
input[type=file], select, textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: .875rem;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--red); }
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--surface2); }

.input-group {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.input-group input { flex: 1; }

/* ── Logo preview ─────────────────────────────────────────────────────────── */
.logo-preview-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
}
.logo-preview-row img {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
}
.logo-preview-info strong { display: block; font-size: .9rem; }
.logo-preview-info small  { color: var(--text-dim); font-size: .78rem; }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state svg { opacity: .3; margin-bottom: 10px; }
.empty-state p { font-size: .85rem; }

/* ── Link cell ────────────────────────────────────────────────────────────── */
.link-cell a {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--red-bright);
  text-decoration: none;
  font-size: .82rem;
}
.link-cell a:hover { text-decoration: underline; }
.link-cell a svg { width: 12px; height: 12px; }

/* ── Status dot ───────────────────────────────────────────────────────────── */
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
}
.status-dot.online  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.offline { background: #ef4444; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--red-bright);
  padding: 12px 18px;
  border-radius: 8px;
  font-size: .85rem;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 200;
  max-width: 320px;
}
#toast.show  { opacity: 1; transform: translateY(0); }
#toast.green { border-left-color: var(--green); }
#toast.error { border-left-color: #ef4444; }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Profile avatar ───────────────────────────────────────────────────────── */
.profile-hero {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  object-fit: cover;
  border: 2px solid var(--red);
}
.profile-info h2 { font-size: 1.1rem; font-weight: 700; }
.profile-info p  { color: var(--text-dim); font-size: .83rem; margin-top: 3px; }

/* ── Log viewer ───────────────────────────────────────────────────────────── */
.log-box {
  background: #050505;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-family: 'Consolas', 'Fira Code', monospace;
  font-size: .78rem;
  color: #aaa;
  max-height: 380px;
  overflow-y: auto;
  line-height: 1.6;
}
.log-box .log-error { color: #ef4444; }
.log-box .log-warn  { color: var(--yellow); }
.log-box .log-info  { color: #60a5fa; }
