/* DNR Texas Admin Portal */
:root {
  --navy: #0e2a47;
  --navy-2: #14385e;
  --navy-3: #0a1f36;
  --teal: #0e9f8a;
  --teal-dark: #0b7f6f;
  --bg: #faf8f4;
  --card: #ffffff;
  --ink: #1c2733;
  --muted: #68727f;
  --line: #e6e0d5;
  --danger: #c0392b;
  --warn: #b97b0e;
  --ok: #177a4c;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
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.5;
}

/* ---------- auth ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--navy-3), var(--navy) 60%, var(--navy-2));
  padding: 20px;
}
.auth-card {
  background: #fff; border-radius: 14px; padding: 36px 34px; width: 100%; max-width: 420px;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.auth-card .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.auth-card .brand-mark {
  width: 46px; height: 46px; border-radius: 10px; background: var(--navy); color: var(--teal);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 26px;
}
.auth-card h1 { font-size: 22px; margin: 0; color: var(--navy); }
.auth-card .sub { color: var(--muted); margin: 4px 0 22px; font-size: 14px; }
.auth-note {
  margin-top: 18px; padding: 12px 14px; background: #f1efe9; border-left: 4px solid var(--teal);
  border-radius: 6px; font-size: 13px; color: var(--muted);
}
.auth-error { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 20px; }
.otp-hint { font-size: 13px; color: var(--muted); margin-top: 12px; }
.linklike { background: none; border: none; color: var(--teal-dark); cursor: pointer; padding: 0; font-size: 14px; }
.linklike:hover { text-decoration: underline; }

/* ---------- layout ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: var(--navy); color: #dfe7f0; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.side-brand { padding: 20px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.12); }
.side-brand .mark {
  width: 38px; height: 38px; border-radius: 9px; background: var(--teal); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 22px;
  vertical-align: middle; margin-right: 10px;
}
.side-brand .name { font-weight: 700; font-size: 17px; vertical-align: middle; }
.side-brand .tag { display: block; margin-top: 8px; font-size: 12px; color: #9fb2c7; letter-spacing: .08em; text-transform: uppercase; }
.side-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.side-nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: #c9d5e3; text-decoration: none; font-size: 14.5px; margin-bottom: 2px;
}
.side-nav a .ico { width: 22px; text-align: center; }
.side-nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.side-nav a.active { background: var(--teal); color: #fff; font-weight: 600; }
.side-foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; color: #9fb2c7; }
.side-foot button { margin-top: 6px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: #fff; border-bottom: 1px solid var(--line); padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50;
}
.topbar h2 { margin: 0; font-size: 19px; color: var(--navy); }
.topbar .who { font-size: 13.5px; color: var(--muted); }
.hamburger { display: none; background: none; border: none; font-size: 24px; cursor: pointer; color: var(--navy); }
.content { padding: 24px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ---------- cards & grids ---------- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: 0 1px 3px rgba(14,42,71,.05); }
.card h3 { margin: 0 0 12px; font-size: 16px; color: var(--navy); }
.card .big { font-size: 30px; font-weight: 700; color: var(--navy); }
.card .caption { font-size: 13px; color: var(--muted); }
.stat-row { display: flex; align-items: center; justify-content: space-between; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 14px; flex-wrap: wrap; gap: 10px; }
.section-head h2, .section-head h3 { margin: 0; color: var(--navy); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left; padding: 11px 14px; background: #f3f0e9; color: var(--navy);
  font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
table.data td { padding: 11px 14px; border-bottom: 1px solid #f0ece3; vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #fbfaf7; }
table.data tr.clickable { cursor: pointer; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { white-space: nowrap; }
.empty-row td { text-align: center; color: var(--muted); padding: 28px !important; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  white-space: nowrap; background: #eef0f2; color: #556;
}
.badge-ok { background: #e3f4ea; color: var(--ok); }
.badge-warn { background: #fdf0da; color: var(--warn); }
.badge-bad { background: #fbe4e0; color: var(--danger); }
.badge-info { background: #e2f4f1; color: var(--teal-dark); }
.badge-pri-urgent { background: #fbe4e0; color: var(--danger); }
.badge-pri-semi { background: #fdf0da; color: var(--warn); }
.badge-pri-regular { background: #eef0f2; color: #556; }
.badge-status-open { background: #e8eef5; color: var(--navy); }
.badge-status-scheduled { background: #e6e6fa; color: #4a4aa0; }
.badge-status-enroute, .badge-status-onsite { background: #e2f4f1; color: var(--teal-dark); }
.badge-status-working { background: #d9ecff; color: #1a5fa8; }
.badge-status-awaiting_parts { background: #fdf0da; color: var(--warn); }
.badge-status-completed { background: #e3f4ea; color: var(--ok); }
.badge-status-closed { background: #eef0f2; color: #556; }
.badge-status-invoiced { background: #efe4f7; color: #7a3fb0; }
.badge-status-paid { background: #e3f4ea; color: var(--ok); }
.badge-status-cancelled { background: #fbe4e0; color: var(--danger); }

/* ---------- buttons ---------- */
.btn {
  display: inline-block; padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; transition: all .15s;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-2); }
.btn-ghost { background: transparent; color: var(--navy); border-color: var(--line); }
.btn-ghost:hover { background: #f1efe9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a93226; }
.btn-warn { background: var(--warn); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 6px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13.5px; font-weight: 600; color: var(--navy); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #cfc8b8; border-radius: 8px; font-size: 14.5px;
  background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14,159,138,.15);
}
.field textarea { resize: vertical; min-height: 90px; }
.field .help { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .field { margin-bottom: 0; min-width: 150px; }
.search-input { min-width: 220px; }

/* ---------- loading / error ---------- */
.loading { display: flex; align-items: center; gap: 12px; padding: 40px; justify-content: center; color: var(--muted); }
.spinner {
  width: 26px; height: 26px; border: 3px solid #d9e8e4; border-top-color: var(--teal);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-box {
  background: #fdeeea; border: 1px solid #f5c6bd; color: #8a2c1e; border-radius: var(--radius);
  padding: 20px; margin: 10px 0;
}
.error-box p { margin: 8px 0 12px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 22px; right: 22px; z-index: 1000; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 9px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); opacity: 0; transform: translateY(10px); transition: all .3s;
  max-width: 360px;
}
.toast.show { opacity: 1; transform: none; }
.toast.success { background: var(--ok); }
.toast.error { background: var(--danger); }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10,31,54,.55); z-index: 900;
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 520px; max-height: 90vh;
  display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(0,0,0,.3);
}
.modal-wide { max-width: 720px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 17px; color: var(--navy); }
.modal-head-danger h3 { color: var(--danger); }
.modal-x { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.confirm-warning {
  margin-top: 12px; padding: 10px 12px; background: #fdf6e3; border-left: 4px solid var(--warn);
  border-radius: 6px; font-size: 13.5px; color: #7a5a10;
}

/* ---------- detail pages ---------- */
.detail-head { margin-bottom: 18px; }
.detail-head .crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.detail-head .crumbs a { color: var(--teal-dark); text-decoration: none; }
.detail-head h2 { margin: 0 0 6px; color: var(--navy); font-size: 22px; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 20px; }
.kv .k { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kv .v { font-size: 15px; font-weight: 600; color: var(--ink); }

/* notes thread */
.note { border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; margin-bottom: 10px; background: #fff; }
.note.deleted { opacity: .55; border-style: dashed; }
.note .note-meta { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.note .note-actions { display: flex; gap: 6px; }
.note .note-body { white-space: pre-wrap; word-break: break-word; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 26px; border-left: 2px solid var(--line); margin-left: 8px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before {
  content: ''; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--teal); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--teal);
}
.timeline .t-when { font-size: 12.5px; color: var(--muted); }

/* attachments */
.attach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.attach { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.attach img { width: 100%; height: 110px; object-fit: cover; display: block; }
.attach .a-name { font-size: 12.5px; padding: 8px 10px; word-break: break-word; }
.attach .a-name a { color: var(--teal-dark); }

/* property tree */
.prop { padding: 10px 0; border-bottom: 1px solid #f0ece3; }
.prop:last-child { border-bottom: none; }
.prop.sub { margin-left: 24px; border-left: 2px solid var(--teal); padding-left: 12px; }
.prop .prop-name { font-weight: 600; }

/* toggle switch */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; vertical-align: middle; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .track { position: absolute; inset: 0; background: #c9c2b2; border-radius: 999px; transition: .2s; cursor: pointer; }
.toggle .track::before {
  content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.toggle input:checked + .track { background: var(--teal); }
.toggle input:checked + .track::before { transform: translateX(20px); }

.quick-assign { display: flex; gap: 6px; }
.quick-assign select { flex: 1; padding: 6px 8px; border: 1px solid #cfc8b8; border-radius: 6px; font-size: 13px; }

.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.muted { color: var(--muted); }
.text-right { text-align: right; }
.total-row td { font-weight: 700; border-top: 2px solid var(--navy); }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 600; transform: translateX(-100%);
    transition: transform .25s; width: 250px;
  }
  .sidebar.open { transform: none; }
  .side-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 550; }
  .hamburger { display: block; }
  .content { padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .topbar { padding: 10px 14px; }
}
