:root {
  --bg: #0b1220;
  --card: #121a2b;
  --text: #e6eefc;
  --muted: #b6c2e2;
  --brand: #66d17a;
  --accent: #7aa7ff;
  --danger: #ff6b6b;
  --border: #22304d;
  --surface: #0c1424;
  --thBg: #0e1830;
  --topbar: rgba(9,14,26,0.8);
  --hoverRow: rgba(122,167,255,0.06);
  /* buttons */
  --btnBg: #101a2d;
  --btnText: var(--text);
  --btnBorder: var(--border);
  --btnHover: #132140;
  --btnPrimaryText: #081426;
}

:root[data-theme="light"] {
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --brand: #22c55e;
  --accent: #2563eb;
  --danger: #dc2626;
  --border: #e5e7eb;
  --surface: #f8fafc;
  --thBg: #f1f5f9;
  --topbar: rgba(255,255,255,0.8);
  --hoverRow: rgba(37,99,235,0.08);
  /* buttons */
  --btnBg: #ffffff;
  --btnText: #0f172a;
  --btnBorder: #e5e7eb;
  --btnHover: #f3f4f6;
  --btnPrimaryText: #ffffff;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: ui-sans-serif, system-ui, Segoe UI, Roboto, Helvetica, Arial, Apple Color Emoji, Segoe UI Emoji; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: 10px 20px; background: var(--topbar); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); gap: 16px; }
.brand { font-weight: 700; letter-spacing: 0.4px; font-size: 18px; display: flex; align-items: center; gap: 8px; }

/* Navigation styles */
#nav { display: flex; align-items: center; gap: 12px; flex: 1; justify-content: space-between; margin-left: 24px; }
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  border: 1px solid transparent;
}
.nav-link:hover { background: var(--surface); border-color: var(--border); }
.nav-link.primary { background: var(--accent); color: white; }
.nav-link.primary:hover { background: #5a9bff; }
.nav-link.logout { color: var(--muted); font-size: 12px; padding: 6px 12px; }
.nav-link.logout:hover { color: #f87171; background: rgba(248, 113, 113, 0.1); }
.nav-icon { font-size: 14px; }
.nav-user { display: flex; align-items: center; gap: 12px; }
.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text);
}
.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #22c55e, #3b82f6);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
}
.container { width: 100%; max-width: 100%; margin: 24px auto; padding: 0 20px; }
.footer { text-align: center; color: var(--muted); padding: 24px 0; font-size: 12px; border-top: 1px solid var(--border); margin-top: 32px; }

.card { background: radial-gradient(1200px 500px at -10% -50%, rgba(102,209,122,0.15), rgba(255,255,255,0) 40%),
                 radial-gradient(1000px 600px at 120% -10%, rgba(122,167,255,0.12), rgba(255,255,255,0) 50%),
                 var(--card);
        border: 1px solid var(--border); border-radius: 12px; padding: 18px; box-shadow: 0 0 0 1px rgba(255,255,255,0.03) inset; }
.row { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px; }
.field { grid-column: span 4; display: flex; flex-direction: column; }
.field label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.field input, .field select { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 10px; outline: none; }
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(122,167,255,0.15); }
.actions { display: flex; gap: 10px; margin-top: 14px; }
.btn { border: 1px solid var(--btnBorder); background: var(--btnBg); color: var(--btnText); padding: 10px 14px; border-radius: 10px; cursor: pointer; }
.btn:hover { background: var(--btnHover); }
.btn.primary { background: linear-gradient(135deg, var(--brand), #4db3e8); border: none; color: var(--btnPrimaryText); font-weight: 600; }
.btn.ghost { background: transparent; color: var(--text); }
.btn.ghost:hover { background: rgba(0,0,0,0.05); }
.btn.danger { background: #201317; border-color: #3a2027; color: #ff9aa0; }
.muted { color: var(--muted); }
.space { height: 16px; }
.error { color: #ff9aa0; font-size: 12px; }
.invalid { border-color: var(--danger) !important; box-shadow: 0 0 0 3px rgba(255,107,107,0.15) !important; }

/* Action steps in dashboard */
.action-steps { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.action-step {
  display: inline-flex;
  align-items: center;
  gap: 0;
  position: relative;
}
.action-step .step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  margin-right: -6px;
  z-index: 1;
  position: relative;
}
.action-step.done .step-num {
  background: #22c55e;
  border-color: #22c55e;
  color: white;
}
.action-step .step-btn {
  padding-left: 12px;
}
.action-step.done .step-btn {
  border-color: rgba(34, 197, 94, 0.3);
  background: rgba(34, 197, 94, 0.1);
}
.action-step.done .step-btn:hover {
  background: rgba(34, 197, 94, 0.2);
}
.edit-btn {
  margin-left: 8px;
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.edit-btn:hover {
  background: #5a9bff;
}

table { border-collapse: collapse; width: 100%; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
th, td { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; font-size: 11px; }
th { background: var(--thBg); color: var(--muted); font-weight: 600; font-size: 10px; letter-spacing: 0.2px; white-space: normal; line-height: 1.3; max-width: 120px; }
td .btn { font-size: 11px; padding: 4px 8px; text-decoration: none; display: inline-block; line-height: 1.4; }
tbody tr:hover { background: var(--hoverRow); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; border: 1px solid var(--border); background: var(--surface); }

/* Status dropdown styling */
.status-select { 
  cursor: pointer; 
  border: 1px solid transparent; 
  background: transparent; 
  color: var(--text);
  font-size: 11px; 
  padding: 4px 8px; 
  border-radius: 4px;
  min-width: 120px;
}
.status-select:hover { 
  background: var(--surface); 
  border-color: var(--border);
}
.status-select:focus { 
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.status-select option {
  background: var(--surface);
  color: var(--text);
}

/* Status row colors - muted versions for dark theme */
tr.status-initiated { background: rgba(255, 152, 0, 0.2); }
tr.status-final { background: rgba(76, 175, 80, 0.18); }
tr.status-report { background: rgba(33, 150, 243, 0.18); }
tr.status-cancelled { background: rgba(244, 67, 54, 0.18); }
tr.status-archived { background: rgba(158, 158, 158, 0.2); }

/* Light theme status colors */
:root[data-theme="light"] tr.status-initiated { background: rgba(255, 152, 0, 0.3); }
:root[data-theme="light"] tr.status-final { background: rgba(76, 175, 80, 0.25); }
:root[data-theme="light"] tr.status-report { background: rgba(33, 150, 243, 0.25); }
:root[data-theme="light"] tr.status-cancelled { background: rgba(244, 67, 54, 0.2); }
:root[data-theme="light"] tr.status-archived { background: rgba(158, 158, 158, 0.3); }

/* Status legend */
.status-legend { display: flex; align-items: center; gap: 12px; font-size: 11px; color: var(--muted); }
.legend-item { display: flex; align-items: center; gap: 4px; }
.legend-dot { width: 10px; height: 10px; border-radius: 2px; }
.legend-dot.initiated { background: rgba(255, 152, 0, 0.7); }
.legend-dot.final { background: rgba(76, 175, 80, 0.7); }
.legend-dot.report { background: rgba(33, 150, 243, 0.7); }
.legend-dot.cancelled { background: rgba(244, 67, 54, 0.7); }
.legend-dot.archived { background: rgba(158, 158, 158, 0.7); }

/* horizontal scroll for wide tables */
.scroll-x { overflow-x: auto; }
.scroll-x table { white-space: nowrap; min-width: max-content; }

/* vertical fit for table area */
.table-wrap { display: flex; flex-direction: column; min-height: calc(100vh - 240px); }
.table-body { overflow: auto; flex: 1 1 auto; }
.vh-fit { height: calc(100vh - 240px); min-height: calc(100vh - 240px); max-height: calc(100vh - 240px); }

/* search input */
.search { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.search input { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; min-width: 260px; }
.search input::placeholder { color: var(--muted); }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(122,167,255,0.15); outline: none; }

/* sticky/frozen right column */
.sticky-right { position: sticky; right: 0; z-index: 2; background: var(--thBg); }
.sticky-right-td { position: sticky; right: 0; z-index: 1; background: var(--surface); border-left: 1px solid var(--border); box-shadow: -6px 0 8px rgba(0,0,0,0.2); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.center { display: grid; place-items: center; min-height: 50vh; }
.title { font-size: 20px; margin: 0 0 12px 0; }

/* Master schedule builder */
.ms-container { display: flex; flex-direction: column; gap: 16px; }
.ms-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.ms-header-meta { display: flex; flex-direction: column; gap: 4px; }
.ms-header-meta .title { margin: 0; }
.ms-header-meta .small { font-size: 12px; }
.ms-stepper { display: flex; flex-wrap: wrap; gap: 8px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.ms-stepper-item { border: 1px solid var(--border); background: var(--btnBg); color: var(--text); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.ms-stepper-item.active { background: var(--accent); color: var(--btnPrimaryText); border-color: var(--accent); }
.ms-step-body { display: flex; flex-direction: column; gap: 18px; margin-top: 8px; }
.ms-group { border: 1px solid var(--border); border-radius: 10px; padding: 16px; background: rgba(12, 20, 36, 0.35); }
:root[data-theme="light"] .ms-group { background: rgba(37, 99, 235, 0.05); }
.ms-group-title { margin: 0 0 12px 0; font-size: 16px; }
.ms-fields-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.ms-field { display: flex; flex-direction: column; gap: 6px; }
.ms-field label { font-size: 12px; color: var(--muted); }
.ms-field input, .ms-field textarea, .ms-field select { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 10px; resize: vertical; }
.ms-field select { appearance: none; cursor: pointer; }
.ms-field textarea { min-height: 72px; }
.ms-field input:focus, .ms-field textarea:focus, .ms-field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(122,167,255,0.15); outline: none; }
.combo-input { display: flex; gap: 8px; align-items: stretch; }
.combo-input input { flex: 1; }
.study-director-selector { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 10px; }
.study-director-select { flex: 1 1 240px; display: flex; flex-direction: column; gap: 6px; }
.study-director-select select { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.study-director-note { flex-basis: 100%; font-size: 12px; margin: 0; }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 999; padding: 20px; }
.modal-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; width: min(420px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,0.4); }
.signature-modal { width: min(700px, 100%); }
.signature-canvas { width: 100%; border: 1px dashed var(--border); border-radius: 8px; background: #fff; }
.signature-actions { display: flex; gap: 10px; margin-top: 8px; }
.signature-field { display: flex; flex-direction: column; gap: 6px; }
.modal-header { font-size: 18px; font-weight: 600; padding: 16px; border-bottom: 1px solid var(--border); }
.modal-form { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.modal-field input, .modal-field textarea { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.modal-field textarea { min-height: 80px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.btn.icon { padding: 0 12px; min-width: 38px; font-size: 20px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.ms-note { font-size: 12px; color: var(--muted); }
.ms-array { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.ms-array-items { display: flex; flex-direction: column; gap: 12px; }
.ms-array-item { border: 1px dashed var(--border); border-radius: 10px; padding: 12px; background: var(--surface); }
.ms-array-item-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.ms-array-item-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.ms-array-item-title { font-weight: 600; font-size: 14px; }
.ms-step { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; cursor: pointer; font-size: 13px; background: var(--btnBg); color: var(--text); }
.ms-step.active { background: var(--accent); color: var(--btnPrimaryText); border-color: var(--accent); }
.ms-step.done { border-color: var(--accent); color: var(--accent); }
.ms-step .step-num { font-weight: 600; }
.ms-step .step-title { white-space: nowrap; }
.ms-status { font-size: 12px; color: var(--muted); margin-top: 6px; }
.ms-status.warn { color: #fbbf24; }
.ms-status.success { color: #4ade80; }
.ms-status.danger { color: #f87171; }
.ms-actions { justify-content: flex-end; }

/* ─────────────────────────────────────────────────────────────────────────────
   Residue Extraction Calendar Styles
   ───────────────────────────────────────────────────────────────────────────── */
.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.calendar-toolbar .title { margin: 0; }
.view-toggle { display: flex; gap: 8px; }

.calendar-legend {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--muted);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-item .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.legend-item .dot.explicit { background: #22c55e; }
.legend-item .dot.computed { background: #3b82f6; }
.legend-item .dot.suggested { background: #f59e0b; }

.calendar-container { background: var(--surface); border-radius: 12px; padding: 16px; border: 1px solid var(--border); }
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  gap: 8px;
}
.calendar-header h3 { min-width: 180px; text-align: center; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.calendar-day-header {
  text-align: center;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}
.calendar-cell {
  min-height: 80px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  background: var(--bg);
}
.calendar-cell:hover { border-color: var(--accent); background: rgba(59, 130, 246, 0.05); }
.calendar-cell.empty { background: transparent; border-color: transparent; cursor: default; }
.calendar-cell.empty:hover { background: transparent; border-color: transparent; }
.calendar-cell.today { border-color: var(--accent); background: rgba(59, 130, 246, 0.1); }
.calendar-cell.past { opacity: 0.6; }
.calendar-cell.has-events { border-left: 3px solid #22c55e; }

.calendar-day-num {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}
.event-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}
.event-item {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: 10px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
}
.event-item .event-dot {
  width: 8px;
  height: 8px;
  min-width: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.event-item.explicit .event-dot { background: #22c55e; }
.event-item.computed .event-dot { background: #3b82f6; }
.event-item.suggested .event-dot { background: #f59e0b; }
.event-label {
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.event-more { font-size: 9px; color: var(--muted); margin-top: 2px; }

/* Calendar detail modal */
.calendar-detail { max-width: 600px; max-height: 80vh; overflow-y: auto; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 { margin: 0; }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 16px; }

.event-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.event-card.suggested { border-left: 3px solid #f59e0b; }
.event-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.event-card-header strong { font-size: 15px; }

.badge {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge.explicit { background: #22c55e; color: white; }
.badge.computed { background: #3b82f6; color: white; }
.badge.suggested { background: #f59e0b; color: white; }

.event-details {
  font-size: 13px;
  width: 100%;
  border-collapse: collapse;
}
.event-details td { padding: 4px 8px; }
.event-details td:first-child { color: var(--muted); width: 100px; }

/* List view */
.calendar-list-view { background: var(--surface); border-radius: 12px; padding: 16px; border: 1px solid var(--border); }
.calendar-list-view h3 { margin: 0 0 12px 0; font-size: 16px; }
.calendar-list-view .table { width: 100%; }
.calendar-list-view tr.suggested { background: rgba(245, 158, 11, 0.1); }
.calendar-list-view details { margin-top: 12px; }
.calendar-list-view summary { cursor: pointer; color: var(--muted); font-size: 13px; }

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

/* Modal overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  max-width: 90vw;
}