/* ============================================================
   JMA Facilities Work Order System
   Base palette/typography carried over from the approved mockup.
   NOTE: navy/gold below are the mockup's placeholders. Replace with the real
   JMA brand hex values + font-family from johnmilledge.org before launch —
   see README "Before go-live".
   ============================================================ */
:root{
  --navy:#152B4E;
  --navy-dark:#0D1C34;
  --gold:#C9A227;
  --gold-light:#E9D48A;
  --bg:#F5F6F8;
  --card:#FFFFFF;
  --border:#D9DCE3;
  --text:#1E2430;
  --text-muted:#5B6472;
  --danger:#B4392C;
  --success:#2E7D4F;
  --warn:#C9871F;
}
*{box-sizing:border-box;}
body{
  margin:0; background:var(--bg); color:var(--text);
  font-family:"Source Sans Pro","Segoe UI",Arial,sans-serif;
  font-size:14px;
}
h1,h2,h3,.brand-serif{ font-family:Georgia,"Times New Roman",serif; }
a{ color:var(--navy); }

header.app-header{
  background:var(--navy); color:#fff; padding:14px 24px;
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  border-bottom:4px solid var(--gold); flex-wrap:wrap;
}
header.app-header .brand{ display:flex; align-items:center; gap:10px; }
header.app-header .brand .crest{
  width:34px; height:34px; border-radius:50%; background:var(--gold);
  color:var(--navy-dark); display:flex; align-items:center; justify-content:center;
  font-weight:bold; font-family:Georgia,serif; font-size:15px; flex-shrink:0;
}
header.app-header h1{ margin:0; font-size:18px; letter-spacing:.3px; }
header.app-header .user{ font-size:12px; color:var(--gold-light); text-align:right; }
header.app-header .user .role-label{ display:block; opacity:.85; }
header.app-header .user button{
  background:transparent; border:1px solid var(--gold-light); color:var(--gold-light);
  padding:4px 10px; border-radius:3px; font-size:11px; cursor:pointer; margin-top:4px;
  font-family:inherit;
}

nav.tabs{ background:var(--navy-dark); display:flex; gap:2px; padding:0 20px; flex-wrap:wrap; }
nav.tabs button{
  background:transparent; border:none; color:#B9C2D4; padding:12px 18px;
  font-size:13px; cursor:pointer; border-bottom:3px solid transparent; font-family:inherit;
}
nav.tabs button.active{ color:#fff; border-bottom-color:var(--gold); font-weight:600; }
nav.tabs button[hidden]{ display:none; }

main{ padding:22px 26px; max-width:1180px; margin:0 auto; }
.view{ display:none; }
.view.active{ display:block; }

.card{ background:var(--card); border:1px solid var(--border); border-radius:6px; padding:20px; }
.grid2{ display:grid; grid-template-columns:1fr 1fr; gap:16px; }
.field{ margin-bottom:14px; }
.field label{ display:block; font-size:12px; font-weight:600; color:var(--text-muted); margin-bottom:5px; text-transform:uppercase; letter-spacing:.4px; }
.field input, .field select, .field textarea{
  width:100%; padding:9px 10px; border:1px solid var(--border); border-radius:4px;
  font-size:14px; font-family:inherit; background:#fff; color:var(--text);
}
.field input:disabled, .field select:disabled, .field textarea:disabled{ background:#F0F0F0; color:var(--text-muted); }
.field textarea{ min-height:80px; resize:vertical; }
.hint{ font-size:11px; color:var(--text-muted); margin-top:4px; }
.conditional{ border-left:3px solid var(--gold); padding-left:12px; margin-top:8px; background:#FBF8EE; padding:10px 12px; border-radius:0 4px 4px 0; }
.radio-row{ display:flex; gap:18px; }
.radio-row label{ display:flex; align-items:center; gap:6px; font-size:13px; font-weight:normal; text-transform:none; color:var(--text); }

.btn{ padding:10px 20px; border-radius:4px; border:none; font-size:13px; font-weight:600; cursor:pointer; font-family:inherit; }
.btn:disabled{ opacity:.55; cursor:not-allowed; }
.btn-primary{ background:var(--navy); color:#fff; }
.btn-primary:hover:not(:disabled){ background:var(--navy-dark); }
.btn-secondary{ background:#fff; color:var(--navy); border:1px solid var(--navy); }
.btn-danger{ background:var(--danger); color:#fff; }
.btn-sm{ padding:6px 14px; font-size:12px; }

/* Badges */
.badge{ display:inline-block; padding:3px 9px; border-radius:12px; font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.3px; }
.badge-low{ background:#E4ECE2; color:var(--success); }
.badge-medium{ background:#FCEFD9; color:var(--warn); }
.badge-high{ background:#FBE1DC; color:var(--danger); }
.badge-immediate{ background:var(--danger); color:#fff; }
.badge-status{ background:#E9EEF6; color:var(--navy); }
.badge-locked{ background:#2B2B2B; color:#fff; }
.badge-none{ background:#EDEFF3; color:var(--text-muted); }

/* Record view */
.record-header{ display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:18px; gap:16px; flex-wrap:wrap; }
.record-header .ticket-num{ font-size:22px; font-family:Georgia,serif; color:var(--navy); }
.record-grid{ display:grid; grid-template-columns:2fr 1fr; gap:18px; }
.subsection{ margin-bottom:22px; }
.subsection h3{ font-size:14px; margin:0 0 10px 0; color:var(--navy); border-bottom:2px solid var(--border); padding-bottom:6px; }
.history-item{ display:flex; gap:10px; padding:8px 0; border-bottom:1px solid #EEE; font-size:12.5px; }
.history-item .dot{ width:8px; height:8px; border-radius:50%; background:var(--gold); margin-top:5px; flex-shrink:0; }
.history-item .who{ color:var(--text-muted); }
table.mini{ width:100%; border-collapse:collapse; font-size:12.5px; }
table.mini th{ text-align:left; color:var(--text-muted); font-weight:600; padding:6px 4px; border-bottom:1px solid var(--border); vertical-align:top; }
table.mini td{ padding:6px 4px; border-bottom:1px solid #F0F0F0; vertical-align:top; }
.lock-banner{ background:#2B2B2B; color:#fff; padding:10px 14px; border-radius:4px; font-size:12.5px; display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:16px; flex-wrap:wrap; }
.lock-banner button{ background:var(--gold); color:var(--navy-dark); border:none; padding:6px 12px; border-radius:3px; font-size:11px; font-weight:700; cursor:pointer; font-family:inherit; }

/* List view */
.filters{ display:flex; gap:10px; margin-bottom:14px; flex-wrap:wrap; }
.filters select, .filters input{ padding:7px 10px; border:1px solid var(--border); border-radius:4px; font-size:12.5px; font-family:inherit; }
.table-scroll{ overflow-x:auto; }
table.list{ width:100%; border-collapse:collapse; background:#fff; }
table.list th{ background:var(--navy); color:#fff; text-align:left; padding:10px; font-size:11.5px; text-transform:uppercase; letter-spacing:.3px; white-space:nowrap; }
table.list td{ padding:10px; border-bottom:1px solid var(--border); font-size:13px; }
table.list tbody tr:hover td{ background:#F7F9FC; cursor:pointer; }
table.list tr.stuck-row td:first-child{ box-shadow:inset 3px 0 0 var(--danger); }
table.list th.sortable{ cursor:pointer; user-select:none; }
table.list th.sortable .arrow{ opacity:.35; font-size:10px; margin-left:4px; }
table.list th.sortable.sorted .arrow{ opacity:1; }

/* Kanban
   The board needs more room than the 1180px reading column the other views
   use: 8 stages at the old fixed 220px plus gaps came to ~1840px, so it could
   never fit and always scrolled. Columns now flex to share whatever width is
   available and only fall back to horizontal scrolling once they'd go below
   min-width — i.e. on genuinely narrow screens, not on a normal monitor. */
main:has(#view-kanban.active){ max-width:1720px; }

.kanban{ display:flex; gap:8px; overflow-x:auto; padding-bottom:10px; align-items:flex-start; }
.kcol{ flex:1 1 0; min-width:134px; background:#EDEFF3; border-radius:6px; padding:8px; min-height:80px; }
.kcol.drag-over{ background:#E2E8F4; outline:2px dashed var(--navy); }
.kcol h4{ font-size:11px; text-transform:uppercase; color:var(--navy); margin:0 0 9px 0; letter-spacing:.2px; display:flex; justify-content:space-between; align-items:baseline; gap:5px; }
/* "Awaiting Contractor" is too long for a narrow column — let it wrap rather
   than truncate, and keep the count pinned to the right. */
.kcol h4 > span:first-child{ overflow-wrap:anywhere; }
.kcol h4 > span:last-child{ flex-shrink:0; }
.kcard{ background:#fff; border-radius:5px; padding:10px; margin-bottom:8px; border-left:3px solid var(--gold); box-shadow:0 1px 2px rgba(0,0,0,.08); font-size:12.5px; cursor:grab; }
.kcard.dragging{ opacity:.45; }
.kcard .kt{ font-weight:700; color:var(--navy); margin-bottom:4px; }
.kcard .kmeta{ color:var(--text-muted); font-size:11px; margin-top:6px; }
.kcard .kmoved{ font-size:10.5px; color:#8A93A3; margin-top:6px; border-top:1px dashed var(--border); padding-top:5px; }
.kcard.stuck{ border-left-color:var(--danger); background:#FFF7F5; }
.stuck-flag{ color:var(--danger); font-weight:700; }

.note{ background:#FBF8EE; border:1px solid var(--gold-light); border-radius:4px; padding:10px 12px; font-size:12px; color:#6B5A17; margin-top:16px; }
.error-inline{ background:#FBE1DC; border:1px solid var(--danger); color:#7A2318; border-radius:4px; padding:10px 12px; font-size:12.5px; margin:10px 0; }
.empty{ color:var(--text-muted); font-size:13px; padding:22px; text-align:center; }

/* Photos */
.photo-grid{ display:flex; flex-wrap:wrap; gap:10px; }
.photo-thumb{ width:110px; border:1px solid var(--border); border-radius:4px; overflow:hidden; background:#fff; }
.photo-thumb img{ width:100%; height:80px; object-fit:cover; display:block; cursor:pointer; }
.photo-thumb .pmeta{ font-size:10px; color:var(--text-muted); padding:4px 5px; word-break:break-all; }
.photo-thumb .pdel{ display:block; width:100%; border:none; border-top:1px solid var(--border); background:#fff; color:var(--danger); font-size:10px; padding:3px; cursor:pointer; font-family:inherit; }

/* Dashboard — carried over from the approved mockup, which Phase 1 didn't need. */
.stat-grid{ display:grid; grid-template-columns:repeat(4,1fr); gap:14px; margin-bottom:22px; }
.stat-grid-5{ grid-template-columns:repeat(5,1fr); }
.stat-box{ background:var(--navy); color:#fff; border-radius:6px; padding:16px; border-bottom:3px solid var(--gold); }
.stat-box .num{ font-size:26px; font-family:Georgia,serif; }
.stat-box .label{ font-size:11px; text-transform:uppercase; color:var(--gold-light); letter-spacing:.4px; margin-top:4px; }
.breakdown-grid{ display:grid; grid-template-columns:1fr 1fr; gap:18px; }
.bar-row{ display:flex; align-items:center; gap:10px; margin-bottom:9px; font-size:12.5px; }
.bar-row .bar-label{ width:130px; flex-shrink:0; color:var(--text-muted); }
.bar-row .bar-track{ flex:1; background:#EDEFF3; border-radius:3px; height:14px; overflow:hidden; }
.bar-row .bar-fill{ background:var(--navy); height:100%; border-radius:3px; }
.bar-row .bar-fill.gold{ background:var(--gold); }
.bar-row .bar-count{ width:28px; text-align:right; font-weight:600; }

/* Five stat cards don't fit a laptop width; degrade rather than squash. */
@media (max-width:1000px){
  .stat-grid, .stat-grid-5{ grid-template-columns:repeat(2,1fr); }
  .breakdown-grid{ grid-template-columns:1fr; }
}
@media (max-width:560px){
  .stat-grid, .stat-grid-5{ grid-template-columns:1fr; }
}

/* Sign-in */
.signin-wrap{ max-width:420px; margin:70px auto; }
.signin-wrap .card{ padding:28px; }
.signin-wrap h2{ margin:0 0 6px 0; color:var(--navy); }

/* Toast */
#toast-host{ position:fixed; right:18px; bottom:18px; display:flex; flex-direction:column; gap:8px; z-index:60; }
.toast{ background:var(--navy-dark); color:#fff; padding:11px 15px; border-radius:4px; font-size:13px; box-shadow:0 3px 10px rgba(0,0,0,.25); max-width:380px; }
.toast.err{ background:var(--danger); }
.toast.ok{ background:var(--success); }

/* Modal */
.modal-backdrop{ position:fixed; inset:0; background:rgba(13,28,52,.55); display:flex; align-items:center; justify-content:center; z-index:50; padding:20px; }
.modal{ background:#fff; border-radius:6px; padding:22px; max-width:520px; width:100%; max-height:90vh; overflow:auto; }
.modal h3{ margin:0 0 10px 0; color:var(--navy); }
.modal-actions{ display:flex; gap:10px; justify-content:flex-end; margin-top:16px; }

.loading{ color:var(--text-muted); font-size:13px; padding:18px 0; }
.readonly-banner{ background:#E9EEF6; border:1px solid var(--border); color:var(--navy); border-radius:4px; padding:8px 12px; font-size:12px; margin-bottom:14px; }

@media (max-width:820px){
  .grid2{ grid-template-columns:1fr; }
  .record-grid{ grid-template-columns:1fr; }
  main{ padding:16px 12px; }
  nav.tabs{ padding:0 8px; }
  nav.tabs button{ padding:10px 12px; font-size:12px; }
}
