/* ============================================================
   Liberty Lou — Markets Dashboard
   ============================================================ */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #15803d;
  --brand-d: #166534;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}
.hidden { display: none !important; }
.app-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: #b91c1c; color: #fff; padding: .6rem 1rem; font-size: .9rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.app-banner button { background: transparent; border: 0; color: #fff; font-size: 1.2rem; cursor: pointer; line-height: 1; }
.app-loading {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 90;
  background: #1e293b; color: #fff; padding: .55rem 1.1rem; border-radius: 999px;
  display: flex; align-items: center; gap: .6rem; font-size: .88rem;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .3);
}
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff;
  animation: spin .8s linear infinite; flex: 0 0 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
a { color: var(--brand-d); }
h2, h3 { margin: 0 0 .4rem; }
.muted { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: .5rem .9rem;
  border-radius: 8px;
  font-size: .9rem;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); }
.btn.ghost { background: transparent; }
.btn.danger { color: #b91c1c; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: .8rem; text-decoration: underline; padding: 0; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.05rem; }
.brand-mark {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand); color: #fff; font-size: .85rem; font-weight: 800;
}

/* ============================================================
   LOGIN
   ============================================================ */
#login-screen {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #14532d, #166534 55%, #1e293b);
  padding: 1rem;
}
.login-card {
  background: var(--surface);
  width: 100%; max-width: 380px;
  padding: 2rem 1.75rem;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, .25);
  display: flex; flex-direction: column; gap: .85rem;
}
.login-card .brand { font-size: 1.25rem; }
.login-sub { margin: -.3rem 0 .5rem; color: var(--muted); }
.login-card label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }
.login-card input {
  padding: .6rem .7rem; border: 1px solid var(--line);
  border-radius: 8px; font-size: 1rem;
}
.login-error { color: #dc2626; font-size: .85rem; min-height: 1rem; margin: 0; }
.login-demo { font-size: .78rem; color: var(--muted); text-align: center; margin: .2rem 0 0; }
.login-demo code { background: #f1f5f9; padding: .1rem .3rem; border-radius: 4px; }

/* ============================================================
   APP SHELL
   ============================================================ */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .65rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  flex-wrap: wrap;
}
.tabs { display: flex; gap: .25rem; flex: 1; }
.tab-btn {
  border: 0; background: transparent; color: var(--muted);
  padding: .5rem .85rem; border-radius: 8px;
  font-size: .92rem; font-weight: 600; cursor: pointer;
}
.tab-btn:hover { background: #f1f5f9; color: var(--ink); }
.tab-btn.active { background: #dcfce7; color: var(--brand-d); }
.user-box { display: flex; align-items: center; gap: .6rem; }
.user-email { font-size: .82rem; color: var(--muted); }

.content { padding: 1.25rem; max-width: 1280px; margin: 0 auto; }
.hint { color: var(--muted); margin: 0 0 1rem; font-size: .9rem; }

/* ---------- filters ---------- */
.filters {
  display: flex; gap: .6rem; flex-wrap: wrap; align-items: center;
  padding: .75rem 1.25rem; background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 53px; z-index: 15;
}
.filters input, .filters select {
  padding: .5rem .65rem; border: 1px solid var(--line);
  border-radius: 8px; font-size: .9rem; background: #fff;
}
.filters #f-search { flex: 1; min-width: 200px; }
.dir-count { margin-left: auto; color: var(--muted); font-size: .85rem; }

/* ============================================================
   DIRECTORY
   ============================================================ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.market-card { cursor: pointer; transition: transform .12s, box-shadow .12s; display: flex; }
.market-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(15,23,42,.12); }
.card-bar { width: 6px; flex: 0 0 6px; }
.card-body { padding: .9rem 1rem; flex: 1; min-width: 0; }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.card-top h3 { font-size: 1rem; line-height: 1.25; }
.market-card .muted { font-size: .85rem; margin: .15rem 0 .6rem; }
.meta { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.meta.sub { margin-top: .5rem; font-size: .82rem; color: var(--muted); gap: .75rem; }
.empty { color: var(--muted); padding: 2rem; text-align: center; grid-column: 1/-1; }

/* chips & tags */
.chip { font-size: .72rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; white-space: nowrap; }
.chip.county { color: var(--c); background: color-mix(in srgb, var(--c) 12%, white); }
.chip.group-farmers { background: #dcfce7; color: #166534; }
.chip.group-town { background: #dbeafe; color: #1e40af; }
.chip.group-community { background: #fae8ff; color: #86198f; }
.tag { font-size: .72rem; padding: .15rem .5rem; border-radius: 6px; background: #f1f5f9; color: #475569; white-space: nowrap; }

/* ============================================================
   PIPELINE (kanban)
   ============================================================ */
.kanban {
  display: grid;
  grid-template-columns: repeat(6, minmax(180px, 1fr));
  gap: .85rem;
  align-items: start;
  overflow-x: auto;
}
.stage-hidden { background: #475569; }
.kcol-hidden { border-style: dashed; }
.kcol-empty { color: var(--muted); font-size: .8rem; padding: .6rem; text-align: center; }
.kcol-subhead { font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: .35rem .15rem .1rem; }
.kcard-top { display: flex; justify-content: space-between; align-items: flex-start; gap: .4rem; }

/* per-event list in the detail modal */
.ev-help { font-size: .8rem; margin: -.2rem 0 .6rem; }
.ev-list { display: flex; flex-direction: column; gap: .35rem; }
.ev-row { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .35rem .55rem; border: 1px solid var(--line); border-radius: 8px; font-size: .88rem; }
.ev-row.is-hidden { opacity: .55; }
.ev-row .eye-btn { gap: .3rem; padding: .2rem .45rem; }
.ev-state { font-size: .75rem; }

/* show/hide eye button (calendar, directory, pipeline) */
.eye-btn {
  background: transparent; border: 0; padding: 2px; cursor: pointer;
  color: var(--muted); display: inline-grid; place-items: center; border-radius: 6px; flex: 0 0 auto;
}
.eye-btn:hover { color: var(--ink); background: rgba(15, 23, 42, .08); }
.card-top-right { display: flex; align-items: center; gap: .35rem; }
.market-card.is-hidden { opacity: .6; }
.tag-hidden { background: #fee2e2; color: #b91c1c; }
.kcol { background: #f8fafc; border: 1px solid var(--line); border-radius: var(--radius); min-width: 180px; }
.kcol-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: .6rem .75rem; font-weight: 700; font-size: .85rem;
  border-top-left-radius: var(--radius); border-top-right-radius: var(--radius);
  color: #fff;
}
.kcount { background: rgba(255,255,255,.3); border-radius: 999px; padding: 0 .5rem; font-size: .78rem; }
.stage-interested { background: #64748b; }
.stage-enquiry    { background: #0ea5e9; }
.stage-applied    { background: #f59e0b; }
.stage-booked     { background: #16a34a; }
.stage-paid       { background: #7c3aed; }
.kcol-sum { font-size: .72rem; color: var(--muted); padding: .35rem .75rem; border-bottom: 1px solid var(--line); }
.kcol-body { padding: .6rem; display: flex; flex-direction: column; gap: .55rem; min-height: 60px; }
.kcol-body.over { background: #ecfdf5; outline: 2px dashed #16a34a; outline-offset: -4px; border-radius: 8px; }

.kcard {
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--c);
  border-radius: 8px; padding: .55rem .65rem; cursor: grab;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .4rem;
}
.kcard:active { cursor: grabbing; }
.kcard.dragging { opacity: .4; }
.kcard strong { font-size: .85rem; line-height: 1.2; }
.kcard-meta { display: flex; gap: .3rem; flex-wrap: wrap; }
.kcard-foot { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); }

/* ============================================================
   MAP
   ============================================================ */
#map { height: 70vh; min-height: 420px; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); }

/* ============================================================
   INSIGHTS
   ============================================================ */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .15rem;
}
.kpi-v { font-size: 1.8rem; font-weight: 800; color: var(--brand-d); }
.kpi-k { font-weight: 600; }
.kpi-sub { font-size: .78rem; color: var(--muted); }

.insight-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; }
.panel h3 { font-size: .95rem; margin-bottom: .8rem; }
.chart { display: flex; flex-direction: column; gap: .5rem; }

.bar-row, .prog-row { display: grid; grid-template-columns: 120px 1fr auto; gap: .6rem; align-items: center; font-size: .82rem; }
.bar-track, .prog-track { background: #f1f5f9; border-radius: 999px; height: 12px; overflow: hidden; }
.bar-fill, .prog-fill { height: 100%; border-radius: 999px; transition: width .4s; }
.bar-val, .prog-val { color: var(--muted); font-variant-numeric: tabular-nums; }
.prog-row { grid-template-columns: 120px 1fr 110px; }

/* ============================================================
   CALENDAR
   ============================================================ */
.cal-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem;
}
.cal-nav { display: flex; align-items: center; gap: .5rem; }
.cal-title { font-size: 1.15rem; min-width: 12rem; text-align: center; }
.cal-nav .btn { padding: .35rem .7rem; font-size: 1rem; line-height: 1; }
.cal-status { margin: 0; }

.cal-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
  margin-bottom: 6px;
}
.cal-weekdays span {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); text-align: center; padding: .2rem 0;
}
.calendar { display: flex; flex-direction: column; gap: 6px; }

/* One week = a header strip (7 day numbers) + stacked lanes. */
.cal-week { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-week-head, .cal-lane {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
}
.cal-week-head { padding: 6px 6px 0; }
.cal-daynum {
  font-size: .82rem; font-weight: 600; color: var(--ink); min-height: 1.5rem;
}
.cal-daynum.other { color: #cbd5e1; }
.cal-daynum .dn { display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 999px; }
.cal-daynum.today .dn { background: #dc2626; color: #fff; }

.cal-lanes { padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.cal-empty { padding: .4rem; color: #cbd5e1; font-size: .8rem; text-align: center; }

/* A market occurrence bar — spans its day columns within the week. */
.cal-ev {
  border: 1px solid var(--line); border-left: 4px solid var(--c);
  background: color-mix(in srgb, var(--c) 7%, white);
  border-radius: 8px; padding: .4rem .55rem; cursor: pointer;
  font-size: .78rem; line-height: 1.3; min-width: 0; overflow: hidden;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .15rem;
}
.cal-ev:hover { box-shadow: 0 4px 12px rgba(15,23,42,.14); }
.cal-ev.multi { background: linear-gradient(90deg, color-mix(in srgb, var(--c) 16%, white), color-mix(in srgb, var(--c) 6%, white)); }
.cal-ev-head { display: flex; align-items: center; gap: .35rem; }
.cal-ev-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.cal-ev-town { color: var(--muted); font-weight: 600; }
.cal-ev-row { display: flex; flex-wrap: wrap; gap: .15rem .6rem; color: #475569; }
.cal-ev-row .k { color: var(--muted); }
.cal-ev-span { font-size: .68rem; color: var(--muted); font-weight: 600; }

/* Booked status dot. */
.dot { width: 12px; height: 12px; border-radius: 999px; flex: 0 0 12px; display: inline-block; }
.dot.booked { background: #dc2626; box-shadow: 0 0 0 2px rgba(220,38,38,.25); }
.dot.unbooked { background: transparent; border: 2px solid rgba(220,38,38,.35); }

@media (max-width: 720px) {
  .calendar { overflow-x: auto; }
  .cal-week { min-width: 760px; }
  .cal-ev { font-size: .72rem; }
}

/* ============================================================
   DETAIL MODAL
   ============================================================ */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal-card {
  background: var(--surface); width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto;
  border-radius: 16px; padding: 1.5rem; position: relative; box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.modal-close { position: absolute; top: .75rem; right: 1rem; border: 0; background: none; font-size: 1.8rem; line-height: 1; color: var(--muted); cursor: pointer; }
.detail-head { display: flex; justify-content: space-between; border-left: 4px solid; padding-left: .75rem; margin-bottom: 1rem; }
.detail-head .meta { margin-top: .35rem; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem 1.25rem; margin-bottom: 1.25rem; }
.detail-grid > div { font-size: .9rem; }
.dl { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-bottom: .15rem; }
.dl-input { width: 100%; padding: .35rem .5rem; border: 1px solid var(--line); border-radius: 7px; font: inherit; font-size: .9rem; }
.dl-msg { font-size: .72rem; color: var(--brand-d); margin-left: .3rem; }
.detail-section { border-top: 1px solid var(--line); padding-top: 1rem; margin-top: .5rem; }
.detail-section h3 { font-size: .95rem; }

.booking-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: .75rem; }
.booking-row label { display: flex; flex-direction: column; gap: .25rem; font-size: .78rem; color: var(--muted); }
.booking-row select, .booking-row input { padding: .45rem .55rem; border: 1px solid var(--line); border-radius: 7px; font-size: .9rem; }
.booking-actions { display: flex; align-items: center; gap: .6rem; }

.note-form { display: flex; gap: .6rem; margin-bottom: .9rem; align-items: flex-start; }
.note-form textarea { flex: 1; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; resize: vertical; }
.notes-list { display: flex; flex-direction: column; gap: .6rem; }
.note { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: .6rem .75rem; }
.note p { margin: 0 0 .4rem; font-size: .9rem; }
.note-meta { display: flex; justify-content: space-between; font-size: .76rem; color: var(--muted); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 720px) {
  .topbar { gap: .5rem; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .user-box { margin-left: auto; }
  .filters { top: 0; position: static; }
  .detail-grid, .booking-row { grid-template-columns: 1fr; }
  .bar-row, .prog-row { grid-template-columns: 90px 1fr auto; }
  .note-form { flex-direction: column; }
  .note-form .btn { width: 100%; }
  #map { height: 60vh; }
}
