:root {
  /* Neutrals (slate) */
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;

  /* Brand / primary (navy — sampled from the Pryor Bacon logo) */
  --brand: #1a2f5a;
  --primary: #1a2f5a;
  --primary-hover: #14254a;
  --primary-soft: #eef1f7;
  --primary-tint: #f4f6fb;

  /* Status / semantic — red kept for High/Needs-Attention; others
     harmonized into the navy/neutral family. */
  --high: #dc2626;
  --high-bg: #fde8e8;
  --high-ring: #f7c4c4;
  --attn: #c2410c;
  --attn-bg: #ffedd5;
  --attn-ring: #fed7aa;
  --warn: #92671a;
  --warn-bg: #faf0d7;
  --ok: #1f6b46;
  --ok-bg: #dcefe3;
  --info: #1a2f5a;
  --info-bg: #e6eaf3;
  --cyan: #3a5285;
  --cyan-bg: #eef1f8;

  /* Shape & depth */
  --radius: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.10), 0 2px 4px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.18);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";

  /* Spacing scale */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

/* ─── Top bar (white header hosts the navy logo) ─── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: #fff;
  color: var(--brand);
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.topbar .brand { display: inline-flex; align-items: center; }
.topbar .brand:hover { text-decoration: none; opacity: .9; }
.brand-logo { height: 34px; width: auto; display: block; }
.topbar nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; align-items: center; }
.topbar nav a, .topbar nav button {
  color: var(--ink-soft); background: transparent; border: 0;
  padding: 9px 13px; border-radius: var(--radius-sm); font-size: .92rem; font-weight: 600;
  cursor: pointer; min-height: 40px; display: inline-flex; align-items: center; gap: 5px;
  transition: background .15s ease, color .15s ease;
  font-family: inherit;
}
.topbar nav a:hover, .topbar nav button:hover { background: var(--primary-soft); color: var(--brand); text-decoration: none; }
.topbar nav a.active { background: var(--primary-soft); color: var(--brand); }
.icon-btn { color: var(--ink-soft); }
.icon-btn:hover { color: var(--brand); }
.whoami { font-size: .85rem; color: var(--muted); padding-left: 4px; display: inline-flex; align-items: center; gap: 4px; }

/* ─── Icons ─── */
.ic { display: inline-block; vertical-align: -0.16em; flex: 0 0 auto; }
.whoami .ic, .counts .ic, .wo-meta .ic { vertical-align: -0.15em; }

.container { max-width: 1000px; margin: 0 auto; padding: var(--sp-5) var(--sp-4); }

/* ─── Cards ─── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-5);
  margin-bottom: var(--sp-4);
}
.card h2 { margin: 0 0 var(--sp-4); font-size: 1.1rem; font-weight: 700; color: var(--ink); }
.card h2:first-child { margin-top: 0; }

/* ─── Forms ─── */
label {
  display: block; font-size: .8rem; color: var(--ink-soft); margin: var(--sp-3) 0 6px;
  font-weight: 600; letter-spacing: .005em;
}
input, select, textarea {
  width: 100%; padding: 11px 13px; font-size: 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink); font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
  min-height: 44px;
}
input::placeholder, textarea::placeholder { color: #94a3b8; }
input:hover, select:hover, textarea:hover { border-color: #94a3b8; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 47, 90, .16);
}
textarea { min-height: 92px; resize: vertical; line-height: 1.5; }
select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: #fff; border: 0;
  padding: 11px 18px; border-radius: var(--radius-sm); font-size: 1rem; font-weight: 600;
  cursor: pointer; text-align: center; min-height: 44px; line-height: 1.2;
  box-shadow: var(--shadow-sm);
  transition: background .15s ease, box-shadow .15s ease, transform .05s ease;
  font-family: inherit;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(26, 47, 90, .30); }
.btn.secondary { background: #fff; color: var(--ink-soft); border: 1px solid var(--line-strong); box-shadow: var(--shadow-sm); }
.btn.secondary:hover { background: #f8fafc; border-color: #94a3b8; color: var(--ink); }
.btn.danger { background: var(--high); }
.btn.danger:hover { background: #b91c1c; }
.btn.danger:focus-visible { box-shadow: 0 0 0 3px rgba(220, 38, 38, .35); }
.btn.block { width: 100%; }
.btn.small { padding: 8px 13px; font-size: .85rem; min-height: 38px; }
.btn:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }

/* Subtle destructive link-style button (delete work order) */
.danger-zone { margin-top: var(--sp-2); margin-bottom: var(--sp-6); text-align: center; }
.btn-link-danger {
  background: transparent; border: 1px solid var(--high-ring); color: var(--high);
  padding: 9px 16px; border-radius: var(--radius-sm); font-size: .9rem; font-weight: 600;
  cursor: pointer; min-height: 40px; font-family: inherit;
  transition: background .15s ease, border-color .15s ease;
}
.btn-link-danger:hover { background: var(--high-bg); border-color: var(--high); }
.btn-link-danger:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(220, 38, 38, .25); }

.row { display: flex; gap: var(--sp-3); flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.spacer { height: var(--sp-2); }
.hidden { display: none !important; }

/* ─── Badges ─── */
.badge {
  display: inline-flex; align-items: center; padding: 4px 11px; border-radius: var(--radius-pill);
  font-size: .76rem; font-weight: 700; white-space: nowrap; line-height: 1.4;
  letter-spacing: .01em; border: 1px solid transparent;
}
.badge.status-open { background: var(--info-bg); color: var(--info); border-color: #ccd5e6; }
.badge.status-inprogress { background: var(--cyan-bg); color: var(--cyan); border-color: #ccd5e6; }
.badge.status-attention { background: var(--high-bg); color: var(--high); border-color: var(--high-ring); }
.badge.status-materials { background: var(--warn-bg); color: var(--warn); border-color: #ecdcae; }
.badge.status-completed { background: var(--ok-bg); color: var(--ok); border-color: #b6dac5; }
.badge.prio-high { background: var(--high-bg); color: var(--high); border-color: var(--high-ring); }
.badge.prio-none { background: #f1f5f9; color: var(--muted); border-color: var(--line); }
/* Work order Type badges (M / T / C) — harmonized navy/neutral family */
.badge.type-badge { background: #eef1f8; color: var(--brand); border-color: #d4dcec; font-weight: 600; }
.badge.type-maint { background: #e6eaf3; color: #1a2f5a; border-color: #cdd6e8; }
.badge.type-tenant { background: #e7f0ee; color: #245c4f; border-color: #c6ddd6; }
.badge.type-constr { background: #f3ece1; color: #7c5a2a; border-color: #e4d6c0; }

/* ─── Work order list / filters ─── */
.filters { display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: flex-end; }
.filters > div { flex: 1 1 150px; min-width: 130px; }
.filters label { margin-top: 0; }

.tabs {
  display: inline-flex; gap: 4px; margin-bottom: var(--sp-4); padding: 4px;
  background: #e2e8f0; border-radius: var(--radius-sm); width: 100%;
}
.tab {
  flex: 1; text-align: center; padding: 9px 12px; border-radius: 7px; cursor: pointer;
  background: transparent; color: var(--ink-soft); font-weight: 600; font-size: .92rem;
  transition: background .15s ease, color .15s ease; min-height: 40px;
  display: flex; align-items: center; justify-content: center;
}
.tab.active { background: #fff; color: var(--brand); box-shadow: var(--shadow-sm); }
.tab-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 20px; padding: 0 7px; margin-left: 7px;
  border-radius: var(--radius-pill); font-size: .75rem; font-weight: 700;
  background: #cbd5e1; color: var(--ink-soft); line-height: 1;
}
.tab.active .tab-count { background: var(--brand); color: #fff; }

.wo-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.wo-card {
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line-strong);
  border-radius: var(--radius); padding: var(--sp-4) var(--sp-5); box-shadow: var(--shadow-sm);
  display: block; color: var(--ink);
  transition: box-shadow .15s ease, border-color .15s ease, transform .06s ease;
}
.wo-card:hover {
  text-decoration: none; box-shadow: var(--shadow-md); border-color: var(--line-strong);
  border-left-color: var(--primary); transform: translateY(-1px);
}
.wo-card.is-high { border-left-color: var(--high); }
.wo-card.is-attention { border-left-color: var(--attn); }
.wo-card .wo-top { display: flex; justify-content: space-between; gap: var(--sp-3); align-items: baseline; }
.wo-card .wo-title { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.wo-card .wo-meta { color: var(--muted); font-size: .85rem; margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.wo-card .wo-meta span { display: inline-flex; align-items: center; gap: 5px; }
.wo-card .wo-meta .ic { color: var(--muted); opacity: .85; }
.wo-card .wo-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: var(--sp-3); align-items: center; }
.wo-card .counts { color: var(--muted); font-size: .82rem; font-weight: 600; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.wo-card .counts .dot { opacity: .5; margin: 0 2px; }
.created-flag { color: var(--ok); font-weight: 600; display: inline-flex; align-items: center; gap: 4px; margin-left: var(--sp-2); }
.inline-link { display: inline-flex; align-items: center; gap: 5px; }

/* ─── Detail ─── */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-3); flex-wrap: wrap; }
.detail-head h2 { font-size: 1.3rem; }
.kv { display: grid; grid-template-columns: minmax(110px, 150px) 1fr; gap: 8px 16px; font-size: .95rem; }
.kv .k { color: var(--muted); font-weight: 600; }

.note { border-top: 1px solid var(--line); padding: var(--sp-3) 0; }
.note:first-child { border-top: 0; }
.note .note-head { font-size: .8rem; color: var(--muted); margin-bottom: 3px; }
.note .note-author { font-weight: 700; color: var(--ink-soft); }
.note .note-body { white-space: pre-wrap; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: var(--sp-3); }
.gallery figure { margin: 0; }
.gallery img {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm);
  border: 1px solid var(--line); cursor: pointer; box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .12s ease;
}
.gallery img:hover { transform: scale(1.02); box-shadow: var(--shadow); }
.gallery figcaption { font-size: .72rem; color: var(--muted); text-align: center; margin-top: 4px; font-weight: 500; }

.activity-item { font-size: .85rem; color: var(--muted); padding: 7px 0; border-top: 1px dashed var(--line); }
.activity-item:first-child { border-top: 0; }

/* ─── Lightbox ─── */
.lightbox {
  position: fixed; inset: 0; background: rgba(2, 6, 23, .9); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: var(--sp-4);
  backdrop-filter: blur(2px);
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); }
.lightbox .close { position: absolute; top: 14px; right: 20px; color: #fff; font-size: 2.2rem; cursor: pointer; line-height: 1; }

/* ─── Confirm modal ─── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .55); z-index: 150;
  display: flex; align-items: center; justify-content: center; padding: var(--sp-4);
  backdrop-filter: blur(2px); animation: fade .12s ease;
}
.modal {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 400px; padding: var(--sp-5);
  animation: pop .14s ease;
}
.modal h2 { margin: 0 0 var(--sp-2); font-size: 1.15rem; }
.modal-msg { color: var(--ink-soft); margin: 0 0 var(--sp-5); font-size: .95rem; }
.modal-actions { display: flex; gap: var(--sp-3); justify-content: flex-end; }
.modal-actions .btn { flex: 0 1 auto; min-width: 92px; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* ─── Toast / banners ─── */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); z-index: 200; font-size: .92rem; font-weight: 500; max-width: 90vw;
  animation: toastin .2s ease;
}
.toast.error { background: var(--high); }
.toast.ok { background: var(--ok); }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

.banner { padding: 11px 15px; border-radius: var(--radius-sm); margin-bottom: var(--sp-3); font-size: .9rem; }
.banner.info { background: var(--info-bg); color: var(--info); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }

/* ─── Login ─── */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: var(--sp-5); background: linear-gradient(170deg, #ffffff 0%, var(--primary-tint) 55%, #e6eaf3 100%); }
.login-box { width: 100%; max-width: 400px; }
.login-box .logo { text-align: center; margin-bottom: var(--sp-5); }
.login-box .logo img { width: 100%; max-width: 300px; height: auto; }
.login-box .logo p { margin: 14px 0 0; color: var(--muted); font-size: .95rem; }
.login-box .card { box-shadow: var(--shadow-lg); border: 1px solid var(--line); }

/* ─── Excel preview / dropzone ─── */
.preview-item { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-4); margin-bottom: var(--sp-3); background: #f8fafc; }
.preview-item h3 { margin: 0 0 var(--sp-2); font-size: .9rem; color: var(--primary); font-weight: 700; }
.preview-item .create-btn { margin-right: var(--sp-2); }

.dropzone {
  border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 32px 16px; text-align: center;
  color: var(--muted); background: #f8fafc; cursor: pointer;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.dropzone:hover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone.drag { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.dropzone strong { color: var(--ink-soft); }

.emp-row { display: flex; gap: var(--sp-2); align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.emp-row:first-child { border-top: 0; }
.emp-row input { flex: 1; }
.emp-row.inactive input { opacity: .55; }

@media (max-width: 560px) {
  .container { padding: var(--sp-4) var(--sp-3); }
  .topbar { padding: 10px 12px; gap: var(--sp-2); }
  .topbar .brand { font-size: 1.05rem; }
  .topbar nav a, .topbar nav button { padding: 8px 10px; font-size: .88rem; }
  .card { padding: var(--sp-4); }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv .k { margin-top: var(--sp-2); }
  .detail-head h2 { font-size: 1.2rem; }
}
