:root {
  --bg:         #0f0f0f;
  --bg2:        #161616;
  --bg3:        #1e1e1e;
  --bg4:        #252525;
  --border:     #2a2a2a;
  --border2:    #333;
  --text:       #e8e8e8;
  --text2:      #999;
  --text3:      #666;
  --accent:     #4f8ef7;
  --accent-dim: #1a2d50;
  --red:        #ff4d4d;
  --red-dim:    #2a1010;
  --green:      #3ddc84;
  --radius:     10px;
  --radius-sm:  6px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Login ─────────────────────────────────────────────────────────────────── */

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-sub {
  font-size: 13px;
  color: var(--text3);
  margin-top: -8px;
}

.login-error {
  font-size: 12px;
  color: var(--red);
  min-height: 16px;
}

/* ── Topbar ─────────────────────────────────────────────────────────────────── */

.topbar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left { display: flex; align-items: center; gap: 10px; }

.logo { font-size: 15px; font-weight: 700; letter-spacing: -.02em; }
.logo span { color: var(--accent); }

.badge {
  background: var(--bg4);
  border: 1px solid var(--border2);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11px;
  color: var(--text3);
}

/* ── Main ───────────────────────────────────────────────────────────────────── */

.main {
  max-width: 780px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity .15s, background .15s;
}
.btn:hover  { opacity: .85; }
.btn:active { opacity: .7;  }
.btn:disabled { opacity: .35; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }

.btn-ghost {
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border2);
}
.btn-ghost:hover { background: var(--bg4); opacity: 1; }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Rule card ──────────────────────────────────────────────────────────────── */

.rule-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  transition: border-color .15s;
}
.rule-card:hover   { border-color: var(--border2); }
.rule-card.editing { border-color: var(--accent);  }

.rule-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
}

.rule-drag { color: var(--text3); font-size: 16px; cursor: grab; padding: 0 2px; }

.rule-name-display { flex: 1; font-weight: 500; font-size: 14px; }

.rule-summary { font-size: 12px; color: var(--text3); margin-top: 1px; }

.rule-perm-blocked {
  display: inline-block;
  background: var(--red-dim);
  color: var(--red);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 500;
}

.chevron { color: var(--text3); font-size: 11px; transition: transform .2s; }
.chevron.open { transform: rotate(180deg); }

/* ── Rule editor body ───────────────────────────────────────────────────────── */

.rule-body {
  border-top: 1px solid var(--border);
  padding: 16px;
  display: none;
}
.rule-body.open { display: block; }

.field { margin-bottom: 14px; }

.label {
  display: block;
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 5px;
  font-weight: 500;
}

.hint { font-size: 11px; color: var(--text3); margin-top: 4px; }

input[type=text],
input[type=password],
textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
input[type=text]:focus,
input[type=password]:focus,
textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }

/* ── Allow windows ──────────────────────────────────────────────────────────── */

.windows-list { display: flex; flex-direction: column; gap: 8px; }

.window-row {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.window-fields {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.window-remove {
  color: var(--text3);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
  margin-top: 2px;
  transition: color .15s;
}
.window-remove:hover { color: var(--red); }

.days-grid { display: flex; gap: 4px; flex-wrap: wrap; }

.day-btn {
  background: var(--bg4);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 3px 7px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text2);
  transition: all .12s;
  user-select: none;
}
.day-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Perm block toggle ──────────────────────────────────────────────────────── */

.perm-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; }

.toggle-track {
  width: 34px;
  height: 18px;
  background: var(--bg4);
  border: 1px solid var(--border2);
  border-radius: 9px;
  position: relative;
  transition: background .2s, border-color .2s;
  flex-shrink: 0;
}
.toggle-track.on { background: var(--red); border-color: var(--red); }

.toggle-thumb {
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform .2s;
}
.toggle-track.on .toggle-thumb { transform: translateX(16px); }

.perm-label { font-size: 13px; color: var(--text2); }

/* ── Empty state ────────────────────────────────────────────────────────────── */

.empty { text-align: center; padding: 48px 24px; color: var(--text3); }
.empty-icon { font-size: 32px; margin-bottom: 12px; }

/* ── Add rule ───────────────────────────────────────────────────────────────── */

.add-card {
  border: 1px dashed var(--border2);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  cursor: pointer;
  color: var(--text3);
  font-size: 13px;
  transition: all .15s;
}
.add-card:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* ── Toast ──────────────────────────────────────────────────────────────────── */

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all .25s;
  z-index: 100;
  white-space: nowrap;
}
#toast.show    { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.success { border-color: #1a4a2a; color: var(--green); }
#toast.error   { border-color: #4a1a1a; color: var(--red);   }

/* ── Save bar ───────────────────────────────────────────────────────────────── */

#save-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transform: translateY(100%);
  transition: transform .2s;
  z-index: 9;
}
#save-bar.dirty { transform: translateY(0); }
.save-bar-hint { font-size: 12px; color: var(--text3); }

/* ── Misc ───────────────────────────────────────────────────────────────────── */

.mono { font-family: monospace; }