/* ============================================
   Design System & Variables
   ============================================ */
:root {
  color-scheme: light dark;

  /* Colors */
  --text: #0f172a;
  --muted: #475569;
  --line: #e2e8f0;
  --panel: #ffffff;
  --surface: #f8fafc;
  --accent: #0d9488;
  --accent-dark: #0f766e;
  --accent-light: #ccfbf1;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --error: #dc2626;
  --error-bg: #fef2f2;
  --success: #059669;
  --success-bg: #ecfdf5;
  --info: #2563eb;
  --info-bg: #eff6ff;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.04);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.06), 0 2px 4px -2px rgb(0 0 0 / 0.04);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.04);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.08), 0 8px 10px -6px rgb(0 0 0 / 0.04);

  /* Radii */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Z-index scale */
  --z-dropdown: 20;
  --z-sticky: 30;
  --z-modal: 50;
  --z-toast: 100;

  /* Transitions */
  --transition-fast: 0.12s ease;
  --transition-base: 0.2s ease;
  --transition-slow: 0.35s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #f1f5f9;
    --muted: #94a3b8;
    --line: #334155;
    --panel: #1e293b;
    --surface: #0f172a;
    --accent: #2dd4bf;
    --accent-dark: #14b8a6;
    --accent-light: #115e59;
    --warn: #fbbf24;
    --warn-bg: #451a03;
    --error: #f87171;
    --error-bg: #450a0a;
    --success: #34d399;
    --success-bg: #064e3b;
    --info: #60a5fa;
    --info-bg: #1e3a8a;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.25), 0 2px 4px -2px rgb(0 0 0 / 0.2);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.25);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.35), 0 8px 10px -6px rgb(0 0 0 / 0.3);
  }
}

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--surface);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg, video { max-width: 100%; height: auto; }

/* Custom scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ============================================
   Layout & Typography
   ============================================ */
main {
  width: min(1020px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 24px 0 56px;
}

header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
  margin-bottom: 24px;
}

h1 { margin: 0 0 6px; font-size: 26px; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
h2 { margin: 0 0 14px; font-size: 17px; line-height: 1.35; font-weight: 600; }
h3 {
  margin: 18px 0 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.4;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

p { margin: 0; color: var(--muted); line-height: 1.7; font-size: 14px; }

/* ============================================
   Cards & Sections
   ============================================ */
section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base);
}
section:hover { box-shadow: var(--shadow); }

/* ============================================
   Forms
   ============================================ */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--panel);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.6; }
input:disabled, select:disabled, textarea:disabled { opacity: 0.5; cursor: not-allowed; }

textarea { min-height: 120px; resize: vertical; line-height: 1.65; padding: 12px; }

/* ============================================
   Buttons
   ============================================ */
button {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-width: 120px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast);
}

button:hover { background: var(--accent-dark); }
button:active { transform: scale(0.97); }
button:disabled { cursor: not-allowed; opacity: .55; transform: none; }
button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-light), 0 0 0 5px var(--accent);
}

.secondary { background: var(--muted); }
.secondary:hover { background: var(--text); }
.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.ghost:hover { background: var(--surface); }

/* Button loading state */
button.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
button.is-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ============================================
   Utility Classes
   ============================================ */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.break-word { overflow-wrap: anywhere; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ============================================
   Components
   ============================================ */
.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
}

.pill {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.pill:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.pill.ok { color: var(--success); border-color: var(--success); background: var(--success-bg); }
.pill.warn { color: var(--warn); border-color: var(--warn); background: var(--warn-bg); }
.pill.credit { color: var(--info); border-color: var(--info); background: var(--info-bg); }

.field { margin-bottom: 14px; }
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}
.check input { width: auto; accent-color: var(--accent); }

pre {
  margin: 16px 0 0;
  padding: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-height: 80px;
  font-size: 13px;
  line-height: 1.65;
  font-family: var(--font-mono);
  overflow-x: auto;
}

.note {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}

.save-status, .auth-status {
  margin: 12px 0 0;
  min-height: 22px;
  color: var(--muted);
  font-size: 14px;
}

/* ============================================
   Auth
   ============================================ */
.auth-shell {
  min-height: 70vh;
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(440px, 100%);
  animation: fadeInUp var(--transition-slow) ease;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}
.tabs button { min-width: 0; }
.tabs button[aria-selected="false"] {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

/* ============================================
   Panels & Tabs
   ============================================ */
.panel-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 8px;
  margin: 0 0 18px;
}
.panel-tabs button {
  min-width: 0;
  padding-inline: 10px;
  font-size: 13px;
}
.panel-tabs button[aria-selected="false"] {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.account-summary {
  display: grid;
  gap: 10px;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.account-title {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
  color: var(--text);
  font-size: 15px;
}

.account-list {
  display: grid;
  gap: 8px;
  margin: 10px 0 16px;
}

.account-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: background var(--transition-fast), transform var(--transition-fast);
}
.account-item:hover { background: var(--panel); transform: translateY(-1px); }
.account-item strong {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  color: var(--text);
}
.account-item small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.config-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
  gap: 8px;
  margin: 10px 0 16px;
}
.config-tabs button {
  min-width: 0;
  padding: 8px 10px;
  font-size: 13px;
}
.config-tabs button[aria-selected="false"] {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

[data-config-group][hidden] { display: none; }
.admin-only[hidden], .settings-section[hidden] { display: none; }

/* ============================================
   Admin / User Management
   ============================================ */
.user-table { display: grid; gap: 10px; }
.user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px 116px;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  transition: background var(--transition-fast);
}
.user-row:hover { background: var(--surface); }

.code-table { display: grid; gap: 10px; margin-top: 14px; }
.code-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) 90px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
}

.code-value {
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.user-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 600;
  font-size: 14px;
}

.system-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 7px;
  border: 1px solid var(--success);
  border-radius: 6px;
  background: var(--success-bg);
  color: var(--success);
  font-size: 11px;
  font-weight: 600;
  vertical-align: middle;
}

.user-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

/* ============================================
   Menu / Dropdown
   ============================================ */
.menu { position: relative; }

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: min(780px, calc(100vw - 28px));
  max-height: min(78vh, 760px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  animation: fadeIn var(--transition-base) ease;
}

.menu-panel[hidden], .app[hidden], .auth-shell[hidden] { display: none; }

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 220px;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow-lg);
  animation: toastIn var(--transition-base) ease;
  display: flex;
  align-items: center;
  gap: 10px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.toast::before {
  content: '';
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.toast.toast-success {
  background: rgba(5, 150, 105, 0.92);
  border: 1px solid rgba(5, 150, 105, 0.3);
}
.toast.toast-success::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='white'%3E%3Cpath fill-rule='evenodd' d='M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z' clip-rule='evenodd'/%3E%3C/svg%3E");
}

.toast.toast-error {
  background: rgba(220, 38, 38, 0.92);
  border: 1px solid rgba(220, 38, 38, 0.3);
}
.toast.toast-error::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='white'%3E%3Cpath fill-rule='evenodd' d='M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z' clip-rule='evenodd'/%3E%3C/svg%3E");
}

.toast.toast-info {
  background: rgba(37, 99, 235, 0.92);
  border: 1px solid rgba(37, 99, 235, 0.3);
}
.toast.toast-info::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='white'%3E%3Cpath fill-rule='evenodd' d='M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z' clip-rule='evenodd'/%3E%3C/svg%3E");
}

.toast.toast-warn {
  background: rgba(217, 119, 6, 0.92);
  border: 1px solid rgba(217, 119, 6, 0.3);
}
.toast.toast-warn::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='white'%3E%3Cpath fill-rule='evenodd' d='M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z' clip-rule='evenodd'/%3E%3C/svg%3E");
}

.toast-exit { animation: toastOut var(--transition-fast) ease forwards; }

/* ============================================
   Task / Production Board
   ============================================ */
.production-board { display: grid; gap: 20px; }

.task-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.task-column, .task-detail {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  min-width: 0;
}

.task-column { overflow: hidden; }

.task-toolbar, .task-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.task-toolbar strong, .task-detail-title {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.task-toolbar button, .task-actions button {
  min-width: 0;
  padding: 7px 11px;
  font-size: 13px;
}

.task-list {
  display: grid;
  gap: 0;
  max-height: 640px;
  overflow: auto;
}

.task-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  min-width: 0;
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
}

.task-row:hover, .task-row.active {
  background: var(--surface);
  color: var(--text);
  transform: none;
}
.task-row.active {
  box-shadow: inset 3px 0 0 var(--accent);
}
.task-row:focus-visible {
  outline: none;
  box-shadow: inset 3px 0 0 var(--accent), 0 0 0 2px var(--accent-light);
}

.task-row-main { min-width: 0; }

.task-row-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.task-row-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  color: var(--muted);
  background: var(--panel);
}

.status-badge.queued, .status-badge.running, .status-badge.publishing {
  color: var(--info);
  border-color: var(--info);
  background: var(--info-bg);
}
.status-badge.review, .status-badge.approved {
  color: var(--warn);
  border-color: var(--warn);
  background: var(--warn-bg);
}
.status-badge.published {
  color: var(--success);
  border-color: var(--success);
  background: var(--success-bg);
}
.status-badge.failed {
  color: var(--error);
  border-color: var(--error);
  background: var(--error-bg);
}

/* Status badge dot */
.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  margin-right: 5px;
  flex-shrink: 0;
}

.mode-control {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.mode-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  cursor: pointer;
  color: var(--text);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.mode-option:hover { border-color: var(--accent); }
.mode-option:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.mode-option input {
  width: auto;
  margin-top: 3px;
  accent-color: var(--accent);
}

.mode-option strong {
  display: block;
  font-size: 13px;
  line-height: 1.4;
}

.mode-option span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.task-detail-body {
  padding: 16px;
  min-height: 360px;
}

.task-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 0;
}

.task-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  background: var(--surface);
  min-width: 0;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.metric:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.metric strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.article-preview {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 14px;
  max-height: 420px;
  overflow: auto;
  font-size: 13px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.review-editor {
  display: grid;
  gap: 12px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 14px;
}

.review-editor .field { margin-bottom: 0; }

.review-body {
  min-height: 360px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
}

.review-note { min-height: 76px; }

.review-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.review-toolbar button {
  min-width: 0;
  padding: 7px 11px;
  font-size: 13px;
}

.review-version {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.source-list, .event-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.source-item, .event-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  background: var(--panel);
  font-size: 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  transition: border-color var(--transition-fast), transform var(--transition-fast);
}
.source-item:hover, .event-item:hover {
  border-color: var(--accent);
  transform: translateX(2px);
}

.source-item a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.source-item a:hover { text-decoration: underline; }

/* ============================================
   Operations & Calendar
   ============================================ */
.ops-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.ops-alerts-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.ops-alert-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.ops-alert-stat {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  padding: 9px 10px;
  min-width: 0;
}

.ops-alert-stat span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.ops-alert-stat strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 17px;
  line-height: 1.2;
}

.ops-alert-list {
  display: grid;
  gap: 8px;
  padding: 16px;
  max-height: 360px;
  overflow: auto;
}

.ops-alert-item {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  padding: 10px 12px;
  text-align: left;
  min-width: 0;
}

.ops-alert-item:hover {
  background: var(--surface);
  color: var(--text);
  transform: none;
  border-color: var(--accent);
}

.ops-alert-item.danger { border-color: var(--error); background: var(--error-bg); }
.ops-alert-item.warn { border-color: var(--warn); background: var(--warn-bg); }
.ops-alert-item.info { border-color: var(--info); background: var(--info-bg); }

.ops-alert-label {
  border-radius: 999px;
  border: 1px solid currentColor;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.ops-alert-main {
  min-width: 0;
}

.ops-alert-title {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.ops-alert-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.ops-alert-time {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
}

.calendar-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.calendar-list {
  display: grid;
  gap: 10px;
  padding: 16px;
  max-height: 360px;
  overflow: auto;
}

.calendar-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.calendar-filters select {
  min-width: 0;
  font-size: 13px;
  padding: 8px 10px;
}

.calendar-day { display: grid; gap: 8px; }

.calendar-day-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.calendar-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.calendar-item:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }

.calendar-time {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.calendar-main { min-width: 0; }

.calendar-title {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.calendar-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.calendar-item button {
  min-width: 0;
  padding: 6px 10px;
  font-size: 12px;
}

.ops-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  min-width: 0;
  overflow: hidden;
}

.ops-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.ops-header strong {
  font-size: 14px;
  color: var(--text);
}

.ops-body { padding: 16px; }

.compact-form {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.compact-form textarea { min-height: 76px; }
.compact-form button { justify-self: end; }

.work-list {
  display: grid;
  gap: 8px;
  max-height: 420px;
  overflow: auto;
}

.work-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  padding: 10px 12px;
  min-width: 0;
  transition: border-color var(--transition-fast), transform var(--transition-fast);
}
.work-item:hover { border-color: var(--accent); transform: translateX(2px); }

.work-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  overflow-wrap: anywhere;
  line-height: 1.4;
}

.work-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.work-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.work-actions button {
  min-width: 0;
  padding: 6px 10px;
  font-size: 12px;
}

.risk-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.risk-item {
  border: 1px solid var(--warn);
  background: var(--warn-bg);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.schedule-box {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 14px;
}

.schedule-row {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.schedule-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.schedule-actions button {
  min-width: 0;
  padding: 7px 11px;
  font-size: 13px;
}

.event-meta {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  margin-bottom: 3px;
}

/* ============================================
   Empty State
   ============================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  padding: 32px 18px;
  font-size: 14px;
  line-height: 1.7;
  text-align: center;
}

.empty-state::before {
  content: '';
  width: 48px;
  height: 48px;
  background: var(--line);
  border-radius: var(--radius-lg);
  opacity: 0.6;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='1.5'%3E%3Cpath d='M9 12h.01M15 12h.01M10 16c.5.3 1.2.5 2 .5s1.5-.2 2-.5M22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10z'/%3E%3C/svg%3E") center/contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='1.5'%3E%3Cpath d='M9 12h.01M15 12h.01M10 16c.5.3 1.2.5 2 .5s1.5-.2 2-.5M22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10z'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* ============================================
   Spinner & Loading
   ============================================ */
.spinner {
  width: 16px;
  height: 16px;
  border: 2.5px solid rgba(128,128,128,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

/* ============================================
   Password Toggle
   ============================================ */
.password-field { position: relative; }

.password-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  min-width: 0;
  padding: 4px 8px;
  user-select: none;
}
.password-toggle:hover { color: var(--text); background: none; }

/* ============================================
   Skeleton
   ============================================ */
.skeleton {
  background: linear-gradient(90deg, var(--line) 25%, var(--surface) 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.4s ease infinite;
  border-radius: var(--radius-sm);
  height: 14px;
}

/* ============================================
   Animations
   ============================================ */
@keyframes spin { to { transform: rotate(360deg); } }

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

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

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

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(30px); }
}

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

@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.animate-pulse { animation: pulse 1.5s ease-in-out infinite; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}

/* ============================================
   Transition Utilities
   ============================================ */
.transition-fade {
  transition: opacity var(--transition-base), transform var(--transition-base);
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 720px) {
  main { width: min(100vw - 20px, 1020px); padding-top: 18px; }
  header { display: block; }
  .top-actions { justify-content: flex-start; margin-top: 14px; }
  .status { justify-content: flex-start; }
  h1 { font-size: 22px; }
  .field-row { grid-template-columns: 1fr; }
  .task-layout, .mode-control, .task-metrics, .ops-layout, .schedule-row, .calendar-item, .calendar-filters, .ops-alert-summary, .ops-alert-item { grid-template-columns: 1fr; }
  .panel-tabs, .user-row, .code-row { grid-template-columns: 1fr; }
  .menu-panel {
    position: fixed;
    inset: 8px;
    width: auto;
    max-height: none;
    border-radius: var(--radius);
    padding: 18px;
  }
  .toast-container { right: 10px; left: 10px; top: 10px; }
  .toast { max-width: 100%; }
}

/* Tablet breakpoint */
@media (min-width: 721px) and (max-width: 960px) {
  .task-layout { grid-template-columns: 280px minmax(0, 1fr); }
  .task-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calendar-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ops-alert-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ops-layout { grid-template-columns: 1fr; }
}
