:root {
  --green: #15803d;
  --green-d: #14532d;
  --green-l: #dcfce7;
  --ink: #0f172a;
  --slate: #475569;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --red: #dc2626;
  --amber: #d97706;
  --blue: #2563eb;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.06);
  --shadow-lg: 0 10px 30px rgba(15,23,42,.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ---------------- LOGIN ---------------- */
#loginView {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #14532d 100%);
  padding: 24px;
}
.login-card {
  background: var(--card);
  width: 100%; max-width: 400px;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}
.brand { text-align: center; margin-bottom: 24px; }
.brand .logo {
  width: 56px; height: 56px; border-radius: 14px;
  background: var(--green); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 800; margin-bottom: 12px;
}
.brand h1 { font-size: 22px; letter-spacing: -.3px; }
.brand p { color: var(--slate); font-size: 13px; margin-top: 4px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--slate); }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 13px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--green); border-color: var(--green); }
textarea { resize: vertical; min-height: 80px; font-family: inherit; }

.btn {
  width: 100%; padding: 12px; border: none; border-radius: 9px;
  background: var(--green); color: #fff; font-size: 15px; font-weight: 700;
}
.btn:hover { background: var(--green-d); }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.secondary:hover { background: var(--bg); }
.btn.sm { width: auto; padding: 8px 14px; font-size: 13px; }

.demo-accounts { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }
.demo-accounts h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--slate); margin-bottom: 10px; }
.demo-pill {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px;
  font-size: 13px; cursor: pointer; background: #fff;
}
.demo-pill:hover { border-color: var(--green); background: var(--green-l); }
.demo-pill .who { font-weight: 700; }
.demo-pill .meta { color: var(--slate); font-size: 12px; }
.login-error { color: var(--red); font-size: 13px; margin-top: 8px; min-height: 16px; }

/* ---------------- APP SHELL ---------------- */
#appView { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  background: var(--ink); color: #fff; padding: 0 20px; height: 58px; flex-shrink: 0;
}
.topbar .logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--green);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 17px;
}
.topbar .title { font-weight: 700; font-size: 16px; }
.topbar .title small { display:block; font-weight: 400; font-size: 11px; color:#94a3b8; }
.topbar .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; color: #cbd5e1; border: none; padding: 8px 14px;
  border-radius: 8px; font-size: 14px; font-weight: 600;
}
.tab:hover { background: rgba(255,255,255,.08); color: #fff; }
.tab.active { background: var(--green); color: #fff; }
.user-chip { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user-chip .avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--green);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.user-chip .uname { font-weight: 700; }
.user-chip .urole { color: #94a3b8; font-size: 12px; }

.content { flex: 1; overflow: auto; padding: 18px 20px; }

/* ---------------- STATS ---------------- */
.stats { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; min-width: 120px; box-shadow: var(--shadow);
}
.stat .num { font-size: 24px; font-weight: 800; }
.stat .lab { font-size: 12px; color: var(--slate); margin-top: 2px; }

.toolbar { display:flex; align-items:center; gap:10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.toolbar select, .toolbar input {
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; background:#fff;
}

/* ---------------- KANBAN BOARD ---------------- */
.board { display: flex; gap: 14px; align-items: flex-start; }
.column {
  background: #e8edf3; border-radius: 12px; width: 280px; flex-shrink: 0;
  display: flex; flex-direction: column; max-height: calc(100vh - 220px);
}
.column-head {
  display:flex; align-items:center; justify-content:space-between;
  padding: 12px 14px; font-weight: 700; font-size: 14px;
  position: sticky; top: 0;
}
.column-head .count {
  background: #fff; color: var(--slate); border-radius: 20px;
  font-size: 12px; font-weight: 700; padding: 2px 9px;
}
.column-body { padding: 0 10px 12px; overflow-y: auto; flex: 1; min-height: 60px; }
.column.drag-over { outline: 2px dashed var(--green); outline-offset: -4px; }
.column.drag-over .column-body { background: rgba(21,128,61,.06); border-radius: 8px; }

/* stage accent bars */
.col-New .column-head      { color:#1d4ed8; }
.col-Assigned .column-head { color:#7c3aed; }
.col-InProgress .column-head { color:#b45309; }
.col-OnHold .column-head   { color:#64748b; }
.col-Completed .column-head{ color:#15803d; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; margin-bottom: 10px; box-shadow: var(--shadow); cursor: grab;
  border-left: 4px solid var(--slate);
}
.card:active { cursor: grabbing; }
.card.dragging { opacity: .45; }
.card.pr-High   { border-left-color: var(--red); }
.card.pr-Medium { border-left-color: var(--amber); }
.card.pr-Low    { border-left-color: var(--blue); }
.card .card-top { display:flex; justify-content:space-between; align-items:center; margin-bottom: 6px; }
.card .wo { font-size: 11px; font-weight: 700; color: var(--slate); letter-spacing:.3px; }
.card .card-title { font-weight: 700; font-size: 14px; line-height: 1.3; margin-bottom: 8px; }
.card .meta-row { display:flex; align-items:center; gap:6px; flex-wrap:wrap; margin-bottom: 6px; }
.card .loc { font-size: 12px; color: var(--slate); margin-bottom: 8px; line-height:1.3; }

.badge {
  display:inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px;
}
.badge.trade { background: #eef2ff; color:#4338ca; }
.badge.pr-High { background:#fee2e2; color:var(--red); }
.badge.pr-Medium { background:#fef3c7; color:var(--amber); }
.badge.pr-Low { background:#dbeafe; color:var(--blue); }

.assignee { display:flex; align-items:center; gap:7px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.assignee .av {
  width: 24px; height: 24px; border-radius: 50%; color:#fff; font-size: 11px; font-weight: 700;
  display:inline-flex; align-items:center; justify-content:center; flex-shrink:0;
}
.assignee .an { font-size: 12px; font-weight: 600; }
.assignee .at { font-size: 11px; color: var(--slate); }
.assignee.unassigned .av { background:#cbd5e1; color:#fff; }
.assignee.unassigned .an { color: var(--slate); font-style: italic; font-weight:500; }
.photo-flag { font-size: 11px; color: var(--slate); margin-top:6px; }

/* ---------------- DISPATCH (by team) ---------------- */
.lane-head { display:flex; align-items:center; gap:8px; padding: 12px 14px; }
.lane-head .av { width: 28px; height:28px; border-radius:50%; color:#fff; font-weight:700; font-size:12px; display:inline-flex; align-items:center; justify-content:center; }
.lane-head .ln { font-weight: 700; font-size: 14px; }
.lane-head .lt { font-size: 11px; color: var(--slate); }
.vendor-tag { font-size:10px; font-weight:700; background:#fff7ed; color:#ea580c; padding:1px 6px; border-radius:6px; }

/* ---------------- MODAL ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display:flex; align-items:flex-start; justify-content:center; padding: 28px 16px; z-index: 50; overflow:auto;
}
.modal {
  background: var(--card); width: 100%; max-width: 760px; border-radius: 16px;
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal-head {
  display:flex; align-items:flex-start; justify-content:space-between; gap:12px;
  padding: 18px 22px; border-bottom: 1px solid var(--line);
}
.modal-head .wo { font-size: 12px; font-weight:700; color: var(--slate); }
.modal-head h2 { font-size: 19px; margin-top: 2px; }
.modal-head .x { background:none; border:none; font-size: 26px; color: var(--slate); line-height:1; }
.modal-body { padding: 20px 22px; max-height: 70vh; overflow:auto; }

.detail-grid { display:grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.detail-grid .di { background: var(--bg); border-radius: 9px; padding: 10px 12px; }
.detail-grid .di .k { font-size: 11px; text-transform:uppercase; letter-spacing:.4px; color: var(--slate); font-weight:700; }
.detail-grid .di .v { font-size: 14px; font-weight: 600; margin-top: 3px; }

.section { margin-bottom: 20px; }
.section h3 { font-size: 13px; text-transform: uppercase; letter-spacing:.5px; color: var(--green-d); margin-bottom: 10px; border-bottom: 2px solid var(--green-l); padding-bottom: 6px; }
.section p.body { font-size: 14px; line-height: 1.55; color:#1e293b; }
.info-box { background:#f8fafc; border:1px solid var(--line); border-radius:9px; padding: 11px 13px; font-size: 13px; line-height:1.5; }
.info-box .k { font-weight: 700; }
.matflag { display:inline-block; font-size:11px; font-weight:700; padding:2px 8px; border-radius:20px; background:#e0f2fe; color:#0369a1; margin-bottom:6px;}

.photo-grid { display:flex; gap:10px; flex-wrap: wrap; }
.photo-item { width: 150px; }
.photo-item img { width: 150px; height: 112px; object-fit: cover; border-radius: 9px; border:1px solid var(--line); display:block; }
.photo-item .cap { font-size: 11px; color: var(--slate); margin-top: 4px; line-height:1.3; }
.photo-empty { font-size: 13px; color: var(--slate); font-style: italic; }
.add-photo {
  width:150px; height:112px; border:2px dashed var(--line); border-radius:9px;
  display:flex; align-items:center; justify-content:center; flex-direction:column; gap:4px;
  color: var(--slate); font-size: 12px; font-weight:600; background:#fafafa;
}
.add-photo:hover { border-color: var(--green); color: var(--green); }

.cost-table { width:100%; border-collapse: collapse; font-size: 14px; }
.cost-table th, .cost-table td { text-align:left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.cost-table th { font-size: 11px; text-transform:uppercase; color: var(--slate); }
.cost-table td.amt, .cost-table th.amt { text-align: right; }
.cost-table tfoot td { font-weight: 800; border-top: 2px solid var(--ink); border-bottom:none; }
.cost-add { display:flex; gap:8px; margin-top:10px; flex-wrap:wrap; }
.cost-add input, .cost-add select { padding:8px 10px; border:1px solid var(--line); border-radius:8px; font-size:13px; }

.modal-foot { display:flex; align-items:center; gap:10px; padding: 16px 22px; border-top: 1px solid var(--line); background:#f8fafc; flex-wrap:wrap; }
.modal-foot label { font-size:12px; font-weight:700; color:var(--slate); }
.modal-foot select { padding:8px 10px; border:1px solid var(--line); border-radius:8px; font-size:13px; background:#fff; }
.modal-foot .spacer { flex:1; }

/* ---------------- CUSTOMER PORTAL ---------------- */
.cust-wrap { max-width: 1000px; margin: 0 auto; }
.panel { background: var(--card); border:1px solid var(--line); border-radius: 14px; padding: 22px; box-shadow: var(--shadow); margin-bottom: 18px; }
.panel h2 { font-size: 18px; margin-bottom: 4px; }
.panel .sub { color: var(--slate); font-size: 13px; margin-bottom: 16px; }
.form-grid { display:grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

.req-list { display:grid; gap: 10px; }
.req-row {
  display:flex; align-items:center; gap: 14px; padding: 14px 16px;
  border:1px solid var(--line); border-radius: 11px; background:#fff;
}
.req-row .rw-wo { font-size:12px; font-weight:700; color:var(--slate); width:70px; flex-shrink:0;}
.req-row .rw-title { font-weight:700; font-size: 14px; }
.req-row .rw-loc { font-size:12px; color: var(--slate); }
.req-row .grow { flex:1; }
.status-badge { font-size:12px; font-weight:700; padding:4px 11px; border-radius:20px; }
.st-New { background:#dbeafe; color:#1d4ed8; }
.st-Assigned { background:#ede9fe; color:#7c3aed; }
.st-InProgress { background:#fef3c7; color:#b45309; }
.st-OnHold { background:#e2e8f0; color:#475569; }
.st-Completed { background:#dcfce7; color:#15803d; }

/* ---------------- LIST / TABLE VIEW ---------------- */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: auto; }
.jobs-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.jobs-table thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--slate); padding: 12px 14px; border-bottom: 2px solid var(--line);
  background: #f8fafc; position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
.jobs-table tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.jobs-table tbody tr { cursor: pointer; }
.jobs-table tbody tr:hover { background: var(--green-l); }
.jobs-table .c-wo { font-weight: 700; color: var(--slate); font-size: 12px; white-space: nowrap; }
.jobs-table .c-title .jt { font-weight: 700; }
.jobs-table .c-title .jl { font-size: 12px; color: var(--slate); margin-top: 2px; }
.jobs-table .c-sel { white-space: nowrap; }
.inline-sel { padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; background: #fff; font-family: inherit; max-width: 170px; }
.inline-sel:focus { outline: 2px solid var(--green); border-color: var(--green); }
.st-sel { font-weight: 700; border: none; }
.st-sel.st-New { background: #dbeafe; color: #1d4ed8; }
.st-sel.st-Assigned { background: #ede9fe; color: #7c3aed; }
.st-sel.st-InProgress { background: #fef3c7; color: #b45309; }
.st-sel.st-OnHold { background: #e2e8f0; color: #475569; }
.st-sel.st-Completed { background: #dcfce7; color: #15803d; }

@media (max-width: 720px) {
  .detail-grid, .form-grid { grid-template-columns: 1fr; }
  .tabs .tab { padding: 8px 10px; }
}
