:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-hover: #f1f5f9;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --red: #ef4444;
  --red-hover: #dc2626;
  --dark: #0f172a;
  --green: #10b981;
  --green-bg: #d1fae5;
  --green-text: #065f46;
  --amber: #f59e0b;
  --amber-bg: #fef3c7;
  --amber-text: #92400e;
  --red-bg: #fee2e2;
  --red-text: #991b1b;
  --blue: #3b82f6;
  --blue-bg: #dbeafe;
  --blue-text: #1e40af;
  --brand-primary: #ef2029;
  --brand-primary-alpha: rgba(239, 32, 41, 0.12);
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.06), 0 4px 6px -2px rgba(0, 0, 0, 0.02);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font: 'Outfit', sans-serif;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme Variables */
document, html.dark {
  --bg: #090d12;
  --panel: #121824;
  --panel-hover: #1e293b;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --line: #1e293b;
  --red-hover: #f87171;
  --green-bg: rgba(16, 185, 129, 0.15);
  --green-text: #34d399;
  --amber-bg: rgba(245, 158, 11, 0.15);
  --amber-text: #fbbf24;
  --red-bg: rgba(239, 68, 68, 0.15);
  --red-text: #fca5a5;
  --blue-bg: rgba(59, 130, 246, 0.15);
  --blue-text: #60a5fa;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
}

a {
  color: inherit;
  text-decoration: none;
  transition: var(--transition);
}

/* Shell Layout */
.shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.side {
  background: var(--dark);
  color: #ffffff;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  z-index: 10;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 36px;
  padding: 0 8px;
}

.brand img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px var(--brand-primary-alpha));
}

.brand strong {
  display: block;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.brand span {
  color: #94a3b8;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav a {
  display: flex;
  align-items: center;
  color: #94a3b8;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #ffffff;
  transform: translateX(4px);
}

.nav a.active {
  background: var(--brand-primary-alpha);
  color: #ffffff;
  border-left: 3px solid var(--brand-primary);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-weight: 600;
}

/* Main Content Area */
.main {
  padding: 32px;
  overflow-y: auto;
}

/* Header Top */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.top h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Dark Mode Toggle Button */
.btn-theme {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  cursor: pointer;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.btn-theme:hover {
  background: var(--panel-hover);
  transform: translateY(-1px);
}

.btn-theme svg {
  width: 20px;
  height: 20px;
}

.sun-icon { display: none; }
.moon-icon { display: block; }

.dark .sun-icon { display: block; }
.dark .moon-icon { display: none; }

/* Grid Systems */
.grid {
  display: grid;
  gap: 20px;
}

.grid.cards {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

/* Cards & Stats */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.stat {
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.stat::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--blue);
}

.grid.cards > .card:nth-child(1)::after { background: var(--blue); }
.grid.cards > .card:nth-child(2)::after { background: var(--green); }
.grid.cards > .card:nth-child(3)::after { background: var(--amber); }
.grid.cards > .card:nth-child(4)::after { background: var(--brand-primary); }

.stat b {
  display: block;
  font-size: 32px;
  font-weight: 700;
  margin: 8px 0;
  color: var(--ink);
  letter-spacing: -1px;
}

.report-cards {
  margin-top: 14px;
}

.filter-bar {
  display: grid;
  grid-template-columns: 1.1fr 1.2fr 1fr 1fr auto auto auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 20px;
}

.filter-bar label {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.filter-chip {
  align-self: center;
  justify-self: end;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 13px;
  background: var(--panel-hover);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric {
  display: grid;
  gap: 8px;
}

.metric b {
  font-size: 28px;
  line-height: 1;
}

.metric small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--panel-hover);
}

.bar span {
  display: block;
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: var(--blue);
}

.bar.green span {
  background: var(--green);
}

.bar.amber span {
  background: var(--amber);
}

.bar.red span {
  background: var(--brand-primary);
}

.health-grid {
  grid-template-columns: 1fr 1fr 1fr;
}

.health-grid h3 {
  margin-bottom: 14px;
}

.stage-list {
  display: grid;
  gap: 10px;
}

.stage-list > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.stage-list > div:last-child {
  border-bottom: 0;
}

.stage-list strong {
  font-size: 18px;
}

.mini-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mini-grid > div {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
  background: var(--panel-hover);
}

.mini-grid b {
  display: block;
  font-size: 24px;
  margin-top: 4px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.project-report-grid,
.pipeline-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.project-report-card,
.pipeline-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--panel), var(--panel-hover));
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.project-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.project-card-head strong {
  font-size: 16px;
  line-height: 1.25;
}

.project-kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.project-kpis > div {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel);
  padding: 12px;
}

.project-kpis span,
.project-progress span,
.pipeline-mini span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.35px;
}

.project-kpis b {
  display: block;
  font-size: 28px;
  line-height: 1;
  margin-top: 6px;
}

.project-progress {
  display: grid;
  gap: 11px;
  margin-top: 16px;
}

.project-progress > div {
  display: grid;
  grid-template-columns: 72px 1fr 42px;
  gap: 10px;
  align-items: center;
}

.project-progress em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
  text-align: right;
}

.pipeline-strip {
  display: flex;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  margin-bottom: 16px;
}

.pipeline-strip span {
  min-width: 2px;
}

.pipeline-strip .blue { background: var(--blue); }
.pipeline-strip .amber { background: var(--amber); }
.pipeline-strip .green { background: var(--green); }
.pipeline-strip .red { background: var(--brand-primary); }

.pipeline-mini {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

.pipeline-mini span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 7px;
}

.pipeline-mini b {
  color: var(--ink);
  font-size: 13px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

/* Buttons */
.btn {
  border: 0;
  background: var(--brand-primary);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.btn:hover {
  background: var(--red-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn.secondary {
  background: var(--dark);
}

.btn.secondary:hover {
  background: #1e293b;
}

.btn.light {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn.light:hover {
  background: var(--panel-hover);
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  overflow: hidden;
}

th, td {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
  vertical-align: middle;
}

th {
  background: var(--panel-hover);
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
}

tr:last-child td {
  border-bottom: 0;
}

tr {
  transition: var(--transition);
}

tbody tr:hover {
  background: var(--panel-hover);
}

/* Form Controls */
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-family: var(--font);
  font-size: 14px;
  background: var(--panel);
  color: var(--ink);
  transition: var(--transition);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

textarea {
  min-height: 120px;
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-full {
  grid-column: 1 / -1;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--blue-bg);
  color: var(--blue-text);
}

.badge.green, .badge.visit_confirmed, .badge.visit_done {
  background: var(--green-bg);
  color: var(--green-text);
}

.badge.amber, .badge.interested, .badge.visit_scheduled {
  background: var(--amber-bg);
  color: var(--amber-text);
}

.badge.red, .badge.lost, .badge.failed {
  background: var(--red-bg);
  color: var(--red-text);
}

/* Notifications & Notices */
.notice {
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--amber-bg);
  border: 1px solid var(--amber);
  color: var(--amber-text);
  margin-bottom: 20px;
  font-size: 14px;
  font-weight: 500;
}

/* Draft Option Box Styles */
.draft-options {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.draft-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  background: var(--panel);
  cursor: pointer;
  transition: var(--transition);
}

.draft-card:hover {
  border-color: var(--brand-primary);
  background: var(--panel-hover);
}

.draft-card input[type="radio"] {
  width: auto;
  margin-top: 4px;
}

/* Campaign Video & Preview Boxes */
.preview-box {
  border: 1px solid var(--line);
  background: var(--panel-hover);
  border-radius: var(--radius-md);
  padding: 16px;
}

#templatePreview {
  margin-top: 12px;
  color: var(--ink);
  display: grid;
  gap: 10px;
  max-width: 460px;
}

.video-preview {
  height: 180px;
  border-radius: var(--radius-md);
  color: #ffffff;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  display: grid;
  place-items: center;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.video-preview span {
  display: block;
  max-width: 90%;
  overflow-wrap: anywhere;
  font-size: 12px;
  font-weight: 400;
  color: #cbd5e1;
  text-align: center;
}

.quick-reply-preview {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--amber-text);
  padding: 12px;
  border-radius: var(--radius-md);
  font-weight: 600;
  text-align: center;
  cursor: default;
}

/* Responsiveness adjustments */
@media (max-width: 991px) {
  .shell {
    grid-template-columns: 1fr;
  }
  .side {
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 16px 20px;
  }
  .brand {
    margin-bottom: 16px;
  }
  .nav {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 8px;
  }
  .nav a {
    white-space: nowrap;
    padding: 8px 12px;
  }
  .nav a.active {
    border-left: none;
    border-bottom: 3px solid var(--brand-primary);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
  }
  .main {
    padding: 20px;
  }
  .grid.cards {
    grid-template-columns: 1fr 1fr;
  }
  .health-grid {
    grid-template-columns: 1fr;
  }
  .filter-bar {
    grid-template-columns: 1fr 1fr;
  }
  .filter-chip {
    justify-self: start;
  }
}

@media (max-width: 580px) {
  .grid.cards {
    grid-template-columns: 1fr;
  }
  .filter-bar,
  .form-grid {
    grid-template-columns: 1fr;
  }
  .top {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .top-actions {
    width: 100%;
    justify-content: flex-end;
  }
}
