/* ==========================================================================
   EMC Work Orders — Cityworks Contractor Portal
   Professional theme
   ========================================================================== */
:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e5e9f0;
  --border-strong: #cbd5e1;

  --text: #0f172a;
  --text-soft: #64748b;
  --text-faint: #94a3b8;

  --navy: #0f172a;
  --navy-2: #1e293b;

  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;

  --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);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.22);
  --radius: 12px;
  --radius-sm: 8px;

  /* Status colors (Open=gray, In Progress=amber, Completed=green, Closed=slate) */
  --st-open-bg: #f1f5f9;   --st-open-fg: #475569;   --st-open-bd: #cbd5e1;
  --st-prog-bg: #fef3c7;   --st-prog-fg: #92400e;   --st-prog-bd: #fcd34d;
  --st-done-bg: #dcfce7;   --st-done-fg: #166534;   --st-done-bd: #86efac;
  --st-closed-bg: #e2e8f0; --st-closed-fg: #334155; --st-closed-bd: #94a3b8;
  --danger-bg: #fef2f2;    --danger-fg: #b91c1c;    --danger-bd: #fca5a5;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
svg { display: block; }
.icon { width: 1.1em; height: 1.1em; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Brandmark ---------- */
.brandmark {
  width: 36px; height: 36px; flex: none; border-radius: 9px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect width='24' height='24' rx='5' fill='%232563eb'/%3E%3Cpath d='M7 8h10M7 12h10M7 16h6' stroke='white' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
  box-shadow: var(--shadow-sm);
}
.brandmark--sm { width: 30px; height: 30px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font: inherit; font-weight: 600; font-size: 0.9rem;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem; cursor: pointer;
  background: var(--surface-2); color: var(--text);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, opacity 0.15s, transform 0.05s;
}
.btn:hover { background: #eceff4; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn--primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn--primary:hover { background: var(--primary-dark); }
.btn--ghost { background: transparent; border-color: var(--border-strong); color: var(--text-soft); }
.btn--ghost:hover { background: var(--surface-3); color: var(--text); }
.btn--block { width: 100%; justify-content: center; margin-top: 0.6rem; padding: 0.6rem; }
.btn--icon { padding: 0.45rem; }
.btn--icon .icon { width: 1.15em; height: 1.15em; }
.btn__icon { display: inline-flex; }
.btn__icon .icon { width: 1.05em; height: 1.05em; }

.linkbtn { background: none; border: none; color: var(--primary); font: inherit; font-weight: 600; font-size: 0.82rem; cursor: pointer; padding: 0; }
.linkbtn:hover { text-decoration: underline; }

.text-input {
  width: 100%; padding: 0.6rem 0.7rem; font: inherit;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
}
.text-input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.field-label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--text-soft); margin: 0.8rem 0 0.3rem; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem;
  padding: 1.5rem;
  background: radial-gradient(1100px 460px at 50% -8%, #d6e4ff 0%, transparent 62%), var(--bg);
}
.login__card {
  width: 100%; max-width: 390px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 1.9rem;
}
.login__brand { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 1.4rem; }
.login__brandname { font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; }
.login__brandsub { color: var(--text-soft); font-size: 0.82rem; }
.login__error { color: var(--danger-fg); font-size: 0.85rem; min-height: 1.2em; margin: 0.6rem 0 0; }
.login__note { color: var(--text-soft); font-size: 0.78rem; margin: 1.1rem 0 0; text-align: center; }
.login__footer { color: var(--text-faint); font-size: 0.76rem; max-width: 390px; text-align: center; }

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.6rem 1.25rem;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%);
  color: #e2e8f0;
}
.appbar__brand { display: flex; align-items: center; gap: 0.6rem; }
.appbar__titles { display: flex; flex-direction: column; line-height: 1.15; }
.appbar__title { font-weight: 800; font-size: 1rem; color: #fff; letter-spacing: -0.01em; }
.appbar__subtitle { font-size: 0.72rem; color: #94a3b8; }
.appbar__right { display: flex; align-items: center; gap: 0.9rem; }
.appbar__user { display: flex; align-items: center; gap: 0.5rem; }
.appbar__avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, #3b82f6, #6366f1); color: #fff;
  display: grid; place-items: center; font-size: 0.72rem; font-weight: 700;
}
.appbar__email { font-size: 0.83rem; color: #cbd5e1; }
.appbar .btn--ghost { border-color: rgba(148,163,184,0.35); color: #cbd5e1; }
.appbar .btn--ghost:hover { background: rgba(148,163,184,0.18); color: #fff; }

.sync { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.76rem; color: #94a3b8; }
.sync__dot { width: 8px; height: 8px; border-radius: 50%; background: #64748b; }
.sync.is-live .sync__dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,0.18); }
.sync.is-live { color: #cbd5e1; }
.sync.is-error .sync__dot { background: #ef4444; }
.sync.is-pulse .sync__dot { animation: pulse 0.8s ease; }
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.6); } 100% { transform: scale(1); } }

/* ---------- Boundary banner ---------- */
.boundary {
  display: flex; align-items: center; gap: 0.6rem;
  background: #fffbeb; border-bottom: 1px solid #fde68a; color: #854d0e;
  font-size: 0.84rem; padding: 0.55rem 1.25rem;
}
.boundary__icon .icon { color: #d97706; width: 1.1rem; height: 1.1rem; }

/* ---------- Main ---------- */
.main { max-width: 1140px; margin: 0 auto; padding: 1.25rem; }

/* ---------- Dashboard stats ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.6rem; margin-bottom: 1.1rem; }
.stat {
  text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.7rem 0.8rem; cursor: pointer; box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.05s; position: relative; overflow: hidden;
}
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--border-strong); }
.stat:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat--active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.18); }
.stat__num { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.stat__label { font-size: 0.74rem; color: var(--text-soft); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat--total::before { background: var(--primary); }
.stat--open::before { background: var(--st-open-bd); }
.stat--in-progress::before { background: #f59e0b; }
.stat--completed::before { background: #22c55e; }
.stat--closed::before { background: var(--st-closed-bd); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 0.6rem; margin-bottom: 0.5rem; }
.search { position: relative; flex: 1 1 260px; }
.search__icon { position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%); color: var(--text-faint); pointer-events: none; }
.search__input {
  width: 100%; padding: 0.6rem 0.8rem 0.6rem 2.2rem; font: inherit;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
}
.search__input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.select { display: flex; flex-direction: column; gap: 0.2rem; }
.select__label { font-size: 0.7rem; color: var(--text-soft); font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.select select {
  padding: 0.55rem 0.6rem; font: inherit; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text); min-width: 110px;
}
.toolbar__spacer { flex: 1 1 auto; }

.wo-meta { display: flex; align-items: center; gap: 0.75rem; margin: 0.5rem 0 0.75rem; }
.wo-meta__count { color: var(--text-soft); font-size: 0.82rem; }

/* ---------- Work order list ---------- */
.wo-list { display: flex; flex-direction: column; gap: 0.5rem; }
.wo { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.wo--open { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.wo--overdue { border-left: 3px solid #ef4444; }
.wo__summary { display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 0.9rem; cursor: pointer; user-select: none; }
.wo__summary:hover { background: var(--surface-2); }
.wo__summary:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.wo__chev { color: var(--text-faint); transition: transform 0.15s; }
.wo--open .wo__chev { transform: rotate(90deg); }
.wo__id { font-weight: 700; font-variant-numeric: tabular-nums; flex: none; min-width: 84px; }
.wo__desc { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wo__meta { display: flex; align-items: center; gap: 0.55rem; flex: none; }
.wo__loc { color: var(--text-soft); font-size: 0.88rem; display: inline-flex; align-items: center; gap: 0.25rem; }
.wo__loc .icon { width: 0.95em; height: 0.95em; color: var(--text-faint); }
.wo__date { color: var(--text-soft); font-size: 0.86rem; white-space: nowrap; }

.chip { font-size: 0.72rem; font-weight: 600; color: var(--text-soft); background: var(--surface-3); border: 1px solid var(--border); padding: 0.16rem 0.5rem; border-radius: 999px; white-space: nowrap; }
.notes-badge { display: inline-flex; align-items: center; gap: 0.25rem; color: var(--text-faint); font-size: 0.8rem; font-weight: 600; }
.notes-badge .icon { width: 0.95em; height: 0.95em; }

.badge-overdue { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.72rem; font-weight: 700; color: var(--danger-fg); background: var(--danger-bg); border: 1px solid var(--danger-bd); padding: 0.12rem 0.45rem; border-radius: 999px; white-space: nowrap; }
.badge-overdue .icon { width: 0.9em; height: 0.9em; }

/* ---------- Status pills ---------- */
.pill { font-size: 0.73rem; font-weight: 700; padding: 0.24rem 0.62rem; border-radius: 999px; border: 1px solid transparent; white-space: nowrap; }
.pill--open { background: var(--st-open-bg); color: var(--st-open-fg); border-color: var(--st-open-bd); }
.pill--in-progress { background: var(--st-prog-bg); color: var(--st-prog-fg); border-color: var(--st-prog-bd); }
.pill--completed { background: var(--st-done-bg); color: var(--st-done-fg); border-color: var(--st-done-bd); }
.pill--closed { background: var(--st-closed-bg); color: var(--st-closed-fg); border-color: var(--st-closed-bd); }

/* ---------- Detail card ---------- */
.wo__detail { border-top: 1px solid var(--border); padding: 1rem; background: var(--surface-2); }
.wo__detailtop { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.8rem; flex-wrap: wrap; }
.wo__updated { font-size: 0.78rem; color: var(--text-faint); }
.wo__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0.6rem; margin-bottom: 1rem; }
.field { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.5rem 0.65rem; }
.field__label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-soft); font-weight: 700; margin-bottom: 0.15rem; }
.field__value { font-size: 0.92rem; word-break: break-word; }

.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.8rem 0.9rem; margin-bottom: 1rem; }
.tile--instructions { border-left: 4px solid var(--primary); }
.tile--comments { border-left: 4px solid #94a3b8; }
.tile__title { display: flex; align-items: center; gap: 0.4rem; margin: 0 0 0.45rem; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-soft); }
.tile__title .icon { width: 1em; height: 1em; }
.tile__body { white-space: pre-wrap; word-break: break-word; font-size: 0.95rem; }

.control { margin-bottom: 1.1rem; }
.control__title { display: flex; align-items: center; gap: 0.4rem; margin: 0 0 0.5rem; font-size: 0.95rem; }
.control__sub { font-weight: 400; color: var(--text-soft); font-size: 0.8rem; }
.control__hint { color: var(--text-soft); font-size: 0.8rem; margin: 0.5rem 0 0; }

/* Segmented status control */
.seg-group { display: inline-flex; flex-wrap: wrap; gap: 0.4rem; }
.seg { font: inherit; font-weight: 600; font-size: 0.85rem; padding: 0.4rem 0.85rem; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-soft); cursor: pointer; transition: background 0.12s, color 0.12s, border-color 0.12s; }
.seg:hover { border-color: var(--text-soft); }
.seg--active { box-shadow: inset 0 0 0 1px currentColor; }
.seg--active.seg--open { background: var(--st-open-bg); color: var(--st-open-fg); border-color: var(--st-open-bd); }
.seg--active.seg--in-progress { background: var(--st-prog-bg); color: var(--st-prog-fg); border-color: var(--st-prog-bd); }
.seg--active.seg--completed { background: var(--st-done-bg); color: var(--st-done-fg); border-color: var(--st-done-bd); }
.seg--active.seg--closed { background: var(--st-closed-bg); color: var(--st-closed-fg); border-color: var(--st-closed-bd); }

/* Notes */
.note-add { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
.note-add__input { flex: 1 1 280px; font: inherit; padding: 0.5rem 0.6rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); resize: vertical; min-height: 2.4rem; }
.note-add__author { width: 110px; font: inherit; padding: 0.5rem 0.6rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); }
.note-add .btn { align-self: flex-start; }
.notes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.note { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.5rem 0.65rem; }
.note__head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.2rem; }
.note__author { font-size: 0.74rem; font-weight: 700; color: var(--text); background: var(--surface-3); padding: 0.05rem 0.4rem; border-radius: 999px; }
.note__time { font-size: 0.72rem; color: var(--text-faint); }
.note__text { white-space: pre-wrap; word-break: break-word; font-size: 0.92rem; }
.note--empty { color: var(--text-soft); font-style: italic; border-style: dashed; }

/* ---------- Empty / skeleton / notices ---------- */
.empty { text-align: center; padding: 3rem 1rem; color: var(--text-soft); background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.empty h2 { margin: 0 0 0.5rem; color: var(--text); }
.empty .btn { margin-top: 1rem; }
.notice { padding: 0.75rem 1rem; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); }
.notice--ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.notice--error { background: var(--danger-bg); border-color: var(--danger-bd); color: var(--danger-fg); }

.skeleton { display: flex; flex-direction: column; gap: 0.5rem; }
.skeleton-row { height: 48px; border-radius: var(--radius); background: linear-gradient(90deg, #eef2f7 25%, #e2e8f0 37%, #eef2f7 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---------- Footer ---------- */
.footer { max-width: 1140px; margin: 1.5rem auto; padding: 0 1.25rem 2rem; color: var(--text-faint); font-size: 0.78rem; text-align: center; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,0.5); display: grid; place-items: center; padding: 1rem; backdrop-filter: blur(2px); }
.modal__card { width: 100%; max-width: 520px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 1.25rem 1.4rem 1.5rem; }
.modal__head { display: flex; align-items: center; justify-content: space-between; }
.modal__head h2 { margin: 0; font-size: 1.1rem; }
.modal__desc { color: var(--text-soft); font-size: 0.85rem; margin: 0.5rem 0 1rem; }
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 2rem 1rem; text-align: center; cursor: pointer; color: var(--text-soft); transition: border-color 0.15s, background 0.15s; }
.dropzone:hover, .dropzone:focus-visible { border-color: var(--primary); background: var(--primary-soft); outline: none; }
.dropzone--over { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }
.dropzone__icon { display: inline-flex; margin-bottom: 0.4rem; }
.dropzone__icon .icon { width: 1.6rem; height: 1.6rem; }
.progress { margin-top: 1rem; height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress__bar { height: 100%; width: 0; background: var(--primary); transition: width 0.15s; }
#import-summary { margin-top: 1rem; }
#import-summary:empty { margin-top: 0; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 60; display: flex; flex-direction: column; gap: 0.5rem; max-width: min(360px, 90vw); }
.toast { display: flex; align-items: center; gap: 0.5rem; background: var(--navy); color: #fff; padding: 0.65rem 0.85rem; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font-size: 0.88rem; opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s; }
.toast--in { opacity: 1; transform: none; }
.toast--ok { background: #166534; }
.toast--error { background: #b91c1c; }
.toast .icon { width: 1.1em; height: 1.1em; }

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .wo__loc, .wo__date { display: none; }
}
@media (max-width: 620px) {
  .appbar__email { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .wo__meta .chip { display: none; }
  .toolbar__spacer { display: none; }
  .btn__text { display: none; }
}
