/* ======================================================
   DATS 2.0 — Alfie Palette & Animation System
   ====================================================== */

:root {
  /* Alfie palette */
  --navy: #0B2E59;
  --blue: #0057B8;
  --teal: #399AFF;
  --cyan: #00C2FF;
  --gold: #F4B400;
  --white: #FFFFFF;
  --success: #16A34A;
  --warning: #FFC107;
  --light-blue: #E6F4FF;
  --soft-cyan: #CCF2FF;
  --slate-blue: #6B87B7;
  --indigo: #283593;
  --neutral-gray: #F1F5F9;
  --dark-gray: #1F2937;
  --muted: var(--slate-blue);
  --line: var(--soft-cyan);
  --soft: var(--neutral-gray);
  --ink: var(--dark-gray);
  --danger: #b42318;
  --shadow: 0 12px 30px rgba(11,46,89,.08);

  /* Animation tokens */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.45, 0, 0.55, 1);
  --duration-base: 0.4s;
  --duration-slow: 0.6s;
  --transition-base: 0.25s ease;
}

/* ---- Keyframes ---- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes fadeInLeft {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

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

/* ---- Base ---- */
*{box-sizing:border-box}

body {
  margin: 0;
  background: var(--neutral-gray);
  color: var(--ink);
  font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  animation: fadeIn var(--duration-base) var(--ease-out);
}

a { color: var(--blue); text-decoration: none; transition: color var(--transition-base); }
a:hover { text-decoration: underline; }

/* ---- Topbar ---- */
.topbar {
  height: 68px;
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 34px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 5px 18px rgba(0,0,0,.14);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 800;
  font-size: 17px;
  white-space: nowrap;
  transition: opacity var(--transition-base);
}
.brand:hover { text-decoration: none; opacity: .88; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--teal);
  color: var(--white);
  font-size: 13px;
  font-weight: 900;
  transition: transform var(--transition-base);
}
.brand:hover .brand-mark { transform: rotate(-4deg) scale(1.06); }

.topbar nav { display: flex; gap: 22px; flex: 1; }
.topbar nav a {
  color: #c8dae8;
  font-weight: 650;
  transition: color var(--transition-base);
}
.topbar nav a:hover { color: #fff; text-decoration: none; }
.topbar nav a.active { color: #fff; border-bottom: 2px solid var(--teal); padding-bottom: 2px; }

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

/* ---- Container & Footer ---- */
.container {
  width: min(1500px, calc(100% - 48px));
  margin: 32px auto 70px;
}
footer { text-align: center; color: var(--muted); padding: 28px; }

/* ---- Hero ---- */
.hero {
  background: linear-gradient(135deg, var(--navy) 0%, var(--blue) 55%, var(--teal) 100%);
  color: white;
  border-radius: 24px;
  padding: 46px 50px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
  animation: fadeInUp var(--duration-slow) var(--ease-out);
}

.hero h1 {
  font-size: 42px;
  line-height: 1.08;
  max-width: 850px;
  margin: 8px 0 14px;
}

.lead { font-size: 18px; color: var(--light-blue); max-width: 900px; }
.lead.compact { color: var(--ink); max-width: none; }

.hero-actions { display: flex; gap: 10px; min-width: 270px; justify-content: flex-end; }

.eyebrow {
  text-transform: uppercase;
  letter-spacing: .11em;
  font-size: 12px;
  font-weight: 800;
  color: var(--gold);
  margin: 0 0 5px;
}
.hero .eyebrow { color: var(--teal); }

/* ---- Metrics (staggered fade) ---- */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin: 20px 0;
}

.metric {
  background: var(--white);
  border: 1px solid var(--soft-cyan);
  border-radius: 18px;
  padding: 22px 24px;
  box-shadow: var(--shadow);
  transition: transform var(--transition-base), box-shadow var(--transition-base);
  animation: fadeInUp var(--duration-base) var(--ease-out) both;
}
.metric:nth-child(1) { animation-delay: 0.05s; }
.metric:nth-child(2) { animation-delay: 0.1s; }
.metric:nth-child(3) { animation-delay: 0.15s; }
.metric:nth-child(4) { animation-delay: 0.2s; }
.metric:hover { transform: translateY(-3px); box-shadow: 0 16px 40px rgba(11,46,89,.12); }

.metric span { display: block; color: var(--muted); font-weight: 650; }
.metric strong { display: block; font-size: 34px; color: var(--navy); margin-top: 2px; }

/* ---- Grid ---- */
.grid { display: grid; gap: 18px; margin: 18px 0; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: repeat(3, 1fr); }
.detail-grid { grid-template-columns: 2fr 1fr 1fr; }
.review-grid { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
.span-two { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

/* ---- Panel (fade-in for grids) ---- */
.panel {
  background: var(--white);
  border: 1px solid var(--soft-cyan);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition-base), transform var(--transition-base);
}
.panel:hover { box-shadow: 0 16px 40px rgba(0,63,140,.1); }
.panel:has(> .review-list):hover,
.panel:has(> .candidate-card):hover { box-shadow: var(--shadow); }
.panel h2 { margin: 2px 0 14px; font-size: 22px; color: var(--navy); }
.panel h3 { color: var(--navy); }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }

.grid.two > .panel:nth-child(1) { animation: fadeInLeft var(--duration-base) var(--ease-out) both; animation-delay: 0.25s; }
.grid.two > .panel:nth-child(2) { animation: fadeInUp var(--duration-base) var(--ease-out) both; animation-delay: 0.3s; }
.grid.three > .panel { animation: fadeInUp var(--duration-base) var(--ease-out) both; }
.grid.three > .panel:nth-child(1) { animation-delay: 0.1s; }
.grid.three > .panel:nth-child(2) { animation-delay: 0.2s; }
.grid.three > .panel:nth-child(3) { animation-delay: 0.3s; }

/* ---- Buttons ---- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--soft-cyan);
  background: var(--white);
  color: var(--navy);
  border-radius: 10px;
  padding: 10px 15px;
  font-weight: 750;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition-base), color var(--transition-base),
              transform 0.15s ease, box-shadow var(--transition-base),
              border-color var(--transition-base);
}
.button:hover {
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,63,140,.12);
}
.button:active { transform: translateY(0); box-shadow: none; }

.button.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--white);
}
.button.primary:hover { background: #2d85e0; border-color: #2d85e0; }

.button.danger { background: #fff1f0; border-color: #f3b3ae; color: var(--danger); }
.button.danger:hover { background: #fde8e6; }

.button.ghost { background: transparent; border-color: var(--muted); color: var(--white); font-size: 13px; }
.button.ghost:hover { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.5); }

/* ---- Bar chart ---- */
.bar-list { display: flex; flex-direction: column; gap: 2px; }

.bar-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.4fr) 1fr 44px;
  gap: 14px;
  align-items: center;
  color: var(--ink);
  padding: 7px 10px;
  border-radius: 10px;
  transition: background var(--transition-base), transform 0.15s ease;
  text-decoration: none;
}
.bar-row:hover {
  text-decoration: none;
  background: var(--light-blue);
  transform: translateX(3px);
}

.bar-label {
  font-size: 13px;
  font-weight: 650;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  height: 10px;
  background: var(--neutral-gray);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--teal));
  border-radius: 999px;
  transition: width 0.9s var(--ease-out);
  animation: barGrow 0.8s var(--ease-out) both;
}
.bar-fill.alt {
  background: linear-gradient(90deg, var(--navy), var(--blue));
}

@keyframes barGrow {
  from { width: 0; }
}

.bar-row:nth-child(1) .bar-fill { animation-delay: 0.08s; }
.bar-row:nth-child(2) .bar-fill { animation-delay: 0.14s; }
.bar-row:nth-child(3) .bar-fill { animation-delay: 0.2s; }
.bar-row:nth-child(4) .bar-fill { animation-delay: 0.26s; }
.bar-row:nth-child(5) .bar-fill { animation-delay: 0.32s; }
.bar-row:nth-child(6) .bar-fill { animation-delay: 0.38s; }
.bar-row:nth-child(7) .bar-fill { animation-delay: 0.44s; }
.bar-row:nth-child(8) .bar-fill { animation-delay: 0.5s; }

.bar-row strong {
  font-size: 13px;
  font-weight: 800;
  color: var(--navy);
  text-align: right;
  background: var(--soft-cyan);
  padding: 2px 8px;
  border-radius: 6px;
  min-width: 28px;
  display: inline-block;
}

/* ---- Table ---- */
.table-wrap { overflow: auto; }
.table-panel { padding: 0; }
.table-panel .table-wrap { border-radius: 18px; }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  background: var(--light-blue);
  color: var(--navy);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 13px 14px;
  position: sticky;
  top: 0;
}
td { padding: 13px 14px; border-top: 1px solid var(--soft-cyan); vertical-align: top; }
td small, .candidate-card small, .review-row small { display: block; color: var(--muted); margin-top: 3px; }

.wide-table { min-width: 1200px; }
.system-name { font-weight: 800; color: var(--navy); }

/* ---- Status / Priority ---- */
.status {
  display: inline-flex;
  background: var(--light-blue);
  color: var(--muted);
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  transition: background var(--transition-base);
}
.status.big { font-size: 14px; padding: 8px 12px; }

.priority {
  display: inline-flex;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}
.priority.high { background: #d4edda; color: #1a5632; }
.priority.medium { background: #fff8dc; color: #7b5700; }
.priority.low { background: #edf0f2; color: #53626c; }

/* ---- Tags ---- */
.tag-group { display: flex; flex-wrap: wrap; gap: 7px; }
.tag {
  display: inline-block;
  border-radius: 6px;
  background: var(--light-blue);
  color: var(--muted);
  padding: 4px 7px;
  font-size: 11px;
  font-weight: 650;
  margin: 2px;
  transition: background var(--transition-base);
}
.tag.primary-tag { background: #cfe8f7; color: #003f8c; }
.tag.soft { background: #fdf3cd; color: #7b5700; }

/* ---- Candidate cards / Review rows ---- */
.card-list, .review-list { display: flex; flex-direction: column; }

.candidate-card, .review-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 5px;
  border-top: 1px solid var(--soft-cyan);
  color: var(--ink);
  transition: background var(--transition-base), border-color var(--transition-base);
}
.review-row > div { min-width: 0; flex: 1; overflow: hidden; }
.review-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.candidate-id { min-width: 42px; }
.confidence { min-width: 48px; text-align: right; }

.candidate-card:hover {
  text-decoration: none;
  background: var(--soft);
  border-left: 3px solid var(--teal);
  padding-left: 12px;
}

.confidence { font-weight: 850; color: var(--teal); font-size: 17px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---- Page headings ---- */
.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin: 8px 0 24px;
  animation: fadeIn var(--duration-base) var(--ease-out);
}
.page-heading h1 { font-size: 38px; line-height: 1.1; color: var(--navy); margin: 4px 0 6px; }
.page-heading p { color: var(--muted); margin: 0; max-width: 850px; }

/* ---- Filters ---- */
.filters {
  display: grid;
  grid-template-columns: 1.2fr repeat(4, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
  animation: fadeInUp var(--duration-base) var(--ease-out) both;
  animation-delay: 0.15s;
}
.filters .button { height: 43px; }

/* ---- Forms ---- */
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--soft-cyan);
  border-radius: 9px;
  padding: 10px 11px;
  background: var(--white);
  color: var(--ink);
  font: inherit;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}
textarea { resize: none; }
input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(0,87,184,.15);
  border-color: var(--blue);
}
input[readonly] { background: #e9ecef; color: #6c757d; border-color: #dee2e6; cursor: not-allowed; }

/* ---- Facts / Detail ---- */
.facts { display: grid; grid-template-columns: 160px 1fr; gap: 11px 18px; }
.facts dt { font-weight: 800; color: var(--muted); }
.facts dd { margin: 0; }
.source-list { display: flex; gap: 20px; flex-wrap: wrap; }
.score-panel { text-align: center; }
.score { font-size: 54px; color: var(--teal); }
.score small { font-size: 20px; color: var(--muted); }

/* ---- Submit grid ---- */
.submit-grid .form-panel { position: relative; }
.step {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--teal);
  color: var(--white);
  font-weight: 900;
}
.form-panel h2 { margin-top: 12px; }
.form-panel label { margin: 14px 0; }

/* ---- Workflow ---- */
.workflow {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 14px;
  margin-top: 24px;
  animation: fadeInUp var(--duration-base) var(--ease-out) both;
  animation-delay: 0.35s;
}
.workflow div { text-align: center; }
.workflow span { display: block; font-weight: 850; color: var(--navy); }
.workflow small { color: var(--muted); }
.workflow b { color: var(--muted); font-size: 20px; }

/* ---- Submission status page ---- */
.status-page { text-align: center; max-width: 750px; margin: 60px auto; padding: 55px; animation: scaleIn var(--duration-base) var(--ease-out); }
.status-page h1 { font-size: 38px; color: var(--navy); }

/* ---- Progress bar ---- */
.progress { height: 12px; background: var(--light-blue); border-radius: 999px; overflow: hidden; margin: 25px; }
.progress span {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, transparent, var(--teal), transparent);
  animation: indeterminate 1.5s ease-in-out infinite;
}
.progress span.needs_review, .progress span.approved { width: 100%; background: var(--teal); animation: none; }
.progress span.failed, .progress span.rejected { width: 100%; background: var(--danger); animation: none; }

@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ---- Error box ---- */
.error-box { background: var(--light-blue); color: var(--danger); padding: 18px; border-radius: 10px; }

/* ---- Tabs ---- */
.tabs { display: flex; border: 1px solid var(--soft-cyan); border-radius: 11px; overflow: hidden; background: var(--white); }
.tabs a {
  padding: 9px 14px;
  color: var(--muted);
  font-weight: 750;
  transition: background var(--transition-base), color var(--transition-base);
}
.tabs a:hover { background: var(--soft); }
.tabs a.active { background: var(--navy); color: var(--white); }
.tabs .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gold);
  color: var(--navy);
  font-size: 11px;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  margin-left: 6px;
}

/* ---- Nav badge (topbar) ---- */
.topbar nav .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gold);
  color: var(--navy);
  font-size: 11px;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  margin-left: 6px;
  vertical-align: middle;
  line-height: 1;
}

/* ---- Candidate ID ---- */
.candidate-id { font-weight: 850; color: var(--blue); }

/* ---- Form grid (review) ---- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---- Stack / Duplicate / Evidence ---- */
.stack { display: flex; flex-direction: column; gap: 18px; }
.duplicate { display: block; border-top: 1px solid var(--soft-cyan); padding: 12px 0; color: var(--ink); transition: background var(--transition-base); }
.duplicate:hover { background: var(--soft); }
.duplicate span { display: block; }
.evidence { border-top: 1px solid var(--soft-cyan); padding: 13px 0; }
.evidence p { margin: 5px 0; }
.evidence small { color: var(--muted); margin-right: 8px; }

/* ---- Decision panel ---- */
.decision-panel { margin-top: 20px; animation: fadeInUp var(--duration-base) var(--ease-out) both; animation-delay: 0.4s; }
.decision-forms { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.decision-forms form { border-top: 1px solid var(--soft-cyan); padding-top: 18px; }
.decision-forms label { margin: 10px 0; }

/* ---- Code ---- */
code { background: var(--light-blue); padding: 2px 5px; border-radius: 5px; white-space: pre-wrap; }

/* ---- Detail heading ---- */
.detail-heading { align-items: center; }

/* ---- Token field (inline style already in template) ---- */

/* ======================================================
   Responsive
   ====================================================== */
@media (max-width: 1100px) {
  .grid.three, .detail-grid { grid-template-columns: 1fr; }
  .grid.two, .review-grid { grid-template-columns: 1fr; }
  .span-two { grid-column: auto; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .filters { grid-template-columns: 1fr 1fr; }
  .hero { align-items: start; flex-direction: column; }
  .hero-actions { justify-content: start; }
  .top-actions { display: none; }
}

@media (max-width: 720px) {
  .topbar { height: auto; min-height: 64px; flex-wrap: wrap; padding: 12px 18px; }
  .topbar nav { order: 3; overflow: auto; width: 100%; padding-bottom: 5px; }
  .container { width: min(100% - 24px, 1500px); margin-top: 18px; }
  .hero { padding: 30px 24px; }
  .hero h1, .page-heading h1 { font-size: 31px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .filters, .form-grid, .decision-forms { grid-template-columns: 1fr; }
  .workflow { align-items: stretch; flex-direction: column; }
  .workflow b { transform: rotate(90deg); }
  .facts { grid-template-columns: 1fr; }
  .page-heading { align-items: start; flex-direction: column; }
  .bar-row { grid-template-columns: 1fr 80px 35px; }
}

/* ======================================================
   Toast notifications
   ====================================================== */
.toast-container { position: fixed; top: 80px; right: 24px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 14px 20px;
  border-radius: 10px;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  animation: toast-in 0.35s var(--ease-out);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 420px;
}
.toast.success { background: #059669; }
.toast.error { background: var(--danger); }
.toast.info { background: var(--blue); }
.toast-close { cursor: pointer; margin-left: auto; opacity: .8; font-size: 18px; transition: opacity var(--transition-base); }
.toast-close:hover { opacity: 1; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ---- Loading state ---- */
.button.loading { opacity: .65; cursor: not-allowed; pointer-events: none; }
