:root {
  --bg: #f7f2e8;
  --bg-2: #efe4d3;
  --ink: #1f2937;
  --ink-soft: #5b6472;
  --card: #fffdf8;
  --line: #d8cbb3;
  --primary: #0f4c5c;
  --primary-strong: #093946;
  --accent: #e36414;
  --ok: #1f8a5b;
  --watch: #c77900;
  --blocked: #b42222;
  --radius: 16px;
  --shadow: 0 10px 28px rgba(30, 24, 14, 0.14);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  background:
    radial-gradient(920px 500px at 8% -10%, rgba(227,100,20,0.16), transparent 60%),
    radial-gradient(1000px 560px at 100% 0%, rgba(15,76,92,0.18), transparent 62%),
    repeating-linear-gradient(135deg, transparent 0 14px, rgba(15,76,92,0.02) 14px 15px),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
}

a { color: var(--primary-strong); }

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(11, 47, 58, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
}

.topbar-inner {
  max-width: 1500px;
  margin: 0 auto;
  padding: 0.6rem 0.76rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand {
  color: #f8f2e8;
  font-size: 0.94rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
  margin-right: 0.4rem;
  border: 1px solid rgba(255,255,255,0.24);
  border-radius: 999px;
  padding: 0.3rem 0.62rem;
}

.nav-toggle {
  display: none;
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 0.36rem 0.62rem;
  cursor: pointer;
}

.shell-layout {
  width: 100%;
  margin: 0;
  padding: 52px 0 0;
  display: block;
}

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 250px;
  background: rgba(11, 47, 58, 0.92);
  border-right: 1px solid rgba(255,255,255,0.12);
  box-shadow: var(--shadow);
  padding: 0.75rem 0.6rem;
  backdrop-filter: blur(8px);
  overflow-y: auto;
  z-index: 120;
}

.sidebar-nav {
  display: grid;
  gap: 0.32rem;
}

.sidebar-brand {
  color: #f8f2e8;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
  border: 1px solid rgba(255,255,255,0.24);
  border-radius: 10px;
  padding: 0.48rem 0.62rem;
  margin-bottom: 0.58rem;
  background: rgba(255,255,255,0.06);
}

.sidebar-nav a {
  color: #deefe9;
  text-decoration: none;
  padding: 0.5rem 0.62rem;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 500;
  transition: 0.16s ease;
}

.sidebar-nav a:hover,
.sidebar-nav a:focus-visible {
  color: #fff;
  border-color: rgba(255,255,255,0.32);
  background: rgba(255,255,255,0.08);
}

.sidebar-nav a.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(227,100,20,0.28), rgba(15,76,92,0.52));
  border-color: rgba(255,255,255,0.3);
}

.main-content {
  margin-left: 250px;
  width: calc(100% - 250px);
  padding: 1rem;
  min-width: 0;
}

.sidebar-backdrop { display: none; }

@media (min-width: 721px) {
  .topbar { display: none !important; }
  .shell-layout { padding-top: 0 !important; }
  .nav-toggle { display: none !important; }
  .sidebar {
    display: block !important;
    transform: none !important;
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    width: 250px !important;
  }
  .sidebar-backdrop { display: none !important; }
}

body.layout-comfy .main-content {
  max-width: 1300px;
}

body.layout-wide .main-content {
  max-width: none;
}

.page-title {
  margin: 0 0 0.45rem;
  font-size: clamp(1.4rem, 2.2vw, 2rem);
  letter-spacing: 0.01em;
}

.subtle {
  color: var(--ink-soft);
  margin-top: 0;
  margin-bottom: 0.95rem;
}

.grid { display: grid; gap: 1rem; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.mobile-only { display: none; }
.desktop-only { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.05rem;
  margin-bottom: 1rem;
  position: relative;
}

.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  border-radius: 16px 0 0 16px;
  background: linear-gradient(180deg, var(--primary), var(--accent));
  opacity: 0.22;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.6rem;
}

.hero {
  background: linear-gradient(130deg, #0f4c5c 0%, #17697f 42%, #e36414 100%);
  color: #fff;
  border: 0;
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(420px 220px at 93% 10%, rgba(255,255,255,0.2), transparent 70%);
}
.hero .subtle { color: rgba(248,247,242,0.9); }
.hero-grid {
  position: relative;
  display: grid;
  grid-template-columns: 1.4fr 2fr;
  gap: 0.9rem;
}
.hero-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 0.6rem;
}
.hero-kpi {
  border: 1px solid rgba(255,255,255,0.24);
  background: rgba(255,255,255,0.14);
  border-radius: 12px;
  padding: 0.58rem 0.68rem;
}
.hero-kpi-label {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.07em;
}
.hero-kpi-value { margin-top: 0.18rem; font-size: 1.15rem; font-weight: 700; }

.sparkline { margin-top: 0.45rem; display: grid; gap: 0.3rem; }
.spark-row { display: grid; grid-template-columns: 64px 1fr auto; gap: 0.4rem; align-items: center; font-size: 0.74rem; }
.spark-bar { height: 7px; border-radius: 999px; background: rgba(255,255,255,0.2); overflow: hidden; }
.spark-bar > span { display: block; height: 100%; background: #f5b985; }
.spark-value { font-family: "IBM Plex Mono", monospace; font-size: 0.72rem; white-space: nowrap; }

.stat { display: flex; flex-direction: column; gap: 0.18rem; }
.stat-label { color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.75rem; }
.stat-value { font-size: 1.55rem; font-weight: 700; line-height: 1.1; }

.ok { color: var(--ok); font-weight: 700; }
.watch { color: var(--watch); font-weight: 700; }
.blocked { color: var(--blocked); font-weight: 700; }

.pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid;
  border-radius: 999px;
  padding: 0.2rem 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.71rem;
}
.pill.ok { background: #e8fbf1; border-color: #9cd9bc; }
.pill.watch { background: #fff3df; border-color: #ebc588; }
.pill.blocked { background: #ffe7e7; border-color: #e6a0a0; }
.pill.chip { margin: 0 0.35rem 0.35rem 0; padding: 0.17rem 0.48rem; }

.chips-row { margin: 0.2rem 0 0.68rem; }
.chip-label { color: var(--ink-soft); font-size: 0.78rem; margin-right: 0.42rem; }

.btn {
  appearance: none;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  padding: 0.5rem 0.84rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: 0.16s ease;
}
.btn:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
.btn.secondary { background: #fff; color: var(--primary); }
.btn.secondary:hover { background: #f6f8fa; }
.btn.sm { padding: 0.3rem 0.54rem; font-size: 0.8rem; border-radius: 8px; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.54rem 0.68rem;
  background: #fff;
  font: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(15,76,92,0.2);
  border-color: #7ea6b0;
}

textarea { min-height: 110px; }
form p { margin: 0 0 0.75rem; }

.filter-panel summary { display: none; font-weight: 700; cursor: pointer; margin-bottom: 0.66rem; }
.filter-actions { align-self: end; display: flex; gap: 0.5rem; }
.field-wrap { position: relative; }
.grid-3 .field-wrap { grid-column: span 2; }

.saved-filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.8rem; }
.view-toolbar { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }

.daily-plan-list {
  margin: 0;
  padding-left: 1rem;
  max-height: 420px;
  overflow-y: auto;
}

.daily-plan-item {
  margin-bottom: 0.28rem;
  cursor: pointer;
}

.daily-plan-hover-card {
  position: fixed;
  z-index: 300;
  pointer-events: none;
  background: rgba(17, 24, 39, 0.95);
  color: #f9fafb;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 0.32rem 0.5rem;
  font-size: 0.78rem;
  white-space: nowrap;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.35);
  transform: translate3d(0, 0, 0);
  opacity: 0;
  transition: opacity 120ms ease;
}

.daily-plan-hover-card.is-visible {
  opacity: 1;
}

.autocomplete-list {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  top: calc(100% - 8px);
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
}
.autocomplete-item {
  width: 100%;
  border: 0;
  border-bottom: 1px solid #ece7db;
  background: #fff;
  text-align: left;
  padding: 0.5rem 0.6rem;
  cursor: pointer;
}
.autocomplete-item:last-child { border-bottom: 0; }
.autocomplete-item:hover,
.autocomplete-item.active { background: #eef5f7; }

.table-wrap {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
}

thead { background: #f1ece1; position: sticky; top: 0; z-index: 2; }
th, td {
  padding: 0.54rem 0.56rem;
  border-bottom: 1px solid #efe5d3;
  font-size: 0.82rem;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
th { position: sticky; top: 0; z-index: 5; background: #f1ece1; }
th.money-col, td.money-col { text-align: right; font-family: "IBM Plex Mono", monospace; font-size: 0.79rem; }
.col-hidden { display: none; }

.portfolio-table th,
.portfolio-table td,
.queue-table th,
.queue-table td {
  padding: 0.45rem 0.48rem;
  font-size: 0.78rem;
}

.portfolio-table td:nth-child(2),
.portfolio-table th:nth-child(2) {
  min-width: 220px;
}

.portfolio-table td:nth-child(2) {
  white-space: normal;
}

@media (min-width: 721px) {
  .table-wrap .sticky-col-1,
  .table-wrap .sticky-col-2 {
    position: sticky;
    background: #fff;
  }

  .table-wrap th.sticky-col-1,
  .table-wrap th.sticky-col-2 {
    background: #f1ece1;
    z-index: 7;
  }

  .table-wrap td.sticky-col-1,
  .table-wrap td.sticky-col-2 {
    z-index: 3;
  }

  .portfolio-table .sticky-col-1 {
    left: 0;
    min-width: 110px;
    max-width: 110px;
    box-shadow: 2px 0 0 #efe5d3;
  }

  .portfolio-table .sticky-col-2 {
    left: 110px;
    min-width: 220px;
    box-shadow: 2px 0 0 #efe5d3;
  }

  .queue-table .sticky-col-1 {
    left: 0;
    min-width: 220px;
    max-width: 220px;
    box-shadow: 2px 0 0 #efe5d3;
  }

  .queue-table .sticky-col-2 {
    left: 220px;
    min-width: 110px;
    max-width: 110px;
    box-shadow: 2px 0 0 #efe5d3;
  }
}

tr.risk-ok { box-shadow: inset 4px 0 0 #8ddabf; }
tr.risk-watch { box-shadow: inset 4px 0 0 #f0c57f; }
tr.risk-blocked { box-shadow: inset 4px 0 0 #ec9a9a; }
tr.row-partial { background: #fff6e8; }

.totals-grid { grid-template-columns: repeat(6, minmax(170px, 1fr)); margin-bottom: 0.85rem; }
.totals-grid-primary { grid-template-columns: repeat(4, minmax(180px, 1fr)); }
.totals-grid-compare { grid-template-columns: repeat(3, minmax(250px, 1fr)); }
.totals-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 0.66rem 0.72rem;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.34rem;
}
.totals-label { color: var(--ink-soft); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em; }
.totals-value { text-align: right; font-size: 1.04rem; font-weight: 700; overflow-wrap: anywhere; }
.totals-pct { text-align: right; color: var(--ink-soft); font-size: 0.84rem; }
.totals-compare { display: grid; gap: 0.2rem; }
.totals-compare-row { display: flex; justify-content: space-between; gap: 0.45rem; color: var(--ink-soft); font-size: 0.8rem; }
.totals-compare-row strong { color: var(--ink); font-size: 0.92rem; text-align: right; }

.messages { list-style: none; margin: 0 0 0.8rem; padding: 0; }
.messages li {
  border-radius: 10px;
  border: 1px solid #b3d8de;
  background: #e9f6f8;
  color: #0c4958;
  padding: 0.55rem 0.72rem;
  margin-bottom: 0.5rem;
}

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 1rem; }

/* Constrain single-column as_p forms so they don't stretch full width */
.card form:not(.queue-actions-form):not(.grid):not([style*="display:flex"]):not([style*="display: flex"]) {
  max-width: 560px;
}

/* Style form labels rendered by Django as_p */
.card form p label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.card form p {
  margin: 0 0 0.75rem;
}
.meta-list { display: grid; grid-template-columns: 165px 1fr; gap: 0.35rem 0.72rem; margin: 0; }
.meta-list dt { color: var(--ink-soft); }
.meta-list dd { margin: 0; font-weight: 600; }

.sticky-actions {
  position: sticky;
  top: 64px;
  z-index: 30;
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 0.8rem;
  border-radius: 10px;
  border: 1px solid #c3d6dc;
  background: rgba(240, 248, 249, 0.96);
  padding: 0.52rem;
  backdrop-filter: blur(5px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.10);
}

.pagination { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.7rem; margin-top: 0.8rem; }
.pagination-nav { display: flex; gap: 0.4rem; }
.pagination-text { color: var(--ink-soft); font-size: 0.84rem; }

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

.skeleton {
  border-radius: 10px;
  background: linear-gradient(90deg, #eadfcd 0%, #f6f0e4 50%, #eadfcd 100%);
  background-size: 220px 100%;
  animation: pulse 1.1s linear infinite;
}
.skeleton-line { height: 14px; margin-bottom: 0.5rem; }
.skeleton-line.wide { width: 100%; }
.skeleton-line.mid { width: 72%; }
.skeleton-line.short { width: 42%; }
@keyframes pulse { from { background-position: 0 0; } to { background-position: 220px 0; } }

.reveal { animation: revealUp 0.26s ease both; }
@keyframes revealUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 720px) {
  .nav-toggle { display: inline-block; }
  .shell-layout {
    width: 100%;
    padding: 0;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(86vw, 300px);
    border-radius: 0 14px 14px 0;
    z-index: 140;
    transform: translateX(-110%);
    transition: transform 0.2s ease;
    padding-top: 4rem;
  }
  .sidebar-open .sidebar {
    transform: translateX(0);
  }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 130;
  }
  .sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .sidebar-open {
    overflow: hidden;
  }
  .main-content {
    margin-left: 0;
    width: 100%;
    padding: 0.8rem 0.76rem 1.4rem;
    max-width: none !important;
  }
  .hero-grid { grid-template-columns: 1fr; }
  .hero-kpis { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .sticky-actions { top: 58px; }
}

@media (max-width: 680px) {
  .card { padding: 0.82rem 0.88rem; }
  .meta-list { grid-template-columns: 1fr; }
  .totals-grid { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .totals-grid-primary { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .totals-grid-compare { grid-template-columns: repeat(1, minmax(140px, 1fr)); }
  .grid-3 .field-wrap { grid-column: span 1; }
  .mobile-only { display: block; }
  .desktop-only { display: none; }
  .filter-panel summary { display: block; }
  .filter-actions {
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top: 1px solid var(--line);
    padding-top: 0.4rem;
  }
  .filter-actions .btn { flex: 1; text-align: center; }
  table { min-width: 980px; }
}

.queue-hero {
  background: linear-gradient(135deg, #0f4c5c 0%, #1a6f86 45%, #e36414 100%);
  color: #fff;
  border: 0;
}

.queue-hero::before {
  background: radial-gradient(460px 220px at 90% 12%, rgba(255,255,255,0.2), transparent 70%);
  opacity: 1;
}

.queue-hero .subtle { color: rgba(255,255,255,0.9); }

.queue-summary-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1.2fr) minmax(240px, 1fr) minmax(280px, 1.15fr) minmax(260px, 1fr);
  gap: 0.8rem;
  align-items: stretch;
}

.queue-hero-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
}

.queue-kpi-row {
  margin-top: 0.7rem;
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 0.5rem;
}

.queue-kpi {
  border: 1px solid rgba(255,255,255,0.24);
  background: rgba(255,255,255,0.14);
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
  display: grid;
  gap: 0.12rem;
}

.queue-kpi span {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.queue-kpi strong { font-size: 1.05rem; }

.queue-section-label {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}

.queue-pill-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.queue-notes {
  margin-top: 0.8rem;
  border-top: 1px dashed var(--line);
  padding-top: 0.55rem;
}

.queue-notes p {
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.queue-main-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.7rem;
}

.queue-table td:nth-child(7),
.queue-table td:nth-child(8),
.queue-table td:nth-child(9),
.queue-table td:nth-child(12) {
  white-space: normal;
  min-width: 220px;
}

.queue-contact-grid,
.queue-actions-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.queue-contact-grid .btn,
.queue-actions-form.outcome-buttons .btn,
.queue-actions-form.control-buttons .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.control-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.control-group .btn {
  flex: 1 1 calc(50% - 0.35rem);
  min-width: 110px;
}

.control-group.control-group-full .btn {
  flex-basis: 100%;
}

.control-label {
  width: 100%;
  margin-bottom: 0.1rem;
}

@media (max-width: 980px) {
  .queue-summary-grid {
    grid-template-columns: repeat(2, minmax(260px, 1fr));
  }

  .queue-kpi-row {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 680px) {
  .queue-summary-grid {
    grid-template-columns: 1fr;
  }
}
