*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── CSS custom properties (light defaults) ── */
:root {
  --bg:          #f0f2f5;
  --surface:     #ffffff;
  --border:      #e5e7eb;
  --border-light:#f3f4f6;
  --text:        #1a1a2e;
  --text-muted:  #6b7280;
  --text-faint:  #9ca3af;
  --accent:      #6366f1;
  --accent-dark: #4f46e5;
  --accent-bg:   #e0e7ff;
  --accent-text: #4338ca;
  --shadow:      rgba(0,0,0,.08);
  --log-bg:      #1a1a2e;
  --log-text:    #d1d5db;
  --flash-bg:    #fef3cd;
  --flash-border:#fbbf24;
}

[data-theme="dark"] {
  --bg:          #0f1117;
  --surface:     #1c1f2b;
  --border:      #2d3148;
  --border-light:#252839;
  --text:        #e2e4f0;
  --text-muted:  #9ca3af;
  --text-faint:  #6b7280;
  --accent:      #818cf8;
  --accent-dark: #6366f1;
  --accent-bg:   #1e2047;
  --accent-text: #a5b4fc;
  --shadow:      rgba(0,0,0,.3);
  --log-bg:      #0a0c14;
  --log-text:    #c9cdd9;
  --flash-bg:    #3b2f00;
  --flash-border:#92631f;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .2s, color .2s;
}

.container { max-width: 960px; margin: 0 auto; padding: 2rem 1rem; }
.container.narrow { max-width: 420px; padding-top: 5rem; }
.container.narrow h1 { text-align: center; margin-bottom: 1.5rem; font-size: 1.5rem; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
header h1 { font-size: 1.5rem; }
.header-actions { display: flex; align-items: center; gap: 1rem; }
.refresh-note { font-size: .8rem; color: var(--text-faint); }
.logout { color: var(--accent); text-decoration: none; font-size: .9rem; }
.logout:hover { text-decoration: underline; }

.btn-dark-toggle {
  background: var(--border);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .25rem .6rem;
  font-size: 1rem;
  cursor: pointer;
  line-height: 1.4;
  transition: background .15s;
}
.btn-dark-toggle:hover { background: var(--border-light); color: var(--text); }

.flash {
  background: var(--flash-bg);
  border: 1px solid var(--flash-border);
  border-radius: 6px;
  padding: .75rem 1rem;
  margin-bottom: 1rem;
  font-size: .9rem;
}

/* ── Jail tabs ── */
.jail-tabs {
  display: flex;
  gap: .5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.jail-tab {
  padding: .35rem .85rem;
  border-radius: 6px;
  font-size: .85rem;
  font-weight: 500;
  text-decoration: none;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: background .15s;
}
.jail-tab:hover { background: var(--accent-bg); color: var(--accent-text); }
.jail-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.card {
  background: var(--surface);
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: 0 2px 8px var(--shadow);
  margin-bottom: 1.5rem;
}
.card h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* Stats */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border-radius: 10px;
  padding: 1.25rem 1rem;
  box-shadow: 0 2px 8px var(--shadow);
  text-align: center;
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-label { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }

/* Badges */
.jail-badge {
  background: var(--accent-bg);
  color: var(--accent-text);
  font-size: .75rem;
  padding: .15rem .5rem;
  border-radius: 4px;
  font-weight: 500;
}
.log-note { font-size: .75rem; color: var(--text-faint); font-weight: 400; }

/* CSV export button */
.btn-export {
  margin-left: auto;
  font-size: .78rem;
  font-weight: 500;
  padding: .2rem .65rem;
  border-radius: 4px;
  text-decoration: none;
  background: var(--border-light);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
  transition: background .15s;
}
.btn-export:hover { background: var(--accent-bg); color: var(--accent-text); }

/* Table */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .8rem; color: var(--text-muted); padding: .5rem .75rem; border-bottom: 1px solid var(--border); }
td { padding: .6rem .75rem; border-bottom: 1px solid var(--border-light); font-size: .9rem; color: var(--text); }
tr:last-child td { border-bottom: none; }

.mono { font-family: monospace; }
.isp { font-size: .8rem; color: var(--text-muted); max-width: 220px; }
.expires { font-size: .85rem; color: #d97706; font-weight: 500; white-space: nowrap; }
[data-theme="dark"] .expires { color: #fbbf24; }
.expiring { color: var(--text-faint); font-style: italic; }
.ban-count { white-space: nowrap; }
.repeat-badge { background: #fef2f2; color: #b91c1c; border: 1px solid #fca5a5; padding: .2rem .5rem; border-radius: 4px; font-size: .8rem; font-weight: 600; }
[data-theme="dark"] .repeat-badge { background: #3b0f0f; color: #fca5a5; border-color: #7f1d1d; }
.first-time { color: var(--text-faint); font-size: .8rem; }
.inline-form { display: inline; }

.btn-unban {
  background: #ef4444;
  color: white;
  border: none;
  padding: .3rem .75rem;
  border-radius: 4px;
  font-size: .8rem;
  cursor: pointer;
}
.btn-unban:hover { background: #b91c1c; }

/* Whitelist */
.protected-note {
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: .75rem;
}
.protected-note .lock { font-size: .75rem; }

.whitelist-table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.whitelist-table td { padding: .5rem .75rem; border-bottom: 1px solid var(--border-light); font-size: .9rem; color: var(--text); }
.whitelist-table tr:last-child td { border-bottom: none; }

.badge-protected {
  font-size: .75rem;
  color: var(--text-muted);
  background: var(--border-light);
  border: 1px solid var(--border);
  padding: .2rem .6rem;
  border-radius: 4px;
}

.btn-remove {
  background: var(--border-light);
  color: #b91c1c;
  border: 1px solid var(--border);
  padding: .25rem .65rem;
  border-radius: 4px;
  font-size: .8rem;
  cursor: pointer;
}
.btn-remove:hover { background: #fee2e2; border-color: #fca5a5; }
[data-theme="dark"] .btn-remove:hover { background: #3b0f0f; border-color: #7f1d1d; }

.whitelist-add { border-top: 1px solid var(--border-light); padding-top: 1rem; }
.add-form { display: flex; gap: .5rem; }
.add-form input[type="text"] {
  flex: 1;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  font-family: monospace;
  background: var(--bg);
  color: var(--text);
}
.add-form input[type="text"]:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
.add-form button {
  background: var(--accent);
  color: white;
  border: none;
  padding: .5rem 1rem;
  border-radius: 6px;
  font-size: .9rem;
  cursor: pointer;
  white-space: nowrap;
}
.add-form button:hover { background: var(--accent-dark); }

.empty { color: var(--text-faint); font-size: .9rem; }

/* Jail Settings */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  margin-bottom: 1rem;
}
.setting-item label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .4rem;
}
.setting-input-row {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.setting-input-row input[type="number"] {
  width: 90px;
  padding: .45rem .6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .95rem;
  font-family: monospace;
  background: var(--bg);
  color: var(--text);
}
.setting-input-row input[type="number"]:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.setting-unit { font-size: .8rem; color: var(--text-muted); white-space: nowrap; }
.setting-hint { font-size: .75rem; color: var(--text-faint); margin-top: .3rem; }
.btn-save {
  background: var(--accent);
  color: white;
  border: none;
  padding: .5rem 1.25rem;
  border-radius: 6px;
  font-size: .9rem;
  cursor: pointer;
}
.btn-save:hover { background: var(--accent-dark); }

/* Manual ban */
.btn-ban {
  background: #dc2626;
  color: white;
  border: none;
  padding: .5rem 1rem;
  border-radius: 6px;
  font-size: .9rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn-ban:hover { background: #b91c1c; }

/* Log */
.log-search-row {
  margin-bottom: .75rem;
}
.log-search-row input[type="text"] {
  width: 100%;
  padding: .45rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .85rem;
  font-family: monospace;
  background: var(--bg);
  color: var(--text);
}
.log-search-row input[type="text"]:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

.log-box {
  background: var(--log-bg);
  border-radius: 6px;
  padding: 1rem;
  max-height: 400px;
  overflow-y: auto;
  font-family: monospace;
  font-size: .78rem;
}
.log-line { padding: .15rem 0; color: var(--log-text); word-break: break-all; }
.log-ban { color: #fca5a5; }
.log-unban { color: #86efac; }
.log-warn { color: #fde68a; }

/* Login form */
label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .4rem; }
input[type="password"] {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  margin-bottom: 1rem;
  outline: none;
  background: var(--bg);
  color: var(--text);
}
input[type="password"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
button[type="submit"] {
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  padding: .65rem;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
}
button[type="submit"]:hover { background: var(--accent-dark); }

@media (max-width: 600px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
}
