:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev-2: #1c232c;
  --border: #30363d;
  --border-strong: #444c56;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --text-muted: #6e7681;
  --accent: #238636;
  --accent-hover: #2ea043;
  --danger: #da3633;
  --danger-hover: #f85149;
  --warn: #d29922;
  --info: #1f6feb;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --radius: 8px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 16px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #238636, #1f6feb);
  font-weight: 700;
  color: white;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.refresh-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 12px;
}

.refresh-indicator .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}

.btn:hover { background: #2d333b; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-elev-2); }

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-icon {
  padding: 6px 8px;
  font-size: 13px;
}

/* ---------- Cards / summary ---------- */

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.summary-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  position: relative;
  overflow: hidden;
}

.summary-card .label {
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.summary-card .value {
  font-size: 28px;
  font-weight: 600;
  color: var(--text);
}

.summary-card.green .value { color: var(--green); }
.summary-card.red .value { color: var(--red); }
.summary-card.yellow .value { color: var(--yellow); }

/* ---------- Panel ---------- */

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev-2);
}

.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.panel-body {
  padding: 0;
}

.collapsible .panel-body { display: none; }
.collapsible.open .panel-body { display: block; }
.collapsible .chevron { transition: transform 0.2s; }
.collapsible.open .chevron { transform: rotate(90deg); }

/* ---------- Bulk action bar ---------- */

.bulk-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elev);
  border: 1px solid var(--info);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  box-shadow: 0 4px 16px rgba(31, 111, 235, 0.2);
}

.bulk-bar.visible { display: flex; }
.bulk-bar .count { font-weight: 600; }
.bulk-bar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Table ---------- */

.table-wrap {
  overflow-x: auto;
}

table.users {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.users th, table.users td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.users thead th {
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  position: sticky;
  top: 0;
  z-index: 1;
}

table.users tbody tr:hover { background: rgba(255, 255, 255, 0.02); }

table.users tbody tr.unavailable { opacity: 0.6; }

table.users td.actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.username-mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--text-dim);
}

/* ---------- Status badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.badge.active { background: rgba(63, 185, 80, 0.15); color: var(--green); }
.badge.inactive { background: rgba(248, 81, 73, 0.15); color: var(--red); }
.badge.unknown { background: rgba(139, 148, 158, 0.15); color: var(--text-dim); }
.badge.paused { background: rgba(210, 153, 34, 0.15); color: var(--yellow); }

.days-pill {
  font-weight: 600;
}
.days-pill.green { color: var(--green); }
.days-pill.yellow { color: var(--yellow); }
.days-pill.red { color: var(--red); }

/* ---------- Traffic bar ---------- */

.traffic {
  min-width: 140px;
}

.traffic .label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
}

.bar > div {
  height: 100%;
  background: var(--green);
  transition: width 0.3s;
}
.bar.yellow > div { background: var(--yellow); }
.bar.red > div { background: var(--red); }

/* ---------- Checkbox ---------- */

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: modalIn 0.15s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.modal-close:hover { color: var(--text); }

/* ---------- Forms ---------- */

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 500;
}

input[type="text"], input[type="time"], input[type="password"], select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

input[type="text"]:focus, input[type="time"]:focus,
input[type="password"]:focus, select:focus {
  outline: none;
  border-color: var(--info);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.25);
}

.days-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.day-check {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  font-size: 12px;
}

.day-check input { margin: 0; }

.day-check.checked {
  border-color: var(--accent);
  background: rgba(35, 134, 54, 0.12);
}

.selected-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  max-height: 90px;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.pill {
  display: inline-flex;
  align-items: center;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
}

/* ---------- Schedules table ---------- */

table.schedules { width: 100%; border-collapse: collapse; font-size: 13px; }
table.schedules th, table.schedules td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
table.schedules thead th {
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
}
.usernames-cell {
  max-width: 320px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.usernames-cell .pill { font-size: 10.5px; }

/* ---------- Toasts ---------- */

.toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  max-width: 360px;
}

.toast {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  animation: toastIn 0.2s ease-out;
  font-size: 13px;
}

.toast.success { border-left-color: var(--accent); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--info); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

/* ---------- Empty state ---------- */

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-dim);
}

.empty .empty-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

/* ---------- Lookup page ---------- */

.lookup-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lookup-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
}

.lookup-card h1 {
  font-size: 22px;
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.lookup-card .subtitle {
  color: var(--text-dim);
  margin: 0 0 24px;
  font-size: 13px;
}

.lookup-form {
  display: flex;
  gap: 8px;
}

.lookup-form input { flex: 1; }

.lookup-result {
  margin-top: 24px;
  display: none;
}

.lookup-result.visible { display: block; }

.lookup-result .row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.lookup-result .row:last-child { border-bottom: none; }
.lookup-result .row .key { color: var(--text-dim); font-size: 12px; }
.lookup-result .row .val { font-weight: 500; }

.lookup-result .bar { margin-top: 6px; }

.lookup-error {
  margin-top: 16px;
  padding: 12px;
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  color: var(--red);
  display: none;
  font-size: 13px;
}
.lookup-error.visible { display: block; }

/* ---------- Login overlay ---------- */

.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 17, 23, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.login-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.login-card h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.login-card p {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 18px;
}

/* ---------- Responsive ---------- */

@media (max-width: 760px) {
  .container { padding: 16px; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .summary-card .value { font-size: 22px; }
  table.users th, table.users td { padding: 10px 8px; }
  .traffic { min-width: 100px; }
  .bulk-bar { flex-direction: column; align-items: stretch; gap: 8px; }
  .bulk-bar .actions { justify-content: stretch; }
  .bulk-bar .actions .btn { flex: 1; }
  .days-grid { grid-template-columns: repeat(3, 1fr); }
}
