/* ==========================================================================
   VIFIMS form design system (M&E + AWPB)
   Scoped under .vf to avoid leaking into the rest of the app.
   Restyles native input/select/textarea so existing Django widgets upgrade
   without changing forms.py.
   ========================================================================== */

/* ---- Self-hosted display + text pairing (drop subsetted woff2 in /static/fonts) ----
   Falls back to a distinctive serif/sans stack so it looks intentional even
   before the woff2 files are added. */
@font-face {
  font-family: "Fraunces VF";
  src: url("/static/fonts/Fraunces-VariableFont.woff2") format("woff2");
  font-weight: 300 700; font-display: swap; font-style: normal;
}
@font-face {
  font-family: "Inter VF";
  src: url("/static/fonts/Inter-VariableFont.woff2") format("woff2");
  font-weight: 300 700; font-display: swap; font-style: normal;
}

:root {
  --vf-display: "Fraunces VF", "Iowan Old Style", "Palatino Linotype", Georgia, ui-serif, serif;
  --vf-text: "Inter VF", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Brand + neutrals (all >= 4.5:1 on white) */
  --vf-ink: #0f1f17;          /* near-black green-tinted */
  --vf-muted: #4b5a53;        /* secondary text */
  --vf-faint: #8a978f;        /* tertiary */
  --vf-line: #e3e8e5;         /* hairlines */
  --vf-canvas: #f6f8f7;       /* page wash */
  --vf-surface: #ffffff;

  /* Brand green */
  --vf-primary: #1c7c4a;      /* refined forest green */
  --vf-primary-strong: #155f39;
  --vf-primary-ink: #ffffff;
  --vf-primary-wash: #e9f5ee;

  /* Deliberate secondary accent (deep ink-teal) for emphasis */
  --vf-accent: #0c4a4a;

  /* Semantic states */
  --vf-danger: #c0392b;       /* destructive / errors */
  --vf-danger-wash: #fbeae8;
  --vf-warning: #b9740a;      /* amber, AA on white */
  --vf-info: #1f5fbf;

  /* Form */
  --vf-radius: 12px;
  --vf-radius-sm: 8px;
  --vf-field-bg: #fbfcfb;
  /* Shadows removed — flat, border-led surfaces */
  --vf-shadow-sm: none;
  --vf-shadow-md: none;
  --vf-shadow-lg: none;
  --vf-ring: 0 0 0 3px rgba(28,124,74,.22);
}

/* ---- Scope base ---- */
.vf { font-family: var(--vf-text); color: var(--vf-ink); }
.vf *,
.vf *::before,
.vf *::after { box-sizing: border-box; }

.vf a, .vf button, .vf [role="button"],
.vf label.vf-check, .vf summary { cursor: pointer; }

/* ---- Typography ---- */
.vf-eyebrow {
  font-family: var(--vf-text);
  font-size: .72rem; letter-spacing: .14em; text-transform: uppercase;
  font-weight: 600; color: var(--vf-primary);
}
.vf-title {
  font-family: var(--vf-display);
  font-weight: 600; letter-spacing: -.02em; line-height: 1.05;
  color: var(--vf-ink);
  font-size: clamp(1.6rem, 1.2rem + 1.4vw, 2.25rem);
}
.vf-lede { color: var(--vf-muted); font-size: .95rem; max-width: 60ch; }
.vf-section-title {
  font-family: var(--vf-display);
  font-weight: 600; font-size: 1.05rem; letter-spacing: -.01em; color: var(--vf-ink);
}
.vf-section-hint { font-size: .8rem; color: var(--vf-faint); }

/* ---- Layout: asymmetric form + context rail ---- */
.vf-grid {
  display: grid; gap: 1.5rem;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 1024px) {
  .vf-grid.has-rail { grid-template-columns: minmax(0, 1fr) 19rem; align-items: start; }
}

/* ---- Cards / sections ---- */
.vf-card {
  background: var(--vf-surface);
  border: 1px solid var(--vf-line);
  border-radius: var(--vf-radius);
  overflow: clip;
}

.vf-card-head {
  display: flex; align-items: center; gap: .75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--vf-line);
  background:
    linear-gradient(180deg, #fff, #fbfdfb);
  position: relative;
}
.vf-card-icon {
  flex: 0 0 auto; width: 2.1rem; height: 2.1rem; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--vf-primary-wash); color: var(--vf-primary);
}
.vf-card-icon svg { width: 1.15rem; height: 1.15rem; }
.vf-card-body { padding: 1.25rem 1.25rem 1.4rem; }

/* ---- Field grid ---- */
.vf-fields { display: grid; gap: 1.1rem 1.25rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .vf-fields.cols-2 { grid-template-columns: 1fr 1fr; } }
.vf-field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.vf-field.col-span-2 { grid-column: 1 / -1; }

.vf-label { font-size: .82rem; font-weight: 600; color: var(--vf-ink); display: flex; gap: .25rem; align-items: baseline; }
.vf-label .req { color: var(--vf-danger); font-weight: 700; }
.vf-help { font-size: .76rem; color: var(--vf-faint); }
.vf-error { font-size: .76rem; color: var(--vf-danger); font-weight: 500; display: flex; gap: .35rem; align-items: center; }
.vf-error svg { width: .9rem; height: .9rem; flex: 0 0 auto; }

/* ---- Native controls (override DaisyUI widget classes in scope) ---- */
.vf-form input:not([type="checkbox"]):not([type="radio"]),
.vf-form select,
.vf-form textarea {
  width: 100%;
  font-family: var(--vf-text); font-size: .9rem; color: var(--vf-ink);
  background: var(--vf-field-bg);
  border: 1.5px solid var(--vf-line) !important;
  border-radius: var(--vf-radius-sm) !important;
  padding: .6rem .75rem !important;
  height: auto !important;
  box-shadow: none;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
  appearance: none;
}
.vf-form textarea { min-height: 5rem; line-height: 1.5; }
.vf-form select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%234b5a53' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right .7rem center; padding-right: 2rem !important;
}
.vf-form input::placeholder, .vf-form textarea::placeholder { color: var(--vf-faint); }
.vf-form input:focus, .vf-form select:focus, .vf-form textarea:focus {
  outline: none;
  border-color: var(--vf-primary) !important;
  background: #fff;
  box-shadow: var(--vf-ring);
}
.vf-form input[aria-invalid="true"], .vf-form .has-error input,
.vf-form .has-error select, .vf-form .has-error textarea {
  border-color: var(--vf-danger) !important;
}

/* Checkbox as a selectable chip row */
.vf-check {
  display: inline-flex; align-items: center; gap: .6rem;
  padding: .55rem .8rem; border: 1.5px solid var(--vf-line);
  border-radius: 999px; font-size: .85rem; font-weight: 500; color: var(--vf-ink);
  background: #fff; transition: border-color .15s ease, background .15s ease;
}
.vf-check input[type="checkbox"] {
  width: 1.05rem; height: 1.05rem; accent-color: var(--vf-primary); cursor: pointer;
}
.vf-check:has(input:checked) { border-color: var(--vf-primary); background: var(--vf-primary-wash); }

/* ---- Buttons ---- */
.vf-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font-family: var(--vf-text); font-weight: 600; font-size: .9rem; line-height: 1;
  padding: .7rem 1.1rem; border-radius: 10px; border: 1.5px solid transparent;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
  text-decoration: none; cursor: pointer; user-select: none;
}
.vf-btn svg { width: 1.05rem; height: 1.05rem; }
.vf-btn:focus-visible { outline: none; box-shadow: var(--vf-ring); }

.vf-btn-primary { background: var(--vf-primary); color: var(--vf-primary-ink); }
.vf-btn-ghost { background: #fff; color: var(--vf-muted); border-color: var(--vf-line); }
.vf-btn-danger { background: #fff; color: var(--vf-danger); border-color: rgba(192,57,43,.35); }

/* ---- Sticky action bar ---- */
.vf-actions {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; align-items: center; justify-content: flex-end; gap: .6rem;
  margin-top: 1.5rem; padding: .85rem 1rem;
  background: rgba(255,255,255,.86); backdrop-filter: blur(8px);
  border: 1px solid var(--vf-line); border-radius: 14px;
  box-shadow: var(--vf-shadow-md);
}
.vf-actions .spacer { margin-right: auto; }
.vf-actions .vf-dirty { font-size: .78rem; color: var(--vf-muted); }

/* ---- Context rail ---- */
.vf-rail { display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 1rem; }
.vf-rail-card {
  background: linear-gradient(180deg, var(--vf-primary-wash), #fff);
  border: 1px solid var(--vf-line); border-radius: var(--vf-radius);
  padding: 1.1rem; box-shadow: var(--vf-shadow-sm);
}
.vf-rail-card h4 { font-family: var(--vf-display); font-size: .95rem; margin: 0 0 .4rem; color: var(--vf-ink); }
.vf-rail-step { display: flex; gap: .6rem; align-items: flex-start; padding: .35rem 0; font-size: .82rem; color: var(--vf-muted); }
.vf-rail-step .dot {
  flex: 0 0 auto; width: 1.25rem; height: 1.25rem; border-radius: 999px; margin-top: .05rem;
  display: grid; place-items: center; background: var(--vf-primary); color: #fff; font-size: .68rem; font-weight: 700;
}

/* ---- Alerts ---- */
.vf-alert {
  display: flex; gap: .6rem; align-items: flex-start;
  padding: .8rem 1rem; border-radius: 10px; font-size: .85rem;
  border: 1px solid; margin-bottom: 1rem;
}
.vf-alert svg { width: 1.05rem; height: 1.05rem; flex: 0 0 auto; margin-top: .1rem; }
.vf-alert-danger { background: var(--vf-danger-wash); border-color: rgba(192,57,43,.3); color: #8f2a20; }
.vf-alert-error { background: var(--vf-danger-wash); border-color: rgba(192,57,43,.3); color: #8f2a20; }
.vf-alert-success { background: var(--vf-primary-wash); border-color: rgba(28,124,74,.3); color: var(--vf-primary-strong); }
.vf-alert-warning { background: #fdf3e3; border-color: rgba(185,116,10,.3); color: #8a5408; }
.vf-alert-info { background: #e8f0fc; border-color: rgba(31,95,191,.3); color: #1a4c97; }

/* ---- Month grid (AWPB schedule) ---- */
.vf-months { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
@media (min-width: 560px) { .vf-months { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 900px) { .vf-months { grid-template-columns: repeat(6, 1fr); } }
.vf-month label { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--vf-faint); font-weight: 600; }

/* ---- Motion: staggered reveal ---- */
@keyframes vf-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.vf-reveal { opacity: 0; animation: vf-rise .45s cubic-bezier(.22,.61,.36,1) forwards; }
.vf-reveal:nth-child(1) { animation-delay: .04s; }
.vf-reveal:nth-child(2) { animation-delay: .12s; }
.vf-reveal:nth-child(3) { animation-delay: .20s; }
.vf-reveal:nth-child(4) { animation-delay: .28s; }
.vf-reveal:nth-child(5) { animation-delay: .36s; }
.vf-reveal:nth-child(6) { animation-delay: .44s; }

@media (prefers-reduced-motion: reduce) {
  .vf-reveal { animation: none; opacity: 1; }
  .vf-card, .vf-btn { transition: none; }
}

/* ==========================================================================
   List / detail components
   ========================================================================== */

/* Page header / toolbar */
.vf-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.vf-toolbar .vf-actions-inline { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Section nav tabs (e.g. M&E sub-navigation) */
.vf-tabs { display: flex; flex-wrap: wrap; gap: .5rem; border-bottom: 1px solid var(--vf-line); margin-bottom: 1.5rem; padding-bottom: .25rem; }
.vf-tab {
  font-size: .85rem; font-weight: 600; color: var(--vf-muted);
  padding: .6rem 1.1rem; border-radius: 8px 8px 0 0; border: 1px solid transparent; border-bottom: none;
  text-decoration: none; cursor: pointer; transition: color .15s ease, background .15s ease;
}
.vf-tab:hover { color: var(--vf-ink); }
.vf-tab.is-active { color: var(--vf-primary); background: var(--vf-primary-wash); border-color: var(--vf-line); }

/* Pill filter row */
.vf-pills { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.1rem; }
.vf-pill {
  font-size: .82rem; padding: .35rem .85rem; border-radius: 999px;
  border: 1px solid var(--vf-line); color: var(--vf-muted); text-decoration: none; cursor: pointer;
}
.vf-pill.is-active { border-color: var(--vf-primary); color: var(--vf-primary); background: var(--vf-primary-wash); }

/* Tables */
.vf-table-wrap { border: 1px solid var(--vf-line); border-radius: var(--vf-radius); overflow-x: auto; background: var(--vf-surface); }
.vf table { width: 100%; border-collapse: collapse; font-size: .875rem; color: var(--vf-ink); }
.vf table thead th {
  text-align: left; font-weight: 600; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--vf-faint); background: #f8faf9; padding: .7rem .9rem; border-bottom: 1px solid var(--vf-line); white-space: nowrap;
}
.vf table tbody td { padding: .8rem .9rem; border-top: 1px solid var(--vf-line); vertical-align: top; }
.vf table tbody tr:first-child td { border-top: none; }
.vf-num { text-align: right; font-variant-numeric: tabular-nums; }
.vf-code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .78rem; color: var(--vf-faint); }

/* Badges (status pills) */
.vf-badge {
  display: inline-flex; align-items: center; gap: .3rem; font-size: .72rem; font-weight: 600;
  padding: .2rem .55rem; border-radius: 999px; line-height: 1.4; white-space: nowrap;
}
.vf-badge-success { background: var(--vf-primary-wash); color: var(--vf-primary-strong); }
.vf-badge-outline { background: transparent; color: var(--vf-muted); border: 1px solid var(--vf-line); }
.vf-badge-warning { background: #fdf3e3; color: #8a5408; }
.vf-badge-danger  { background: var(--vf-danger-wash); color: #8f2a20; }
.vf-badge-info    { background: #e8f0fc; color: #1a4c97; }
.vf-badge-muted   { background: #eef1f0; color: var(--vf-muted); }

/* Stat cards */
.vf-stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 1.5rem; }
.vf-stat { background: var(--vf-surface); border: 1px solid var(--vf-line); border-radius: var(--vf-radius); padding: 1.1rem 1.25rem; }
.vf-stat .k { font-size: .78rem; color: var(--vf-muted); font-weight: 500; }
.vf-stat .v { font-family: var(--vf-display); font-size: 1.6rem; font-weight: 600; color: var(--vf-ink); margin-top: .15rem; }
.vf-stat .s { font-size: .72rem; color: var(--vf-faint); margin-top: .1rem; }

/* Meter / progress bar */
.vf-meter { height: 6px; border-radius: 999px; background: #eef1f0; overflow: hidden; }
.vf-meter > span { display: block; height: 100%; background: var(--vf-primary); }

/* Empty state */
.vf-empty { text-align: center; padding: 3.5rem 1rem; border: 1px dashed var(--vf-line); border-radius: var(--vf-radius); color: var(--vf-faint); }
.vf-empty svg { width: 2.5rem; height: 2.5rem; color: #cdd6d1; margin: 0 auto .75rem; display: block; }
.vf-empty h3 { font-family: var(--vf-display); font-size: 1.05rem; color: var(--vf-ink); margin-bottom: .25rem; }

/* Inline table action link + icon button (small, flat) */
.vf-act {
  display: inline-flex; align-items: center; gap: .25rem; font-size: .78rem; font-weight: 600;
  color: var(--vf-muted); padding: .28rem .5rem; border-radius: 6px; border: 1px solid transparent;
  background: none; text-decoration: none; cursor: pointer;
}
.vf-act:focus-visible { outline: none; box-shadow: var(--vf-ring); }
.vf-act-danger { color: var(--vf-danger); }
.vf-iconbtn {
  display: inline-grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 8px;
  color: var(--vf-muted); border: 1px solid transparent; background: none; cursor: pointer;
  font-size: 1.05rem; line-height: 1;
}
.vf-iconbtn:focus-visible { outline: none; box-shadow: var(--vf-ring); }

/* Small action links in a table row */
.vf-rowact { display: inline-flex; gap: .25rem; }
.vf-rowact a, .vf-rowact button {
  font-size: .78rem; font-weight: 600; color: var(--vf-muted); background: none; border: none;
  padding: .25rem .45rem; border-radius: 6px; cursor: pointer; text-decoration: none;
}
.vf-rowact a:hover, .vf-rowact button:hover { color: var(--vf-primary); }

/* Dropdown (native details) for row actions */
.vf-menu { position: relative; }
.vf-menu > summary { list-style: none; cursor: pointer; }
.vf-menu > summary::-webkit-details-marker { display: none; }
.vf-menu[open] > .vf-menu-list { display: block; }
.vf-menu-list {
  display: none; position: absolute; right: 0; z-index: 30; min-width: 9rem; padding: .3rem;
  background: #fff; border: 1px solid var(--vf-line); border-radius: 10px; box-shadow: none;
}
.vf-menu-list a {
  display: block; padding: .4rem .6rem; font-size: .82rem; color: var(--vf-ink); border-radius: 6px; text-decoration: none; cursor: pointer;
}
.vf-menu-list a.danger { color: var(--vf-danger); }
