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

/* ── Design tokens (light, neo-brutalist) ── */
:root {
  --bg: #fbf3e4;
  --ink: #141414;
  --surface: #ffffff;
  --surface2: #fffaf1;
  --surface3: #f5ead6;
  --border: #141414;
  --line: #e6dcc8;
  --card: #ffffff;

  --accent: #ff7a59;
  --accent-hover: #ff6640;
  --accent-glow: rgba(255,122,89,0.25);

  --green: #15803d;
  --green-dim: #d4f5df;
  --red: #dc2626;
  --red-dim: #fde3e1;
  --orange: #b45309;
  --blue: #1d4ed8;

  --mint: #c8f0d6;
  --butter: #fff0b3;
  --sky: #cfe4ff;
  --peach: #ffd8c6;

  --text: #141414;
  --text2: #3d3934;
  --text-secondary: #4f4a43;
  --muted: #6e685e;

  --radius: 14px;
  --sidebar-w: 240px;
  --bw: 2px;
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 2px 2px 0 var(--ink);
  --ease: 0.15s ease;
}

html { height: 100%; }
body {
  font-family: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Theme toggle removed — single light theme */
.theme-toggle { display: none !important; }

code {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 0.9em;
  background: var(--butter);
  border: 1px solid var(--ink);
  border-radius: 5px;
  padding: 0 5px;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: var(--bw) solid var(--ink);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 22px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: var(--bw) solid var(--ink);
}

.brand-icon {
  width: 40px; height: 40px;
  background: var(--accent);
  border: var(--bw) solid var(--ink);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  box-shadow: var(--shadow-sm);
}

.brand-text { font-size: 19px; font-weight: 800; letter-spacing: -0.2px; }

.sidebar-nav {
  flex: 1;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  border: var(--bw) solid transparent;
  color: var(--text2);
  text-decoration: none;
  font-size: 14px; font-weight: 600;
  transition: background var(--ease), transform var(--ease), box-shadow var(--ease);
}

.nav-item:hover { background: var(--surface3); color: var(--text); }
.nav-item.active {
  background: var(--accent);
  color: var(--ink);
  border-color: var(--ink);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: var(--bw) solid var(--ink);
}

.version { font-size: 11px; color: var(--muted); font-weight: 600; }

.logout-btn {
  margin: 4px 16px 0; padding: 8px 12px;
  background: var(--surface); color: var(--ink);
  border: var(--bw) solid var(--ink); border-radius: 10px;
  box-shadow: var(--shadow-sm);
  font: 700 12px/1 inherit; font-family: inherit;
  cursor: pointer; display: flex; align-items: center; gap: 6px;
  transition: transform var(--ease), box-shadow var(--ease), background var(--ease);
}
.logout-btn:hover { background: var(--red-dim); transform: translate(1px,1px); box-shadow: 1px 1px 0 var(--ink); }
.logout-btn:active { transform: translate(2px,2px); box-shadow: none; }

/* ── Main Content ── */
.main-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 32px 40px 48px;
}

.page { display: none; }
.page.active { display: block; animation: page-in 0.2s ease; }
@keyframes page-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-header { margin-bottom: 26px; }
.page-header h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.5px; }
.page-desc { color: var(--muted); font-size: 14px; margin-top: 4px; font-weight: 500; }

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 26px;
}

.stat-card {
  background: var(--surface);
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
  transition: transform var(--ease), box-shadow var(--ease);
}
.stat-card:nth-child(4n+1) { background: var(--mint); }
.stat-card:nth-child(4n+2) { background: var(--butter); }
.stat-card:nth-child(4n+3) { background: var(--sky); }
.stat-card:nth-child(4n+4) { background: var(--peach); }
.stat-card:hover { transform: translate(2px,2px); box-shadow: var(--shadow-sm); }

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: var(--surface) !important;
  color: var(--ink) !important;
  border: var(--bw) solid var(--ink);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.stat-value { font-size: 34px; font-weight: 800; line-height: 1.05; letter-spacing: -0.5px; }
.stat-label {
  font-size: 11px; color: var(--text2); margin-top: 4px;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.page > .card + .card { margin-top: 22px; }

.card-title { font-size: 17px; font-weight: 800; margin-bottom: 16px; }
.card-subtitle {
  font-size: 12px; font-weight: 800; margin-bottom: 14px;
  color: var(--ink); text-transform: uppercase; letter-spacing: 0.9px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13px; font-weight: 700;
  cursor: pointer;
  border: var(--bw) solid var(--ink);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform var(--ease), box-shadow var(--ease), background var(--ease), color var(--ease), opacity var(--ease);
  font-family: inherit;
  white-space: nowrap;
}
.btn:hover { transform: translate(1px,1px); box-shadow: 2px 2px 0 var(--ink); }
.btn:active { transform: translate(3px,3px); box-shadow: 0 0 0 var(--ink); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--accent); color: var(--ink); }
.btn-primary:hover { background: var(--accent-hover); }

.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover { background: #2b2b2b; }

.btn-outline { background: var(--surface); color: var(--ink); }
.btn-outline:hover { background: var(--surface3); }

.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 8px; box-shadow: var(--shadow-sm); }
.btn-sm:hover { box-shadow: 1px 1px 0 var(--ink); }
.btn-danger { background: var(--red-dim); color: #b91c1c; }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-green { background: var(--green-dim); color: var(--green); }
.btn-green:hover { background: var(--green); color: #fff; }

.quick-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 11px; font-weight: 800; color: var(--text2);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.8px;
}
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 140px; }

.input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: var(--bw) solid var(--ink);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: box-shadow var(--ease), border-color var(--ease);
}
.input::placeholder { color: #9a9387; }
.input:focus { border-color: var(--ink); box-shadow: 3px 3px 0 var(--accent); }
.textarea { min-height: 120px; resize: vertical; font-family: 'Menlo', 'Consolas', monospace; font-size: 12px; }
textarea.input { resize: vertical; }
select.input { cursor: pointer; }
.method-hint:empty { display: none; }
.method-hint {
  font-size: 12px; color: var(--text2); margin: -8px 0 16px; padding: 8px 12px;
  background: var(--butter); border: 1.5px solid var(--ink); border-radius: 8px;
}

/* ── Tools Grid ── */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
}

.tool-card {
  background: var(--surface);
  border: var(--bw) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  transition: transform var(--ease), box-shadow var(--ease), opacity var(--ease);
}
.tool-card:hover { transform: translate(2px,2px); box-shadow: var(--shadow-sm); }
.tool-card.disabled { opacity: 0.55; background: var(--surface2); }

.tool-card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }

.tool-favicon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--peach);
  border: var(--bw) solid var(--ink);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex-shrink: 0;
}
.tool-favicon img { width: 22px; height: 22px; }

.tool-card-info { flex: 1; min-width: 0; }
.tool-card-name { font-size: 15px; font-weight: 800; }
.tool-card-domains { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tool-card-badges { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1.5px solid var(--ink);
  font-size: 10px; font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-proxy { background: var(--butter); color: var(--ink); }
.badge-overlay { background: var(--sky); color: var(--ink); }
.badge-method { background: var(--surface3); color: var(--ink); }

.tool-card-actions { display: flex; align-items: center; gap: 8px; justify-content: space-between; }

/* ── Toggle ── */
.toggle { position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
  position: absolute; inset: 0;
  background: var(--surface3);
  border: var(--bw) solid var(--ink);
  border-radius: 26px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle .slider::before {
  content: ''; position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: var(--surface);
  border: var(--bw) solid var(--ink);
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(20px); }
.toggle input:focus-visible + .slider { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ── Sessions List ── */
.sessions-list { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

.session-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface2);
  border-radius: 10px;
  border: var(--bw) solid var(--ink);
}
.session-item-info { display: flex; align-items: center; gap: 12px; }
.session-item-name { font-weight: 700; font-size: 14px; }
.session-item-meta { font-size: 11px; color: var(--muted); }

/* Session tool cards (built in app.js) */
.session-tool-card {
  background: var(--surface) !important;
  border: var(--bw) solid var(--ink) !important;
  box-shadow: var(--shadow-sm);
}
.session-tool-card:hover { box-shadow: var(--shadow); transform: translate(-1px,-1px); }

/* ── Profiles List ── */
.profiles-list { display: flex; flex-direction: column; gap: 10px; }

.profile-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface2) !important;
  border-radius: 12px !important;
  border: var(--bw) solid var(--ink) !important;
  box-shadow: var(--shadow-sm);
}

.profile-item > div { flex: 1; min-width: 0; }

.profile-id { font-family: 'Menlo', monospace; font-size: 13px; font-weight: 700; }
.profile-meta { font-size: 11px; color: var(--muted); }

.status-dot-lg {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  flex-shrink: 0;
}
.status-dot-lg.active { background: #22c55e; }
.status-dot-lg.inactive { background: var(--red); }

/* ── Proxy ── */
.proxy-card {
  background: var(--surface2) !important;
  border: var(--bw) solid var(--ink) !important;
  border-radius: 12px !important;
  box-shadow: var(--shadow-sm);
}
.proxy-card .badge { border-color: var(--ink); }
.proxy-tools-list { display: flex; flex-wrap: wrap; gap: 8px; }
.proxy-tool-tag {
  padding: 4px 10px;
  background: var(--butter);
  color: var(--ink);
  border-radius: 8px;
  font-size: 11px; font-weight: 700;
  border: 1.5px solid var(--ink);
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(20,20,20,0.45);
  z-index: 1000;
  align-items: center; justify-content: center;
  padding: 16px;
}
.modal-overlay.active { display: flex; }

.modal {
  background: var(--surface);
  border: var(--bw) solid var(--ink);
  border-radius: 18px;
  width: 560px;
  max-width: 100%;
  max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: 6px 6px 0 var(--ink);
  animation: modal-in 0.18s ease;
}
@keyframes modal-in { from { transform: translateY(8px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px;
  border-bottom: var(--bw) solid var(--ink);
  background: var(--peach);
  border-radius: 16px 16px 0 0;
}
.modal-header h2 { font-size: 18px; font-weight: 800; }
.modal-close {
  width: 32px; height: 32px;
  background: var(--surface);
  border: var(--bw) solid var(--ink); border-radius: 8px;
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  font-size: 20px; line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform var(--ease), box-shadow var(--ease), background var(--ease);
}
.modal-close:hover { background: var(--red-dim); transform: translate(1px,1px); box-shadow: 1px 1px 0 var(--ink); }

.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 16px 24px;
  border-top: var(--bw) solid var(--ink);
  display: flex; gap: 12px; justify-content: flex-end;
}

/* Cookie edit modal (inline-styled in index.html) */
#cookie-modal { border: var(--bw) solid var(--ink) !important; box-shadow: 6px 6px 0 var(--ink) !important; }
.redacted-overlay { border: var(--bw) solid var(--ink) !important; background: var(--surface3) !important; }

/* ── Toast ── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 2000;
  display: flex; flex-direction: column; gap: 10px;
  max-width: calc(100vw - 32px);
}

.toast {
  padding: 12px 18px;
  border-radius: 10px;
  border: var(--bw) solid var(--ink);
  box-shadow: var(--shadow);
  font-size: 13px; font-weight: 700;
  color: var(--ink);
  animation: toast-in 0.25s ease;
  transition: opacity 0.3s ease;
}
.toast.success { background: var(--mint); }
.toast.error { background: var(--accent); }
.toast.info { background: var(--sky); }

@keyframes toast-in {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ── Status Message ── */
.status-msg {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1.5px solid var(--ink);
  font-size: 13px; font-weight: 600;
  display: none;
}
.status-msg.success { display: block; background: var(--mint); color: var(--ink); }
.status-msg.error { display: block; background: var(--peach); color: #9f1d1d; }

#session-file-name:empty { display: none !important; }

/* ── Loading ── */
.loading { text-align: center; padding: 40px; color: var(--muted); font-size: 14px; font-weight: 600; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d6cab3; border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Tag Input (Pages + CSS Selectors) ── */
.tag-input-container {
  background: var(--surface);
  border: var(--bw) solid var(--ink);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 48px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-start;
  cursor: text;
  transition: box-shadow var(--ease);
}
.tag-input-container:focus-within { box-shadow: 3px 3px 0 var(--accent); }

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--sky);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  font-family: 'Menlo', 'Consolas', monospace;
  color: var(--ink);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tag-chip .tag-remove { cursor: pointer; color: var(--ink); font-size: 15px; line-height: 1; flex-shrink: 0; }
.tag-chip .tag-remove:hover { color: var(--red); }

.tag-input {
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-family: 'Menlo', 'Consolas', monospace;
  flex: 1;
  min-width: 160px;
  padding: 4px 2px;
}
.tag-input::placeholder { color: #9a9387; }

/* Page rule items */
.page-rule-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface2);
  border-radius: 12px;
  border: var(--bw) solid var(--ink);
  box-shadow: var(--shadow-sm);
  margin-bottom: 10px;
}
.page-rule-tool { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 10px; }
.page-rule-paths { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* ── Searchable Select ── */
.searchable-select { position: relative; }
.ss-trigger { display: flex; align-items: center; justify-content: space-between; cursor: pointer; user-select: none; }
.ss-dropdown {
  display: none;
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface);
  border: var(--bw) solid var(--ink);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 100;
  overflow: hidden;
}
.ss-dropdown.open { display: block; }
.ss-search {
  border-radius: 0 !important;
  border: none !important;
  border-bottom: var(--bw) solid var(--ink) !important;
  box-shadow: none !important;
}
.ss-list { max-height: 240px; overflow-y: auto; }
.ss-item {
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
  display: flex; align-items: center; gap: 10px;
}
.ss-item:hover { background: var(--surface3); }
.ss-item.active { background: var(--accent); color: var(--ink); font-weight: 700; }
.ss-item img { width: 18px; height: 18px; border-radius: 4px; }
.ss-item.hidden { display: none; }

/* ── Login ── */
.login-card {
  width: 100%; max-width: 380px; padding: 36px 32px;
  background: var(--surface);
  border: var(--bw) solid var(--ink);
  border-radius: 20px;
  box-shadow: 6px 6px 0 var(--ink);
}
.login-logo {
  width: 56px; height: 56px; margin: 0 auto 12px;
  background: var(--accent); border: var(--bw) solid var(--ink); border-radius: 16px;
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.login-title { text-align: center; font-size: 22px; font-weight: 800; }
.login-sub { text-align: center; font-size: 13px; color: var(--muted); margin-top: 4px; font-weight: 500; }
.login-label {
  display: block; color: var(--text2); font-size: 11px; font-weight: 800;
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.8px;
}

/* ── Responsive ── */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .main-content { padding: 28px 24px 40px; }
}

@media (max-width: 760px) {
  body { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: var(--bw) solid var(--ink);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .sidebar-brand { padding: 12px 16px; border-bottom: none; flex: 1; }
  .brand-icon { width: 34px; height: 34px; font-size: 17px; }
  .sidebar-footer {
    border-top: none;
    padding: 12px 16px 12px 0 !important;
    flex-direction: row !important;
    align-items: center;
  }
  .sidebar-footer .version { display: none; }
  .logout-btn { margin: 0; }
  .sidebar-nav {
    order: 3;
    width: 100%;
    flex: none;
    flex-direction: row;
    overflow-x: auto;
    padding: 10px 16px 12px;
    border-top: var(--bw) solid var(--ink);
    gap: 6px;
  }
  .nav-item { padding: 8px 12px; font-size: 13px; white-space: nowrap; flex-shrink: 0; }

  .main-content { padding: 20px 16px 40px; min-height: 0; }
  .page-header h1 { font-size: 24px; }
  .stats-grid { gap: 12px; }
  .stat-card { padding: 14px; gap: 12px; }
  .stat-icon { width: 40px; height: 40px; }
  .stat-value { font-size: 26px; }
  .card { padding: 18px 16px; }
  .tools-grid { grid-template-columns: 1fr; }
  #tools-search { width: 100% !important; }
  #page-tools .page-header > div:last-child { width: 100%; }
  #page-tools .page-header > div:last-child > div { flex: 1; }

  /* Inline-styled layouts from index.html / app.js */
  #sessions-grid > div { grid-template-columns: 1fr !important; }
  #page-sessions .card > div[style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  .proxy-card > div:first-child,
  .profile-item > div:first-child { flex-wrap: wrap; }
  #access-log > div { flex-wrap: wrap; gap: 6px 12px !important; }
  #page-proxy .form-row .form-group { max-width: none !important; flex: 1 1 100% !important; }
  #page-proxy .form-row > .btn { flex: 1; }
  .modal-footer { flex-wrap: wrap; }
  .toast-container { right: 16px; bottom: 16px; }
}
