/* =========================================================
   Capture Digital Marketing Client Portal
   Brand palette from larry-media/brand/visual-voice.md
   ========================================================= */

:root {
  /* Brand colors */
  --coral:        #E94C24;
  --coral-dark:   #D04B27;
  --coral-pale:   #FDF0ED;
  --navy:         #111832;
  --navy-deep:    #0A0F1C;
  --azure:        #1E92FF;
  --azure-muted:  #1E73BE;
  --white:        #FFFFFF;
  --mist:         #EFF4F7;
  --gray-light:   #F5F5F5;
  --gray-mid:     #898989;

  /* Semantic tokens */
  --bg:           var(--mist);
  --surface:      var(--white);
  --border:       #DDE3EA;
  --text:         var(--navy);
  --text-muted:   var(--gray-mid);
  --accent:       var(--coral);
  --accent-hover: var(--coral-dark);
  --focus-ring:   rgba(233, 76, 36, 0.35);

  /* Type */
  --font:         'Inter', system-ui, sans-serif;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow-sm:    0 1px 3px rgba(17,24,50,.07), 0 1px 2px rgba(17,24,50,.05);
  --shadow:       0 4px 16px rgba(17,24,50,.10), 0 2px 6px rgba(17,24,50,.06);
  --shadow-lg:    0 8px 32px rgba(17,24,50,.14), 0 4px 12px rgba(17,24,50,.08);

  /* Transitions */
  --t:            150ms ease;
}

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

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---- Utility ---- */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

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

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  font: 600 14px/1 var(--font);
  transition: background var(--t), opacity var(--t);
}
.btn-primary {
  background: var(--coral); color: var(--white);
}
.btn-primary:hover { background: var(--coral-dark); }
.btn-secondary {
  background: var(--surface); color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { background: var(--gray-light); }
.btn-ghost {
  background: transparent; color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); background: var(--gray-light); }
.btn-danger {
  background: transparent; color: var(--coral);
  border: 1.5px solid var(--coral);
}
.btn-danger:hover { background: var(--coral-pale); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---- Form controls ---- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font: 600 13px/1 var(--font); color: var(--text);
}
.field input, .field select, .field textarea {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font: 400 14px/1.4 var(--font);
  color: var(--text);
  background: var(--white);
  transition: border-color var(--t), box-shadow var(--t);
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--coral);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.field-hint {
  font: 400 12px/1.4 var(--font); color: var(--text-muted);
}

/* ---- Card ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

/* ---- Badge ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font: 600 11px/1.6 var(--font);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.badge-active  { background: #E3F8E8; color: #1A7A34; }
.badge-queued  { background: #FFF6E3; color: #8A5A00; }
.badge-running { background: #E8F0FF; color: #1845A8; }
.badge-ready   { background: #E3F8E8; color: #1A7A34; }
.badge-failed  { background: #FDE8E3; color: #A81818; }
.badge-published { background: #E8F0FF; color: #1845A8; }
.badge-staff   { background: var(--navy); color: var(--white); }
.badge-client  { background: var(--coral-pale); color: var(--coral-dark); }

/* ---- Layout shell ---- */
#app { min-height: 100vh; }

/* ---- Login screen ---- */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--navy-deep) 0%, var(--navy) 60%, #1d2a50 100%);
}
.login-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  display: flex; align-items: center; gap: 10px; margin-bottom: 28px;
}
.login-logo-mark {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--coral); display: flex; align-items: center; justify-content: center;
  font: 700 18px/1 var(--font); color: var(--white); flex-shrink: 0;
}
.login-logo-text { font: 700 16px/1.2 var(--font); color: var(--navy); }
.login-logo-text span { display: block; font: 400 12px/1 var(--font); color: var(--text-muted); }
.login-heading { font: 700 22px/1.2 var(--font); color: var(--navy); margin-bottom: 6px; }
.login-sub { font: 400 14px/1.5 var(--font); color: var(--text-muted); margin-bottom: 24px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-error {
  background: var(--coral-pale); color: var(--coral-dark);
  border-radius: var(--radius-sm); padding: 10px 12px;
  font: 400 13px/1.4 var(--font);
}

/* ---- App shell (post-login) ---- */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--navy);
  display: flex; flex-direction: column;
  padding: 0;
  color: var(--white);
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo-mark {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--coral); display: flex; align-items: center; justify-content: center;
  font: 700 14px/1 var(--font); color: var(--white); flex-shrink: 0;
}
.sidebar-logo-text { font: 700 13px/1.3 var(--font); color: var(--white); }
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-section-label {
  padding: 10px 16px 4px;
  font: 600 10px/1 var(--font); letter-spacing: .08em; text-transform: uppercase;
  color: rgba(255,255,255,.35);
}
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 16px;
  cursor: pointer;
  font: 500 13px/1 var(--font); color: rgba(255,255,255,.7);
  border-radius: 0;
  transition: background var(--t), color var(--t);
  border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: var(--white); }
.nav-item.active { background: rgba(233,76,36,.25); color: var(--white); }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-user {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px;
}
.sidebar-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--coral-pale); color: var(--coral-dark);
  display: flex; align-items: center; justify-content: center;
  font: 700 12px/1 var(--font); flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font: 600 12px/1 var(--font); color: var(--white);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-role { font: 400 11px/1 var(--font); color: rgba(255,255,255,.45); }

/* ---- Main content area ---- */
.main-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.main-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.main-header-title { font: 700 18px/1.2 var(--font); color: var(--navy); }
.main-header-sub { font: 400 13px/1 var(--font); color: var(--text-muted); margin-top: 2px; }
.main-body { flex: 1; padding: 24px; }

/* ---- Staff client switcher ---- */
.client-switcher {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: rgba(233,76,36,.1);
  border-bottom: 1px solid rgba(233,76,36,.2);
  font: 400 13px/1 var(--font); color: var(--navy);
  flex-shrink: 0;
}
.client-switcher label { font-weight: 600; color: var(--coral-dark); }
.client-switcher select {
  padding: 4px 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); font: 400 13px/1 var(--font);
  background: var(--white); color: var(--navy); cursor: pointer;
}

/* ---- Edit workspace (chat + preview side by side) ---- */
.workspace {
  display: flex; gap: 0; height: 100%; overflow: hidden;
}
.chat-panel {
  width: 380px; flex-shrink: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.chat-msg { display: flex; flex-direction: column; gap: 4px; max-width: 90%; }
.chat-msg-user { align-self: flex-end; }
.chat-msg-agent { align-self: flex-start; }
.chat-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font: 400 14px/1.5 var(--font);
}
.chat-msg-user .chat-bubble {
  background: var(--coral); color: var(--white);
  border-bottom-right-radius: 4px;
}
.chat-msg-agent .chat-bubble {
  background: var(--gray-light); color: var(--navy);
  border-bottom-left-radius: 4px;
}
.chat-msg-agent .chat-bubble.streaming::after {
  content: '...'; animation: blink 1s steps(3, end) infinite;
  display: inline-block; width: 1.2em;
}
@keyframes blink { 0%,100%{opacity:0} 50%{opacity:1} }
.chat-ts {
  font: 400 11px/1 var(--font); color: var(--text-muted);
  padding: 0 4px;
}
.chat-edit-badge {
  align-self: flex-start;
  background: var(--azure); color: var(--white);
  padding: 4px 10px; border-radius: 999px;
  font: 600 11px/1 var(--font);
}
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: flex-end;
}
.chat-input-area textarea {
  flex: 1; resize: none;
  padding: 8px 12px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font: 400 14px/1.5 var(--font); color: var(--text);
  background: var(--white); outline: none;
  min-height: 40px; max-height: 120px;
  transition: border-color var(--t), box-shadow var(--t);
}
.chat-input-area textarea:focus {
  border-color: var(--coral); box-shadow: 0 0 0 3px var(--focus-ring);
}
.chat-input-area textarea:disabled { background: var(--gray-light); }

/* ---- Preview panel ---- */
.preview-panel {
  flex: 1; display: flex; flex-direction: column;
  background: var(--gray-light);
  overflow: hidden;
}
.preview-toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.preview-toolbar-section {
  display: flex; align-items: center; gap: 4px;
}
.preview-toolbar-divider {
  width: 1px; height: 20px; background: var(--border); margin: 0 4px;
}
.preview-device-btn {
  padding: 5px 10px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--white);
  font: 500 12px/1 var(--font); color: var(--text-muted); cursor: pointer;
  transition: all var(--t);
}
.preview-device-btn.active {
  background: var(--navy); color: var(--white); border-color: var(--navy);
}
.preview-toggle-btn {
  padding: 5px 10px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--white);
  font: 500 12px/1 var(--font); color: var(--text-muted); cursor: pointer;
  transition: all var(--t);
}
.preview-toggle-btn.active {
  background: var(--coral); color: var(--white); border-color: var(--coral);
}
.preview-url {
  flex: 1; min-width: 0;
  font: 400 12px/1 var(--font); color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.preview-viewport {
  flex: 1; display: flex; align-items: flex-start; justify-content: center;
  padding: 16px; overflow: auto;
}
.preview-frame-wrap {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: width var(--t);
  height: 100%;
  max-height: calc(100vh - 200px);
}
.preview-frame-wrap.device-desktop { width: 100%; max-width: 1200px; }
.preview-frame-wrap.device-tablet  { width: 768px; }
.preview-frame-wrap.device-phone   { width: 390px; }
.preview-frame {
  width: 100%; height: 100%;
  border: none; display: block;
}
.preview-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: var(--text-muted);
}
.preview-empty-icon {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--coral-pale); display: flex; align-items: center; justify-content: center;
}
.preview-empty-icon svg { width: 28px; height: 28px; stroke: var(--coral); }
.preview-empty h3 { font: 600 16px/1.3 var(--font); color: var(--navy); }
.preview-empty p { font: 400 13px/1.5 var(--font); color: var(--text-muted); text-align: center; max-width: 240px; }

/* ---- Change summary + diff ---- */
.change-summary {
  margin: 0; padding: 12px 16px;
  background: var(--coral-pale);
  border-top: 1px solid rgba(233,76,36,.2);
  flex-shrink: 0;
}
.change-summary-text { font: 400 13px/1.5 var(--font); color: var(--navy); }
.diff-toggle-btn {
  background: none; border: none; cursor: pointer;
  font: 600 12px/1 var(--font); color: var(--coral);
  padding: 0; margin-top: 6px; display: block;
}
.diff-block {
  background: var(--navy-deep); color: #A8C4E0;
  padding: 12px 16px; border-radius: var(--radius-sm);
  font: 400 12px/1.6 monospace; white-space: pre-wrap;
  max-height: 200px; overflow-y: auto; margin-top: 8px;
}
.diff-line-add  { color: #7BDB87; }
.diff-line-rm   { color: #FF7575; }
.diff-line-meta { color: var(--text-muted); }

/* ---- Publish bar ---- */
.publish-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface); border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.publish-bar-status { font: 400 13px/1 var(--font); color: var(--text-muted); }
.publish-bar-actions { display: flex; gap: 8px; }

/* ---- History view ---- */
.history-list { display: flex; flex-direction: column; gap: 12px; }
.history-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
  display: flex; align-items: flex-start; gap: 14px;
}
.history-item-icon {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--coral-pale); display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.history-item-icon svg { width: 18px; height: 18px; stroke: var(--coral); }
.history-item-content { flex: 1; min-width: 0; }
.history-item-summary { font: 500 14px/1.4 var(--font); color: var(--navy); margin-bottom: 4px; }
.history-item-meta { font: 400 12px/1 var(--font); color: var(--text-muted); }
.history-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ---- Admin area ---- */
.admin-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px; margin-bottom: 28px;
}
.admin-card-title {
  font: 700 14px/1 var(--font); color: var(--navy); margin-bottom: 4px;
}
.admin-card-sub {
  font: 400 12px/1.5 var(--font); color: var(--text-muted); margin-bottom: 14px;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font: 400 13px/1.4 var(--font); }
thead tr { background: var(--mist); }
th {
  padding: 10px 14px; text-align: left;
  font: 600 12px/1 var(--font); color: var(--text-muted);
  letter-spacing: .04em; text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 10px 14px; color: var(--text);
  border-bottom: 1px solid var(--border);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--mist); }

/* ---- Audit log ---- */
.audit-entry {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.audit-entry:last-child { border-bottom: none; }
.audit-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--coral); flex-shrink: 0; margin-top: 5px;
}
.audit-action { font: 600 13px/1 var(--font); color: var(--navy); }
.audit-detail { font: 400 12px/1.4 var(--font); color: var(--text-muted); margin-top: 2px; }
.audit-time { font: 400 11px/1 var(--font); color: var(--text-muted); margin-left: auto; flex-shrink: 0; }

/* ---- Error banner ---- */
.error-banner {
  background: var(--coral-pale); color: var(--coral-dark);
  padding: 10px 20px;
  font: 400 13px/1.4 var(--font);
  border-bottom: 1px solid rgba(233,76,36,.25);
}

/* ---- Loading spinner ---- */
.spinner {
  width: 22px; height: 22px;
  border: 3px solid rgba(233,76,36,.2);
  border-top-color: var(--coral);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Empty state ---- */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding: 48px 24px; text-align: center;
}
.empty-state h3 { font: 600 16px/1.3 var(--font); color: var(--navy); }
.empty-state p { font: 400 13px/1.5 var(--font); color: var(--text-muted); max-width: 280px; }

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .workspace { flex-direction: column; }
  .chat-panel { width: 100%; height: 45vh; border-right: none; border-bottom: 1px solid var(--border); }
  .preview-panel { flex: 1; }
}
@media (max-width: 640px) {
  .sidebar { display: none; }
  .preview-frame-wrap.device-tablet,
  .preview-frame-wrap.device-phone { width: 100%; }
}
