:root {
  --navy: #0b2a5b;
  --navy-2: #12397a;
  --blue: #2a86e8;
  --blue-soft: #e8f2fd;
  --ink: #17202c;
  --muted: #5c6878;
  --line: #dde3ea;
  --bg: #f3f6f9;
  --card: #ffffff;
  --ok: #1f9d55;
  --ok-soft: #e3f6eb;
  --warn: #c77700;
  --warn-soft: #fff3dc;
  --bad: #d23a3a;
  --bad-soft: #fde8e8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 56, .06), 0 2px 8px rgba(16, 32, 56, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: .25rem 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---------- top bar ---------- */
.topbar {
  background: linear-gradient(180deg, #0d3270, var(--navy));
  color: #fff; position: sticky; top: 0; z-index: 20;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
}
.topbar-inner { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; gap: 1rem; padding: .35rem 1rem; }
.brand { display: flex; align-items: center; background: #fff; border-radius: 8px; padding: 2px 8px; }
.brand img { height: 38px; display: block; }
.nav { display: flex; gap: .15rem; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: #cfe0f7; padding: .5rem .7rem; border-radius: 7px; white-space: nowrap; font-weight: 600; font-size: .93rem; }
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav a.on { background: rgba(255,255,255,.14); color: #fff; }
.userbox { display: flex; align-items: center; gap: .5rem; font-size: .88rem; color: #cfe0f7; white-space: nowrap; }
.userbox a { color: #fff; }
.userbox form { margin: 0; }
.userbox .acct { display: none; }
.linkbtn { background: none; border: 0; color: #cfe0f7; cursor: pointer; font: inherit; padding: 0; }
.linkbtn:hover { color: #fff; text-decoration: underline; }

@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; gap: .4rem; padding: .4rem .6rem; }
  .brand img { height: 32px; }
  .nav { order: 3; flex-basis: 100%; }
  .userbox { margin-left: auto; }
  .userbox .uname { display: none; }
  .userbox .acct { display: inline; }
}

/* ---------- layout ---------- */
main { max-width: 1200px; margin: 0 auto; padding: 1.1rem 1rem 4rem; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.pagehead .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .g2, .g3 { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.card + .card { margin-top: 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.card-head h2 { margin: 0; }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.stat .n { font-size: 1.6rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .85rem; }

/* ---------- flash ---------- */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-weight: 500; }
.flash.ok { background: var(--ok-soft); color: #11663a; border: 1px solid #b9e6cb; }
.flash.err { background: var(--bad-soft); color: #9b1f1f; border: 1px solid #f3c1c1; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  background: var(--blue); color: #fff; border: 1px solid #1f74d0; border-radius: 8px;
  padding: .55rem .95rem; font-family: inherit; font-weight: 600; font-size: .93rem; line-height: 1.2; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #1f74d0; text-decoration: none; }
.btn.secondary { background: #fff; color: var(--navy); border-color: var(--line); }
.btn.secondary:hover { background: #f1f5fa; }
.btn.danger { background: #fff; color: var(--bad); border-color: #f0c4c4; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.small { padding: .32rem .6rem; font-size: .84rem; }
.btn.big { padding: .85rem 1.2rem; font-size: 1.02rem; }
.btn.block { width: 100%; }

form.inline { display: inline; margin: 0; }
label { display: block; font-weight: 600; font-size: .86rem; margin-bottom: .25rem; color: #2b3746; }
.field { margin-bottom: .85rem; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=date],
input[type=time], input[type=search], select, textarea {
  width: 100%; padding: .55rem .65rem; border: 1px solid #c9d2dc; border-radius: 8px; background: #fff;
  font: inherit; color: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(42,134,232,.35); border-color: var(--blue); }
textarea { min-height: 90px; resize: vertical; }
.check { display: flex; align-items: center; gap: .45rem; font-weight: 500; }
.check input { width: 18px; height: 18px; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 160px; }
.searchbar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.searchbar input[type=search] { flex: 1 1 220px; }
.searchbar select { width: auto; }
details.box { background: #f8fafc; border: 1px dashed #c9d2dc; border-radius: 8px; padding: .6rem .8rem; margin-bottom: .8rem; }
details.box summary { cursor: pointer; font-weight: 600; color: var(--navy); }
details.box[open] summary { margin-bottom: .7rem; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; background: #f8fafc; }
tr:hover td { background: #fafcfe; }
td.num, th.num { text-align: right; white-space: nowrap; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: .14rem .5rem; border-radius: 999px; font-size: .76rem; font-weight: 700; background: #eef1f5; color: #445163; white-space: nowrap; }
.badge.lead, .badge.draft, .badge.planned, .badge.untested { background: #eef1f5; color: #445163; }
.badge.quoted, .badge.sent, .badge.pulled { background: var(--blue-soft); color: #145cad; }
.badge.scheduled, .badge.terminated { background: #ece8fd; color: #5133b8; }
.badge.in_progress { background: var(--warn-soft); color: #8a5300; }
.badge.complete, .badge.accepted, .badge.paid, .badge.pass, .badge.tested { background: var(--ok-soft); color: #11663a; }
.badge.invoiced { background: #e0f4f6; color: #0f6570; }
.badge.cancelled, .badge.declined, .badge.void { background: #f1f1f1; color: #888; text-decoration: line-through; }
.badge.fail, .badge.overdue { background: var(--bad-soft); color: #a32424; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: .2rem; border-bottom: 2px solid var(--line); margin-bottom: 1rem; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: .6rem .85rem; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs a:hover { color: var(--navy); text-decoration: none; }
.tabs a.on { color: var(--navy); border-bottom-color: var(--blue); }
.tabs .count { font-size: .75rem; background: #eef1f5; border-radius: 999px; padding: 0 .4rem; margin-left: .2rem; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .6rem 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: .75rem; align-items: flex-start; }
.list li:last-child { border-bottom: 0; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: .35rem .75rem; margin: 0; }
.kv dt { color: var(--muted); font-size: .86rem; }
.kv dd { margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem .5rem; }

/* ---------- photos ---------- */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; }
.photos a { display: block; position: relative; border-radius: 8px; overflow: hidden; background: #e9eef4; aspect-ratio: 1; }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: .3rem .45rem; font-size: .75rem; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.65)); }
.photos.mini { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
.viewer img { max-width: 100%; max-height: 75vh; display: block; margin: 0 auto; border-radius: 8px; }
.viewer iframe { width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: 8px; }

.uploader {
  border: 2px dashed #9fc3ec; background: var(--blue-soft); border-radius: 10px; padding: 1rem; text-align: center;
}
.uploader.drag { background: #d6e9fc; border-color: var(--blue); }
.uploader input[type=file] { display: none; }
.uploader .hint { color: var(--muted); font-size: .85rem; margin-top: .4rem; }
.progress { height: 8px; background: #dfe7f1; border-radius: 99px; overflow: hidden; margin-top: .6rem; display: none; }
.progress > div { height: 100%; width: 0; background: var(--blue); transition: width .2s; }

/* ---------- cable meter ---------- */
.meter { height: 9px; background: #e6ebf1; border-radius: 99px; overflow: hidden; display: flex; min-width: 80px; }
.meter .p { background: var(--ok); }
.meter .f { background: var(--bad); }

/* ---------- schedule ---------- */
.week { min-width: 860px; table-layout: fixed; }
.week th.today, .week td.today { background: #f2f8ff; }
.week td { height: 74px; padding: .3rem; }
.week td.who { font-weight: 700; width: 130px; }
.shift { display: block; background: var(--blue-soft); border-left: 3px solid var(--blue); border-radius: 5px; padding: .25rem .4rem; margin-bottom: .25rem; font-size: .8rem; line-height: 1.25; color: var(--ink); }
.shift:hover { text-decoration: none; background: #d9eafc; }
.shift .t { color: var(--muted); font-size: .74rem; }

/* ---------- billing editor ---------- */
.items td { padding: .35rem; }
.items input { padding: .45rem .5rem; }
.items .d { width: 52%; }
.items .q { width: 11%; }
.items .p { width: 15%; }
.totals { margin-left: auto; width: 280px; max-width: 100%; }
.totals div { display: flex; justify-content: space-between; padding: .3rem 0; }
.totals .grand { font-weight: 800; font-size: 1.15rem; border-top: 2px solid var(--navy); margin-top: .3rem; padding-top: .5rem; }

/* ---------- auth pages ---------- */
.authwrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(circle at 30% 10%, #1a4b99, var(--navy) 60%); }
.authcard { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 1.6rem; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.authcard img { display: block; width: 230px; max-width: 100%; margin: 0 auto 1rem; }
.authcard h1 { text-align: center; font-size: 1.2rem; margin-bottom: 1rem; }

/* ---------- printable docs ---------- */
.printpage { background: #fff; max-width: 850px; margin: 1rem auto; padding: 2.2rem; box-shadow: var(--shadow); border-radius: 6px; }
.printbar { max-width: 850px; margin: 1rem auto 0; display: flex; gap: .5rem; justify-content: flex-end; }
.doc-head { display: flex; justify-content: space-between; gap: 2rem; align-items: flex-start; border-bottom: 3px solid var(--navy); padding-bottom: 1rem; margin-bottom: 1.2rem; }
.doc-head img { width: 240px; }
.doc-title { text-align: right; }
.doc-title .big { font-size: 1.8rem; font-weight: 800; color: var(--navy); letter-spacing: .06em; }
.doc-parties { display: flex; justify-content: space-between; gap: 2rem; margin-bottom: 1.2rem; }
.doc-parties h3 { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: .2rem; }
.printpage table th { background: var(--navy); color: #fff; }
.doc-foot { margin-top: 2rem; padding-top: .8rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .88rem; text-align: center; }
@media print {
  body { background: #fff; }
  .topbar, .printbar, .noprint { display: none !important; }
  main { padding: 0; max-width: none; }
  .printpage { box-shadow: none; margin: 0; padding: 0; max-width: none; }
  .printpage table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a { color: inherit; }
}
