/* =====================================================
 * Design System — overrides Bootstrap + adds new layer
 * ===================================================== */

:root {
  --brand:        #14B8A6;
  --brand-hover:  #0D9488;
  --brand-soft:   #CCFBF1;
  --brand-soft-2: #F0FDFA;

  --bg:            #F7F8FA;
  --surface:       #FFFFFF;
  --surface-2:     #FAFBFC;
  --border:        #E5E7EB;
  --border-strong: #D1D5DB;
  --text:          #111827;
  --text-2:        #6B7280;
  --text-3:        #9CA3AF;

  --amber:        #F59E0B;
  --amber-soft:   #FEF3C7;
  --indigo:       #6366F1;
  --indigo-soft:  #E0E7FF;
  --coral:        #F43F5E;
  --coral-soft:   #FFE4E6;
  --emerald:      #10B981;
  --emerald-soft: #D1FAE5;

  --shadow-sm: 0 1px 2px rgba(16,24,40,.04);
  --shadow-md: 0 4px 12px rgba(16,24,40,.06);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.10);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;

  /* Bootstrap variable overrides */
  --bs-primary:           #14B8A6;
  --bs-primary-rgb:       20,184,166;
  --bs-success:           #10B981;
  --bs-success-rgb:       16,185,129;
  --bs-warning:           #F59E0B;
  --bs-warning-rgb:       245,158,11;
  --bs-danger:            #F43F5E;
  --bs-danger-rgb:        244,63,94;
  --bs-body-bg:           #F7F8FA;
  --bs-body-color:        #111827;
  --bs-body-font-family:  'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  --bs-body-font-size:    0.875rem;
  --bs-border-color:      #E5E7EB;
  --bs-link-color:        #14B8A6;
  --bs-link-hover-color:  #0D9488;
  --bs-card-border-color: #E5E7EB;
  --bs-card-border-radius: 14px;
  --bs-secondary-color:   #6B7280;
  --bs-tertiary-color:    #9CA3AF;
  --bs-secondary-bg:      #FAFBFC;
}

html, body {
  font-family: 'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--bg);
  color: var(--text);
}

/* =====================================================
 * Sidebar
 * ===================================================== */

.sidebar {
  width: 260px;
  min-width: 260px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 14px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.sidebar-brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--brand) 0%, #0891B2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  font-size: 16px;
  box-shadow: 0 4px 10px rgba(20,184,166,.28);
}

.sidebar-brand-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  line-height: 1.2;
}

.sidebar-brand-sub {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 1px;
}

.sidebar-cta {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--brand);
  color: #fff !important;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  text-decoration: none !important;
  margin: 0 10px 8px;
  transition: .15s;
  box-shadow: 0 2px 6px rgba(20,184,166,.25);
}

.sidebar-cta:hover {
  background: var(--brand-hover);
  box-shadow: 0 4px 10px rgba(20,184,166,.35);
  transform: translateY(-1px);
}

.sidebar-section {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .6px;
  padding: 12px 14px 4px;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 1px 10px;
  border-radius: 7px;
  color: var(--text-2);
  font-weight: 500;
  font-size: 13.5px;
  text-decoration: none !important;
  transition: .12s;
}

.sidebar-nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar-nav-item.active {
  background: var(--brand-soft-2);
  color: var(--brand-hover);
  font-weight: 600;
}

.sidebar-nav-item i {
  width: 16px;
  flex-shrink: 0;
  font-size: 15px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 10px 14px;
  border-top: 1px solid var(--border);
}

.sidebar-lang {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 3px;
  gap: 3px;
  margin-bottom: 6px;
}

.sidebar-lang-btn {
  flex: 1;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-align: center;
  text-decoration: none !important;
  transition: .12s;
}

.sidebar-lang-btn:hover { color: var(--text); }

.sidebar-lang-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* =====================================================
 * Sidebar backdrop + mobile slide
 * ===================================================== */

#sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,.45);
  z-index: 1045;
  cursor: pointer;
}

#sidebar-backdrop.show { display: block; }
body.sidebar-open { overflow: hidden; }

@media (max-width: 767.98px) {
  .sidebar {
    position: fixed !important;
    top: 0 !important; left: 0 !important;
    width: 260px !important;
    min-width: 260px !important;
    height: 100vh !important;
    z-index: 1050 !important;
    transform: translateX(-260px) !important;
    transition: transform .28s ease !important;
  }
  .sidebar.show { transform: translateX(0) !important; }
  #wrapper { display: block !important; }
  #wrapper > div { width: 100% !important; min-width: 0 !important; overflow-x: hidden !important; }

  main { font-size: .9375rem !important; }
  h4, h5 { font-size: 1.0625rem !important; }
  main .btn:not(.btn-lg):not(.btn-sm) { min-height: 2.4rem; }
  main .btn-sm { min-height: 2rem; font-size: .875rem !important; }

  .btn-sm {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: .25rem;
  }
  .btn-sm > i {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1;
    margin-inline-end: 0 !important;
  }

  .brief-content { font-size: .82rem !important; line-height: 1.55 !important; }
  .brief-content h1 { font-size: 1.1rem !important; margin-top: 1.2rem !important; }
  .brief-content h2 { font-size: 1rem !important; margin-top: 1rem !important; }
  .brief-content h3 { font-size: .9rem !important; }
  .brief-content ul, .brief-content ol { padding-left: .85rem !important; }
}

/* =====================================================
 * Bootstrap component overrides
 * ===================================================== */

.card {
  border-color: var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  background: var(--surface);
  border-bottom-color: var(--border);
  font-weight: 600;
  font-size: .875rem;
}

.btn {
  font-weight: 600;
  letter-spacing: -.01em;
  border-radius: var(--radius-sm);
}

.btn-primary { background: var(--brand); border-color: var(--brand); }
.btn-primary:hover, .btn-primary:focus {
  background: var(--brand-hover); border-color: var(--brand-hover);
  box-shadow: 0 4px 12px rgba(20,184,166,.3);
}

.btn-outline-primary { color: var(--brand); border-color: var(--brand); }
.btn-outline-primary:hover { background: var(--brand); border-color: var(--brand); }

.btn-dark { background: #111827; border-color: #111827; }
.btn-dark:hover { background: #1F2937; border-color: #1F2937; }

.btn-outline-dark { color: var(--text); border-color: var(--border-strong); background: transparent; }
.btn-outline-dark:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }

.btn-outline-secondary { color: var(--text-2); border-color: var(--border); background: transparent; }
.btn-outline-secondary:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }

.form-control, .form-select {
  border-color: var(--border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:hover, .form-select:hover { border-color: var(--border-strong); }
.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(20,184,166,.15);
  background: var(--surface);
}
.form-label { font-weight: 500; font-size: .8125rem; color: var(--text); margin-bottom: 5px; }

.table {
  --bs-table-color: var(--text);
  --bs-table-border-color: var(--border);
}
.table-light {
  --bs-table-bg: var(--surface-2);
  --bs-table-color: var(--text-2);
}
.table thead th {
  font-weight: 600;
  font-size: .75rem;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.table-hover > tbody > tr:hover > * { background-color: #F0FDFA; }

.badge { font-weight: 600; font-size: .7rem; }

.page-link { color: var(--text-2); border-color: var(--border); }
.page-link:hover { color: var(--brand); background: var(--brand-soft-2); border-color: var(--border); }
.page-item.active .page-link { background: var(--brand); border-color: var(--brand); }

.alert-danger  { --bs-alert-bg: var(--coral-soft);   --bs-alert-border-color: #FECDD3; --bs-alert-color: #9F1239; }
.alert-success { --bs-alert-bg: var(--emerald-soft); --bs-alert-border-color: #A7F3D0; --bs-alert-color: #065F46; }
.alert-warning { --bs-alert-bg: var(--amber-soft);   --bs-alert-border-color: #FDE68A; --bs-alert-color: #92400E; }
.alert-info    { --bs-alert-bg: var(--indigo-soft);  --bs-alert-border-color: #C7D2FE; --bs-alert-color: #3730A3; }

.progress { border-radius: 4px; background: var(--surface-2); }
.progress-bar { background: var(--brand); }

/* =====================================================
 * KPI cards (dashboard stats)
 * ===================================================== */

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  transition: .18s;
  position: relative;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.kpi-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.kpi-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.kpi-icon.teal    { background: var(--brand-soft-2); color: var(--brand-hover); }
.kpi-icon.indigo  { background: var(--indigo-soft);  color: var(--indigo); }
.kpi-icon.emerald { background: var(--emerald-soft); color: var(--emerald); }
.kpi-icon.amber   { background: var(--amber-soft);   color: var(--amber); }
.kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -.5px; line-height: 1.1; color: var(--text); min-height: 1.6em; }
.kpi-label { font-size: 12.5px; color: var(--text-2); margin-top: 4px; }
.kpi-progress { margin-top: 12px; height: 5px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.kpi-progress-bar { height: 100%; background: var(--amber); border-radius: 4px; transition: width .6s; }

@media (max-width: 767.98px) {
  .kpi-value { font-size: 1.35rem !important; min-height: 1.6em !important; }
  .kpi-label { font-size: .68rem !important; }
}

/* =====================================================
 * Video table
 * ===================================================== */

.video-table { font-size: .875rem; }
.video-table th { cursor: pointer; user-select: none; white-space: nowrap; }
.video-table th:hover { background: var(--surface-2); }
.video-table .sort-indicator::after  { content: ' \25B2'; opacity: .3; }
.video-table .sort-asc  .sort-indicator::after { content: ' \25B2'; opacity: 1; }
.video-table .sort-desc .sort-indicator::after { content: ' \25BC'; opacity: 1; }
.video-table td { vertical-align: middle; }
.video-thumbnail { width: 60px; height: 34px; object-fit: cover; border-radius: 4px; }

/* =====================================================
 * Status badges
 * ===================================================== */

.badge-pending                          { background: var(--text-3); }
.badge-searching, .badge-ranking        { background: var(--indigo); }
.badge-processing, .badge-analyzing, .badge-briefing { background: var(--indigo); }
.badge-completed                        { background: var(--emerald); }
.badge-failed                           { background: var(--coral); }

/* =====================================================
 * Analysis cards
 * ===================================================== */

.analysis-section { border-left: 3px solid var(--brand); padding-left: 1rem; margin-bottom: 1.5rem; }
.analysis-card.brief-selectable:hover { box-shadow: 0 0 0 2px rgba(20,184,166,.3) !important; }

/* =====================================================
 * Director's Brief
 * ===================================================== */

.brief-content { line-height: 1.7; }
.brief-content h1 { font-size: 1.5rem; margin-top: 2rem; }
.brief-content h2 { font-size: 1.3rem; margin-top: 1.5rem; color: var(--brand-hover); }
.brief-content h3 { font-size: 1.1rem; margin-top: 1rem; }
.brief-content ul, .brief-content ol { padding-left: 1.5rem; }
.brief-content blockquote { border-left: 3px solid var(--border); padding-left: 1rem; color: var(--text-2); font-style: italic; }

/* =====================================================
 * Form section cards
 * ===================================================== */

.form-section {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.form-section h6 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* =====================================================
 * Extra-small icon buttons
 * ===================================================== */

.btn-xs {
  padding: 0 !important;
  width: 1.875rem !important;
  height: 1.875rem !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  line-height: 1 !important;
  font-size: .8125rem;
  border-radius: var(--radius-sm) !important;
}
.btn-xs > i { display: flex; align-items: center; justify-content: center; line-height: 1; }

@media (max-width: 767.98px) {
  .btn-xs { font-size: .75rem !important; }
}

/* =====================================================
 * Misc utilities
 * ===================================================== */

.cost-value { font-weight: 700; color: var(--emerald); }

.table-sortable th.sorted { background: var(--brand-soft-2); color: var(--brand-hover); }

.progress-animated .progress-bar { animation: progress-pulse 1.5s ease-in-out infinite; }
@keyframes progress-pulse { 0%,100%{opacity:1} 50%{opacity:.7} }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }

.text-brand { color: var(--brand) !important; }
.bg-brand-soft { background: var(--brand-soft-2) !important; }
