/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg:           #1e2238;
  --bg-card:      #272c4a;
  --bg-elevated:  #323761;
  --bg-input:     #3a4070;
  --border:       #464d82;
  --border-hover: #6870b8;
  --text:         #eaecf8;
  --text-muted:   #9ba5cc;
  --accent:       #7c80f5;
  --accent-hover: #6366f1;
  --danger:       #f87171;
  --success:      #4ade80;
  --warning:      #fbbf24;

  --phone-color: #60a5fa;
  --cw-color:    #a78bfa;

  --radius:  8px;
  --radius-sm: 4px;
  --shadow:  0 4px 24px rgba(0,0,0,0.4);
}

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

html { font-size: 14px; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

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

/* ── Layout ────────────────────────────────────────────────────────────────── */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.schedule-shell { height: 100vh; overflow: hidden; }

.page-main {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}
.page-narrow { max-width: 760px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}
.page-header h1 { font-size: 22px; font-weight: 700; }

/* ── Topbar ─────────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  z-index: 50;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-icon { font-size: 20px; }
.brand-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.back-link {
  color: var(--text-muted);
  font-size: 13px;
  white-space: nowrap;
}
.back-link:hover { color: var(--text); }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-input); border-color: var(--border-hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger  { background: var(--danger);  border-color: var(--danger);  color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }
.btn-icon { padding: 6px 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Badges ─────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .4px;
  text-transform: uppercase;
}
.badge-phone   { background: #1d4ed8; color: #bfdbfe; }
.badge-cw      { background: #6d28d9; color: #ddd6fe; }
.badge-neutral { background: var(--bg-input); color: var(--text-muted); }
.badge-success { background: #14532d; color: #86efac; }
.badge-pos     { background: var(--bg-elevated); color: var(--text); }
.badge-xs      { padding: 1px 5px; font-size: 10px; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* ── Contest Grid ───────────────────────────────────────────────────────────── */
.contest-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.contest-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color .15s, transform .1s;
}
.contest-card:hover { border-color: var(--border-hover); transform: translateY(-1px); }

.contest-card-top {
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.contest-callsign { font-size: 22px; font-weight: 800; color: #fff; letter-spacing: 1px; }
.contest-name     { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.contest-card-meta { padding: 12px 16px; }
.meta-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.meta-icon { width: 16px; text-align: center; }
.badges-row { gap: 4px; flex-wrap: wrap; margin-top: 4px; }

.contest-card-actions {
  display: flex;
  gap: 6px;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--border);
}

/* ── Empty State ────────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  gap: 12px;
  text-align: center;
  color: var(--text-muted);
}
.empty-icon { font-size: 48px; }
.empty-state h2 { color: var(--text); font-size: 20px; }
.empty-state-inline { color: var(--text-muted); padding: 20px; font-size: 13px; }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-card { max-width: 100%; }

.form-section {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.form-section:last-of-type { border-bottom: none; }
.form-section-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 540px) { .form-grid { grid-template-columns: 1fr; } }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }

input[type="text"],
input[type="datetime-local"],
select,
textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  width: 100%;
  transition: border-color .15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
input::placeholder { color: var(--text-muted); }

/* Webkit datetime input */
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(.6);
  cursor: pointer;
}

.form-hint { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }

.radio-group, .checkbox-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.radio-label, .checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.radio-label input, .checkbox-label input {
  width: auto;
  accent-color: var(--accent);
}

.unavail-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.unavail-row input { flex: 1; min-width: 160px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 16px;
}

/* ── Operators ──────────────────────────────────────────────────────────────── */
.operators-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.operator-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.op-color-bar { height: 4px; }

.op-card-body { padding: 14px 14px 10px; flex: 1; }
.op-header { margin-bottom: 8px; }
.op-callsign { font-size: 18px; font-weight: 700; letter-spacing: 1px; }
.op-name { font-size: 12px; color: var(--text-muted); }
.op-meta { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }

.op-availability { margin-top: 8px; }
.avail-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; flex-wrap: wrap; }
.avail-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.avail-row-wrap { margin-bottom: 8px; }
.avail-sep { color: var(--text-muted); padding: 0 2px; }
.avail-row select { width: auto; padding: 6px 8px; }

.op-card-actions { display: flex; gap: 6px; padding: 10px 14px 12px; border-top: 1px solid var(--border); }

/* ── Schedule Layout ────────────────────────────────────────────────────────── */
.schedule-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 52px);
}

.schedule-sidebar {
  width: 180px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 8px;
}

.sidebar-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  padding: 0 6px;
  margin-bottom: 8px;
}
.sidebar-sep { border-bottom: 1px solid var(--border); margin: 12px 0; }

.legend-item {
  display: flex;
  gap: 8px;
  padding: 6px;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  cursor: default;
}
.legend-item:hover { background: var(--bg-elevated); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; margin-top: 3px; }
.legend-info { min-width: 0; }
.legend-call { font-size: 13px; font-weight: 700; letter-spacing: .5px; }
.legend-name { font-size: 10px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-modes { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 3px; }
.legend-hours { font-size: 11px; color: var(--accent); margin-top: 2px; font-weight: 600; }

.legend-key { padding: 0 6px; }
.legend-key-row { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-muted); margin-bottom: 5px; }
.legend-key-swatch { width: 20px; height: 12px; border-radius: 2px; }
.mode-phone-swatch { background: var(--phone-color); }
.mode-cw-swatch    { background: var(--cw-color); }
.unavail-swatch    { background: repeating-linear-gradient(-45deg, #2a2d40, #2a2d40 4px, #1e2035 4px, #1e2035 8px); border: 1px solid var(--border); }

/* ── Timeline ───────────────────────────────────────────────────────────────── */
.timeline-wrapper {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  background: var(--bg);
  position: relative;
}

.timeline {
  position: relative;
  min-height: 200px;
}

/* Day bar */
.tl-day-bar { position: absolute; top: 0; height: 20px; z-index: 8; }
.tl-day-label {
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
  height: 20px;
  text-transform: uppercase;
  letter-spacing: .4px;
  background: var(--bg-card);
}

/* Hour header */
.tl-header {
  position: sticky;
  top: 0;
  background: var(--bg-card);
  border-bottom: 2px solid var(--border);
  z-index: 9;
}

.tl-corner {
  position: sticky;
  left: 0;
  background: var(--bg-card);
  z-index: 11;
  border-right: 1px solid var(--border);
}

.tl-tick {
  border-left: 1px solid var(--border);
  height: 100%;
  display: flex;
  align-items: flex-end;
  padding-bottom: 4px;
}
.tl-tick-midnight { border-left: 2px solid var(--border-hover); }
.tl-tick-label {
  font-size: 10px;
  color: var(--text-muted);
  padding-left: 4px;
  white-space: nowrap;
}

/* Rows */
.tl-row { border-bottom: 1px solid var(--border); }

.tl-row-label {
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.tl-row-content { background: var(--bg); }

/* Grid cells */
.tl-cell {
  border-right: 1px dashed rgba(46,49,84,.5);
  cursor: pointer;
  transition: background .1s;
}
.tl-cell:hover { background: rgba(99,102,241,.07); }

/* Unavailable */
.tl-unavail {
  background: repeating-linear-gradient(
    -45deg,
    rgba(30,32,53,.9),
    rgba(30,32,53,.9) 6px,
    rgba(20,22,40,.9) 6px,
    rgba(20,22,40,.9) 12px
  );
  border-left: 2px solid var(--danger);
  pointer-events: none;
}

/* Schedule blocks */
.tl-block {
  border-radius: 3px;
  overflow: hidden;
  transition: box-shadow .1s;
  border-top: 1px solid rgba(255,255,255,.1);
}
.tl-block:hover { box-shadow: 0 2px 12px rgba(0,0,0,.5) !important; }

.tl-block-cw::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 6px,
    rgba(0,0,0,.15) 6px,
    rgba(0,0,0,.15) 7px
  );
  pointer-events: none;
}
.tl-block { position: relative; }

.block-inner {
  padding: 4px 6px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
}
.block-call { font-size: 12px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: .5px; }
.block-mode { font-size: 10px; opacity: .8; font-weight: 600; }

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 520px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-sm { width: 380px; }

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

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }

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

.slot-time-display {
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ── Dropdown ───────────────────────────────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 140px;
  z-index: 60;
  box-shadow: var(--shadow);
}
.dropdown-menu.show { display: block; }
.dropdown-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}
.dropdown-menu button:hover { background: var(--bg-input); }

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .2s, transform .2s;
  z-index: 200;
  pointer-events: none;
  max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: #14532d; color: #86efac; border: 1px solid #22c55e; }
.toast-error   { background: #450a0a; color: #fca5a5; border: 1px solid var(--danger); }
.toast-info    { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); }

/* ── Resize handle ──────────────────────────────────────────────────────────── */
.tl-resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  width: 8px;
  height: 100%;
  cursor: ew-resize;
  z-index: 6;
  border-radius: 0 3px 3px 0;
  background: rgba(255,255,255,.15);
  opacity: 0;
  transition: opacity .15s;
}
.tl-block:hover .tl-resize-handle { opacity: 1; }
.tl-resize-handle:hover            { background: rgba(255,255,255,.35); opacity: 1; }

/* ── Zoom controls ──────────────────────────────────────────────────────────── */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.zoom-label {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  min-width: 38px;
  text-align: center;
}
.zoom-controls .btn-icon {
  border: none;
  background: none;
  font-size: 16px;
  font-weight: 700;
  padding: 2px 8px;
  line-height: 1;
}
.zoom-controls .btn-icon:hover { background: var(--bg-input); }

/* ── User chip ──────────────────────────────────────────────────────────────── */
.user-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 12px;
  color: var(--text-muted);
}
.user-chip .btn-icon {
  padding: 3px 7px;
  font-size: 13px;
  border: none;
  background: none;
}
.user-chip .btn-icon:hover { background: var(--bg-input); }

/* ── Utilities ──────────────────────────────────────────────────────────────── */
.muted { color: var(--text-muted); }

/* ── Print ──────────────────────────────────────────────────────────────────── */
@media print {
  .topbar, .schedule-sidebar, .topbar-actions { display: none !important; }
  .schedule-layout { height: auto; }
  .timeline-wrapper { overflow: visible; }
  body { background: white; color: black; }
  .tl-block { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
