:root {
  --bg: #070a0c;
  --surface: rgba(18, 20, 28, 0.72);
  --surface2: rgba(24, 27, 38, 0.85);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f0f5f8;
  --muted: #7aa0b8;
  --accent: #6ea8ff;
  --accent2: #a78bfa;
  --glow: rgba(110, 168, 255, 0.35);
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --hit: #22d3ee;
  --radius: 14px;
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'Cascadia Code', Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
}

.bg-mesh {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 10% 0%, rgba(110, 168, 255, 0.12), transparent 50%),
    radial-gradient(ellipse 60% 50% at 90% 10%, rgba(167, 139, 250, 0.1), transparent 45%),
    radial-gradient(ellipse 50% 40% at 50% 100%, rgba(34, 211, 238, 0.06), transparent 50%);
  pointer-events: none;
}

.app { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
  background: rgba(7, 8, 12, 0.6);
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #fff;
  box-shadow: 0 0 24px var(--glow);
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.pro {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.12em;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin-left: 4px;
}
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.topbar-meta { display: flex; align-items: center; gap: 10px; }
.site-link {
  color: var(--accent); text-decoration: none; font-size: 12px; font-weight: 500;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface);
}
.site-link:hover { border-color: var(--accent); box-shadow: 0 0 16px var(--glow); }

.pill {
  font-size: 11px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted);
}
.pill.ok { color: var(--ok); border-color: rgba(52, 211, 153, 0.4); background: rgba(52, 211, 153, 0.08); }

.tabs {
  display: flex; gap: 4px; padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 8, 12, 0.4);
}
.tab {
  background: transparent; border: none; color: var(--muted);
  padding: 8px 16px; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 500;
  transition: all 0.15s ease;
}
.tab:hover { color: var(--text); background: var(--surface); }
.tab.active {
  color: #fff; background: linear-gradient(135deg, rgba(110,168,255,0.2), rgba(167,139,250,0.15));
  box-shadow: inset 0 0 0 1px rgba(110,168,255,0.25);
}

.workspace {
  display: grid; grid-template-columns: 280px 1fr; flex: 1; gap: 0; min-height: 0;
}
@media (max-width: 960px) { .workspace { grid-template-columns: 1fr; } }

.rail {
  padding: 12px; display: flex; flex-direction: column; gap: 10px;
  border-right: 1px solid var(--border); overflow-y: auto;
}
.stage { padding: 12px 16px; overflow-y: auto; min-height: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  overflow: hidden;
}
.card.hero { padding: 0; }
.card-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--muted); padding: 12px 14px 0;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.card-head em { font-style: normal; color: var(--muted); font-weight: 500; font-size: 12px; }

.rail .card { padding-bottom: 12px; }
.rail .card .fld, .rail .card input, .rail .card textarea, .rail .card select, .rail .card .btn-block { margin: 8px 12px 0; width: calc(100% - 24px); }

.fld { display: flex; flex-direction: column; gap: 4px; }
.fld span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.fld-row { display: flex; gap: 6px; margin: 8px 12px 0; }
.fld-row input { flex: 1; min-width: 0; }

.autocomplete-wrap { position: relative; margin: 0; flex: 1; min-width: 0; }
.search-row {
  display: flex; align-items: flex-start; gap: 8px; margin: 8px 12px 0;
}
.search-row .search-btn {
  flex-shrink: 0; margin: 0; width: auto; min-width: 88px; padding: 9px 16px;
  height: 40px; align-self: flex-start;
}
.autocomplete-wrap input {
  width: 100%;
  padding-left: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%238b93a7' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242 1.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 11px center;
}
.suggest-dropdown {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 50;
  background: rgba(18, 20, 28, 0.98); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55); max-height: 280px; overflow-y: auto;
  backdrop-filter: blur(16px);
}
.suggest-dropdown.hidden { display: none; }
.suggest-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04); transition: background 0.1s;
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover, .suggest-item.active { background: rgba(110, 168, 255, 0.12); }
.suggest-icon {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 10px; font-weight: 700;
  background: rgba(110, 168, 255, 0.15); color: var(--accent);
}
.suggest-item.course .suggest-icon { background: rgba(167, 139, 250, 0.15); color: var(--accent2); }
.suggest-text strong { display: block; font-size: 13px; font-weight: 600; }
.suggest-text span { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.suggest-empty, .suggest-loading { padding: 14px; text-align: center; color: var(--muted); font-size: 12px; }

.rail .card input:not([type="hidden"]) { margin: 8px 12px 0; width: calc(100% - 24px); }

input, select, textarea {
  background: rgba(0, 0, 0, 0.35); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: 10px; font: inherit; transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow);
}

.btn {
  border: 1px solid var(--border); background: var(--surface2); color: var(--text);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 500;
  transition: all 0.15s ease;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn-block { display: block; text-align: center; }
.btn-glow {
  background: linear-gradient(135deg, #69b5e5, #74bbe7);
  border: none; color: #fff; box-shadow: 0 4px 20px var(--glow);
}
.btn-glow:hover { box-shadow: 0 6px 28px var(--glow); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-danger { border-color: rgba(248,113,113,0.4); color: var(--err); }
.btn-sm { padding: 5px 10px; font-size: 11px; }
.btn-row { display: flex; gap: 8px; margin: 10px 12px 0; }
.btn-row .flex { flex: 1; }

.check { display: flex; align-items: center; gap: 8px; margin: 8px 12px 0; color: var(--muted); font-size: 12px; cursor: pointer; }

.pane { display: none; flex-direction: column; gap: 12px; animation: fadeIn 0.2s ease; }
.pane.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.hero-top { display: flex; justify-content: space-between; align-items: flex-start; padding: 16px 16px 8px; }
.hero h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.03em; }
.sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.sub.pad { padding: 0 14px 12px; }

.schedule-stats {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px;
}
.stat-pill {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: rgba(0,0,0,0.28); border: 1px solid var(--border); border-radius: 10px;
  font-size: 11px; color: var(--muted);
}
.stat-pill strong { color: var(--text); font-size: 14px; font-weight: 700; }

.schedule-section-label {
  padding: 4px 16px 8px; font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted);
}

.week-wrap { padding: 0 12px 12px; overflow-x: auto; }
.week-grid {
  display: grid; grid-template-columns: 52px repeat(5, minmax(100px, 1fr));
  gap: 4px; min-width: 580px; font-size: 10px;
}
.week-grid .gh { background: var(--surface2); color: var(--muted); padding: 8px 6px; text-align: center; border-radius: 8px; font-weight: 600; }
.week-grid .gt { color: var(--muted); padding: 4px 6px; font-size: 9px; font-weight: 500; }
.week-grid .gc { min-height: 36px; background: rgba(0,0,0,0.22); border-radius: 8px; position: relative; border: 1px solid var(--border); }
.week-grid .block {
  position: absolute; left: 3px; right: 3px; border-radius: 7px; padding: 4px 5px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--block-color, #6ea8ff) 55%, transparent), rgba(0,0,0,0.35));
  border: 1px solid color-mix(in srgb, var(--block-color, #6ea8ff) 70%, white);
  font-size: 9px; line-height: 1.3; overflow: hidden; cursor: default;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  transition: transform 0.12s ease, box-shadow 0.12s ease, z-index 0s;
  z-index: 1;
}
.week-grid .block:hover, .week-grid .block:focus-visible {
  transform: scale(1.02); z-index: 5; box-shadow: 0 8px 20px rgba(0,0,0,0.35);
  outline: none;
}
.week-grid .block strong { display: block; font-size: 10px; font-weight: 700; }
.week-grid .block span { display: block; opacity: 0.9; }
.week-grid .block .block-loc { font-size: 8px; opacity: 0.75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.week-grid .block.pending { border-color: var(--warn); }
.week-grid .block.ideal { border-color: var(--accent2); background: linear-gradient(135deg, rgba(167,139,250,0.4), rgba(110,168,255,0.25)); }

.schedule-table-wrap { max-height: 340px; margin: 0 12px 12px; border: 1px solid var(--border); border-radius: 12px; }
.schedule-table .course-cell { white-space: normal; min-width: 180px; }
.schedule-table .course-code { display: block; font-size: 13px; font-weight: 700; }
.schedule-table .course-title { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; max-width: 260px; white-space: normal; }
.schedule-table .course-crn { display: block; font-size: 10px; color: var(--muted); opacity: 0.8; margin-top: 2px; }
.schedule-table .when-cell { font-weight: 500; color: var(--accent); }
.schedule-row { outline: none; }

.schedule-tooltip {
  position: fixed; z-index: 300; pointer-events: none;
  min-width: 280px; max-width: 340px; padding: 0;
  background: rgba(16, 18, 26, 0.96); border: 1px solid rgba(110,168,255,0.35);
  border-radius: 14px; box-shadow: 0 16px 48px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.06);
  backdrop-filter: blur(16px);
  animation: fadeIn 0.12s ease;
}
.schedule-tooltip .tt-head {
  padding: 12px 14px 10px; border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(110,168,255,0.12), rgba(167,139,250,0.08));
  border-radius: 14px 14px 0 0;
}
.schedule-tooltip .tt-code { font-size: 12px; font-weight: 700; color: var(--accent); }
.schedule-tooltip .tt-title { font-size: 13px; font-weight: 600; margin-top: 4px; line-height: 1.35; }
.schedule-tooltip .tt-body { padding: 10px 14px 12px; display: grid; gap: 6px; }
.schedule-tooltip .tt-row {
  display: grid; grid-template-columns: 92px 1fr; gap: 8px; align-items: start; font-size: 11px;
}
.schedule-tooltip .tt-row span { color: var(--muted); text-transform: uppercase; font-size: 9px; letter-spacing: 0.05em; padding-top: 2px; }
.schedule-tooltip .tt-row strong { font-weight: 500; color: var(--text); line-height: 1.35; white-space: normal; }

.tbl-wrap { overflow: auto; }
.tbl-wrap.tall { max-height: calc(100vh - 220px); }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; position: sticky; top: 0; background: var(--surface2); z-index: 1; }
tbody tr { cursor: pointer; transition: background 0.1s; }
tbody tr:hover td { background: rgba(110, 168, 255, 0.06); }

.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10px; font-weight: 600; }
.tag-open { background: rgba(52,211,153,0.15); color: var(--ok); }
.tag-full { background: rgba(248,113,113,0.12); color: var(--err); }
.tag-wait { background: rgba(251,191,36,0.12); color: var(--warn); }
.tag-reg { background: rgba(52,211,153,0.12); color: var(--ok); }

.log-card { max-height: 220px; }
.log { padding: 10px 14px; font-family: var(--mono); font-size: 11px; max-height: 180px; overflow-y: auto; color: var(--muted); }
.log .ok { color: var(--ok); } .log .err { color: var(--err); } .log .warn { color: var(--warn); } .log .hit { color: var(--hit); }

.hidden { display: none !important; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.65); backdrop-filter: blur(8px);
  display: grid; place-items: center; padding: 20px;
  animation: fadeIn 0.12s ease;
}
.modal {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 18px;
  padding: 24px; max-width: 440px; width: 100%; position: relative;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255,255,255,0.05);
  animation: popIn 0.18s cubic-bezier(0.34, 1.4, 0.64, 1);
}
@keyframes popIn { from { opacity: 0; transform: scale(0.92); } to { opacity: 1; transform: scale(1); } }
.modal-close {
  position: absolute; top: 12px; right: 14px; background: none; border: none;
  color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1;
}
.modal-badge { display: inline-block; margin-bottom: 8px; }
.modal h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 4px; }
.modal-sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.modal-grid div { background: rgba(0,0,0,0.25); padding: 10px; border-radius: 10px; border: 1px solid var(--border); }
.modal-grid span { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; margin-bottom: 4px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Toasts */
.toasts { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  pointer-events: auto; padding: 12px 16px; border-radius: 12px; min-width: 260px; max-width: 360px;
  background: var(--surface2); border: 1px solid var(--border); backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4); animation: slideIn 0.2s ease;
}
.toast.hit { border-color: var(--hit); box-shadow: 0 0 24px rgba(34,211,238,0.25); }
.toast.ok { border-color: var(--ok); }
.toast strong { display: block; font-size: 13px; margin-bottom: 2px; }
.toast span { font-size: 11px; color: var(--muted); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

.flash-body { animation: bodyFlash 0.35s ease 2; }
@keyframes bodyFlash { 50% { filter: brightness(1.15); } }

.empty { color: var(--muted); text-align: center; padding: 24px !important; }

/* Login */
.login-screen {
  position: relative; z-index: 2; min-height: 100vh;
  display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 6px; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.login-form .fld { margin-bottom: 12px; }
.login-form .btn-block { margin-top: 8px; width: 100%; }
.login-divider {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 16px 0 6px; padding-top: 12px; border-top: 1px solid var(--border);
}
.login-email-note { margin-bottom: 12px !important; font-size: 12px !important; }
.login-email-hint { font-size: 12px; margin: -4px 0 8px; }
.login-email-hint.ok { color: var(--ok, #34d399); }
.login-email-hint.bad { color: var(--err, #f87171); }
.email-badge { display: block; margin-top: 2px; font-size: 11px; opacity: 0.85; }
.login-error {
  color: var(--err); font-size: 12px; margin: 8px 0 4px;
  padding: 8px 10px; border-radius: 8px;
  background: rgba(248, 113, 113, 0.1); border: 1px solid rgba(248, 113, 113, 0.25);
}

.session-user {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 8px 12px 0; padding: 10px 12px; border-radius: 10px;
  background: rgba(0, 0, 0, 0.2); border: 1px solid var(--border);
}
.session-user strong { display: block; font-size: 13px; }
.session-user .sub { font-size: 11px; color: var(--muted); }

.search-hint {
  font-size: 11px; color: var(--muted); margin: 4px 12px 0; line-height: 1.4;
}

.suggest-mark {
  background: rgba(110, 168, 255, 0.25); color: #fff;
  border-radius: 3px; padding: 0 2px;
}

.snipe-summary {
  margin: 0 16px 12px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid rgba(110, 168, 255, 0.35);
  background: linear-gradient(135deg, rgba(110,168,255,0.12), rgba(167,139,250,0.08));
}
.snipe-summary.hidden { display: none !important; }
.snipe-summary-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px;
}
.snipe-summary-head strong { font-size: 13px; }
.snipe-summary-list { display: flex; flex-direction: column; gap: 6px; }
.snipe-summary-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 10px; background: rgba(0,0,0,0.22); border: 1px solid var(--border);
  font-size: 12px;
}
.snipe-summary-item span { color: var(--muted); font-size: 11px; }

.target-cards { display: none; padding: 0 12px 12px; gap: 8px; flex-direction: column; }
.target-card {
  border: 1px solid var(--border); border-radius: 12px; padding: 12px;
  background: rgba(0,0,0,0.22);
}
.target-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 6px; }
.target-card-top strong { font-size: 14px; }
.target-card-meta { font-size: 11px; color: var(--muted); line-height: 1.45; }
.target-card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.target-card-foot .live-seats { font-size: 12px; font-weight: 600; color: var(--accent); }
.live-seats.live-open { color: var(--ok); font-weight: 700; }
tr.seat-open td, .target-card.seat-open { border-color: rgba(52, 211, 153, 0.45); }
tr.seat-just-opened, .target-card.seat-just-opened {
  animation: seatPulse 1.2s ease 2;
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.35);
}
@keyframes seatPulse {
  50% { background: rgba(52, 211, 153, 0.14); }
}

@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
  .workspace .stage { order: 1; }
  .workspace .rail { order: 2; border-right: none; border-top: 1px solid var(--border); max-height: none; }
  .topbar { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
  .brand-sub { display: none; }
  .site-link { display: none; }
  .tabs {
    position: sticky; top: 0; z-index: 20; overflow-x: auto; flex-wrap: nowrap;
    padding: 6px 10px; -webkit-overflow-scrolling: touch;
  }
  .tab { flex-shrink: 0; padding: 8px 14px; font-size: 12px; }
  .stage { padding: 10px 12px 24px; }
  .rail { padding: 10px 12px 20px; }
  .hero-top { flex-direction: column; align-items: stretch; gap: 10px; }
  .hero-top .btn { width: 100%; }
  .modal-grid { grid-template-columns: 1fr; }
  .toasts { left: 12px; right: 12px; top: auto; bottom: 12px; }
  .toast { max-width: none; min-width: 0; }
  .targets-table-wrap { display: none; }
  .target-cards { display: flex; }
  .tbl-wrap.tall { max-height: none; }
  .log-card { max-height: none; }
  .log { max-height: 240px; }
  .search-row { flex-direction: column; }
  .search-row .search-btn { width: 100%; min-width: 0; }
  .week-wrap { margin: 0 8px 12px; }
}
