:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #16202b;
  --muted: #64717f;
  --border: #e3e8ee;
  --brand: #0a3399;          /* overridden by /brand.css */
  --brand-hover: #082a7d;
  --brand-soft: #e6ecf7;
  --link: var(--brand);
  --good: #15803d;   --good-bg: #dcfce7;
  --warn: #a16207;   --warn-bg: #fef3c7;
  --bad: #b91c1c;    --bad-bg: #fee2e2;
  --none: #64717f;   --none-bg: #eef1f5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 Inter, "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.65rem; margin: 0 0 .5rem; letter-spacing: -.02em; font-weight: 750; }
h2 { font-size: 1.08rem; margin: 0 0 .75rem; letter-spacing: -.01em; }
code { background: var(--none-bg); padding: 0 .3em; border-radius: 4px; font-size: .9em; }

/* ---------- layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); padding: .65rem 1.5rem;
}
.topbar a { color: var(--text); }
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 750; font-size: 1.02rem; color: var(--text) !important; }
.brand:hover { text-decoration: none; }
.brand img { height: 32px; width: auto; }
.brand .mark-img { height: 28px; }
.brand .mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, #f5a524, #f97316); color: #fff;
}
.mainnav { display: flex; gap: .2rem; flex-wrap: wrap; flex: 1; }
.mainnav a { padding: .42rem .8rem; border-radius: 8px; color: var(--muted); font-weight: 550; font-size: .93rem; }
.mainnav a:hover { background: var(--none-bg); color: var(--text); text-decoration: none; }
.mainnav a.active { background: var(--brand-soft); color: var(--brand); }
.userbox { display: flex; align-items: center; gap: .75rem; font-size: .92rem; }
.userbox .role {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
  color: var(--brand); background: var(--brand-soft); padding: .1rem .45rem; border-radius: 999px;
}
.userbox .linkbtn { color: var(--muted); }
.bell { position: relative; display: inline-flex; padding: .4rem; border-radius: 8px; color: var(--muted) !important; }
.bell:hover, .bell.active { background: var(--none-bg); color: var(--text) !important; text-decoration: none; }
.bell .count {
  position: absolute; top: -3px; right: -5px; min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; background: #ef4444; color: #fff; font-size: .68rem; font-weight: 700;
  display: grid; place-items: center; line-height: 1; border: 2px solid #fff;
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* notifications */
.notes { list-style: none; margin: 0; padding: 0; }
.note { display: flex; gap: .9rem; padding: .85rem 1.1rem; border-bottom: 1px solid var(--border); }
.note:last-child { border-bottom: 0; }
.note.unread { background: #f3f7fd; }
.note .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; margin-top: .45rem; background: var(--link); }
.note.warn .dot { background: #d99a00; }
.note.bad .dot { background: var(--bad); }
.note.resolved { opacity: .7; }
.note .main { flex: 1; min-width: 0; }
.note .title { font-weight: 600; }
.note .body { white-space: pre-wrap; color: var(--text); margin: .2rem 0; font-size: .92rem; }
.note .meta { color: var(--muted); font-size: .8rem; }
.note .side { flex: none; display: flex; flex-direction: column; gap: .4rem; align-items: flex-end; }
.note .side input { width: 14rem; font-size: .85rem; padding: .3rem .5rem; }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tabs a { padding: .35rem .8rem; border-radius: 999px; color: var(--text); border: 1px solid var(--border); background: var(--surface); }
.tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.tabs a:hover { text-decoration: none; }
.card.alerting { border-left: 4px solid var(--bad); }
.status-ok { color: var(--good); font-weight: 600; }
.status-off { color: var(--bad); font-weight: 600; }
pre.config { background: #f1f4f8; border: 1px solid var(--border); border-radius: 6px; padding: .75rem; overflow-x: auto; font-size: .82rem; }
@media (max-width: 640px) {
  .note { flex-wrap: wrap; }
  .note .side { align-items: stretch; width: 100%; }
  .note .side input { width: 100%; }
}

.container { max-width: 1280px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.pagehead h1 { margin-bottom: .25rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.crumbs { margin: 0 0 .5rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.narrow { max-width: 520px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; margin-bottom: 1rem;
}
.card.flush { padding: 0; }
.card-pad { padding: 1.1rem 1.25rem .25rem; }
.cardhead { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
details.card summary { cursor: pointer; list-style: revert; }
details.card summary h2 { display: inline; }

/* ---------- stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--none); border-radius: var(--radius); padding: .8rem 1rem; color: var(--text);
}
a.stat:hover { text-decoration: none; border-color: var(--brand); }
.stat .num { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.stat .num.money { font-size: 1.35rem; padding: .25rem 0 .2rem; }
.stat .lbl { color: var(--muted); font-size: .85rem; }
.stat.bad { border-left-color: var(--bad); }
.stat.warn { border-left-color: #d99a00; }
.stat.good { border-left-color: var(--good); }

/* ---------- tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f8fafc; font-weight: 600; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.sub { color: var(--muted); font-size: .82rem; }
td.old { color: var(--bad); text-decoration: line-through; text-decoration-color: rgba(179,38,30,.4); }
td.new { color: var(--good); font-weight: 500; }
tr.groupstart td { border-top: 2px solid var(--border); }
tr.inactive td { color: var(--muted); }
tr.flagged td { background: var(--bad-bg); }

/* ---------- badges */
.badge {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem;
  font-weight: 600; white-space: nowrap; background: var(--none-bg); color: var(--none);
}
.badge.active, .badge.scheduled { background: var(--good-bg); color: var(--good); }
.badge.expiring, .badge.due { background: var(--warn-bg); color: var(--warn); }
.badge.expired, .badge.overdue { background: var(--bad-bg); color: var(--bad); }

/* ---------- forms */
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
label.check { flex-direction: row; align-items: flex-start; gap: .5rem; font-weight: 400; }
label.check input { margin-top: .25rem; }
label.danger { color: var(--bad); }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: #fff;
  border: 1px solid #c4ccd6; border-radius: 6px; padding: .45rem .6rem; min-width: 0;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
textarea { resize: vertical; }
.hint { color: var(--muted); font-size: .82rem; font-weight: 400; }
ul.hint { margin: .75rem 0 0; padding-left: 1.2rem; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.rowform { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .9rem; }
.rowform .grow, .filters .grow { flex: 1 1 240px; }
.rowform .qty { width: 5.5rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.formgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem 1.25rem; }
.formgrid .full { grid-column: 1 / -1; }
.searchbar { display: flex; gap: .5rem; flex: 1 1 320px; max-width: 520px; }
.searchbar input { flex: 1; }
form.inline { display: inline-flex; gap: .4rem; align-items: center; margin: 0; }

.btn {
  display: inline-block; font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer;
  padding: .45rem .95rem; border-radius: 6px; border: 1px solid #c4ccd6; background: #fff; color: var(--text);
  white-space: nowrap;
}
.btn:hover { background: #f1f4f8; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); }
.btn.danger { color: var(--bad); border-color: #e6b4b0; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: .25rem .6rem; font-size: .82rem; }
.btn.wide { width: 100%; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--link); cursor: pointer; }
.linkbtn.danger { color: var(--bad); }
.linkbtn:hover { text-decoration: underline; }

/* ---------- misc */
dl { display: grid; grid-template-columns: 8.5rem 1fr; gap: .4rem .75rem; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.empty { color: var(--muted); margin: .25rem 0; }
.prewrap { white-space: pre-wrap; }
ul.spaced li { margin-bottom: .4rem; }

.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.flash ul { margin: 0; padding-left: 1.2rem; }
.flash.success { background: var(--good-bg); border-color: #b7e0c6; color: #145233; }
.flash.error { background: var(--bad-bg); border-color: #f0bcb8; color: #7f1b15; }
.flash.info { background: #e7f0fc; border-color: #bed3f1; color: #1b3f73; }

.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 1rem; padding: 2rem; }
.login-card h1 { margin: 0; }
.login-card p { margin: 0; }

@media (max-width: 640px) {
  .container { padding: 1rem .75rem 2rem; }
  .grid2 { grid-template-columns: 1fr; }
  .row2 { grid-template-columns: 1fr; }
  .topbar { gap: .5rem 1rem; justify-content: space-between; }
  .mainnav { order: 3; flex-basis: 100%; }
  dl { grid-template-columns: 7rem 1fr; }
}

/* ---------- modern refresh */
.card { border-radius: var(--radius); border-color: var(--border); box-shadow: var(--shadow); }
.stat { border-radius: var(--radius); border: 1px solid var(--border); border-left: 1px solid var(--border);
        box-shadow: var(--shadow); padding: 1rem 1.1rem; position: relative; overflow: hidden; }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--none-bg); }
.stat.bad::before { background: #ef4444; } .stat.warn::before { background: #f59e0b; } .stat.good::before { background: var(--brand); }
.stat.bad .num { color: var(--bad); } .stat.warn .num { color: var(--warn); }
a.stat:hover { border-color: var(--brand); box-shadow: 0 6px 20px -10px rgba(16,24,40,.35); }
.stat .num { font-size: 1.9rem; letter-spacing: -.02em; }
th { background: transparent; font-size: .72rem; letter-spacing: .06em; border-bottom-color: var(--border); }
tbody tr:hover { background: #f9fafb; }
.btn { border-radius: 9px; border-color: var(--border); transition: background .15s, border-color .15s; }
.btn.primary { background: var(--brand); border-color: var(--brand); box-shadow: 0 4px 12px -6px var(--brand); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
input, select, textarea { border-radius: 9px; border-color: #d3dae2; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.badge { font-weight: 650; padding: .14rem .6rem; }
.flash { border-radius: 12px; }
.tabs a.active { background: var(--brand); border-color: var(--brand); }
.note.unread { background: var(--brand-soft); }
.note .dot { background: var(--brand); }
.card.alerting { border-left: 4px solid #ef4444; }

.colorpick { display: flex; align-items: center; gap: .6rem; }
.colorpick input[type=color] { width: 52px; height: 38px; padding: 2px; cursor: pointer; }
.logo-current { display: flex; align-items: center; gap: 1rem; margin-top: .4rem; font-weight: 400; }
.logo-current img { height: 40px; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 4px; }
.inline-label { display: inline; font-weight: 400; }
.section-title { margin: 1.75rem 0 .75rem; font-size: 1.25rem; }
#branding .formgrid { margin: 1rem 0 1.25rem; }
.field { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }

/* ---------- fonts (shared with the website) */
@font-face { font-family: "Figtree"; src: url("../../assets/fonts/figtree.woff2") format("woff2"); font-weight: 300 900; font-display: swap; }
@font-face { font-family: "Archivo"; src: url("../../assets/fonts/archivo.woff2") format("woff2"); font-weight: 100 900; font-stretch: 62% 125%; font-display: swap; }
body { font-family: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif; }
h1, h2, .brand span, .stat .num { font-family: "Archivo", "Figtree", sans-serif; }
h1 { font-stretch: 110%; }

/* ---------- sign-in & setup */
body.auth { background: #f4f1ea; }
.auth-grid { display: grid; grid-template-columns: minmax(320px, 5fr) 7fr; min-height: 100vh; }
.auth-side {
  display: flex; flex-direction: column; justify-content: space-between; gap: 2rem; padding: 2.5rem; color: #d6e0f5;
  background: radial-gradient(600px 400px at 100% 0%, rgba(248, 176, 8, .30), transparent 60%),
              radial-gradient(500px 400px at 0% 100%, rgba(0, 160, 224, .35), transparent 60%),
              linear-gradient(160deg, #041745, #0a3399);
}
.auth-brand { display: inline-flex; align-items: center; gap: .7rem; color: #fff !important; font: 800 1.05rem/1.1 "Archivo", sans-serif; }
.auth-brand:hover { text-decoration: none; }
.auth-brand img { height: 34px; width: auto; }
.auth-pitch h2 { color: #fff; font-size: 2rem; font-stretch: 112%; margin: 0 0 .5rem; }
.auth-pitch p { font-size: 1.05rem; max-width: 26rem; }
.auth-pitch ul { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; gap: .7rem; }
.auth-pitch li::before { content: "✓"; display: inline-grid; place-items: center; width: 22px; height: 22px; margin-right: .6rem; border-radius: 50%; background: rgba(255,255,255,.16); color: #fff; font-size: .75rem; font-weight: 800; }
.auth-foot { margin: 0; font-size: .85rem; opacity: .7; }
.auth-main { display: grid; place-items: center; padding: 2.5rem 1.25rem; }
.auth-card {
  width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 1.1rem; background: #fff; padding: 2.5rem;
  border-radius: 20px; border: 1px solid var(--border); box-shadow: 0 1px 2px rgba(16,24,40,.05), 0 12px 32px -12px rgba(16,24,40,.18);
}
.auth-card h1 { font-size: 1.75rem; margin: 0; }
.auth-card p { margin: 0; }
.auth-card label { font-size: .9rem; }
.auth-card input { padding: .8rem .9rem; width: 100%; min-width: 0; }
.auth-logo { width: 220px; height: auto; align-self: center; margin-bottom: .25rem; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; padding: .8rem 1.2rem; font-size: .95rem; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-block { width: 100%; }
.alert { padding: .75rem 1rem; border-radius: 10px; font-size: .92rem; border: 1px solid; }
.alert ul { margin: 0; padding-left: 1.1rem; }
.alert.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert.success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert.info { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
@media (max-width: 760px) {
  .auth-grid { grid-template-columns: minmax(0, 1fr); }
  .auth-side { padding: 1.5rem; gap: 1rem; }
  .auth-pitch ul, .auth-pitch p, .auth-foot { display: none; }
  .auth-pitch h2 { font-size: 1.4rem; }
  .auth-card { padding: 1.75rem; }
}

/* ---------- quotes & documents */
.badge.muted { background: var(--none-bg); color: var(--none); }
.badge.info { background: var(--brand-soft); color: var(--brand); }
.badge.ok { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
h1 .badge { font-size: .8rem; vertical-align: middle; margin-left: .4rem; font-family: Inter, "Segoe UI", system-ui, sans-serif; letter-spacing: 0; }
table.lines td { vertical-align: middle; padding: .35rem .4rem; }
table.lines td.grow { width: 100%; min-width: 16rem; }
table.lines td.grow input { width: 100%; }
table.lines td.num input { text-align: right; width: 6.5rem; }
table.lines td.num input[name="items[qty][]"] { width: 4.5rem; }
table.lines select { padding-right: 1.6rem; }
.quote-totals { display: flex; gap: 1rem 1.5rem; align-items: flex-end; justify-content: flex-end; flex-wrap: wrap; margin-top: .5rem; }
.quote-totals label input { width: 7rem; text-align: right; }
.quote-totals dl { grid-template-columns: auto 9rem; text-align: right; min-width: 16rem; }
.quote-totals dl dt:last-of-type, .quote-totals dl dd:last-of-type { font-weight: 700; font-size: 1.1rem; color: var(--text); }
tfoot td { border-bottom: 0; padding-top: .35rem; padding-bottom: .35rem; }
tfoot tr.total td { font-weight: 700; font-size: 1.05rem; border-top: 2px solid var(--brand); }
.verify-card { max-width: 560px; }
.narrow-wide { max-width: 760px; display: flex; flex-direction: column; gap: 1rem; }
.verdict { padding: .9rem 1rem; border-radius: 12px; border: 1px solid; line-height: 1.5; }
.verdict.good { background: var(--good-bg); border-color: #b7e0c6; color: #145233; }
.verdict.bad { background: var(--bad-bg); border-color: #f0bcb8; color: #7f1b15; }
.verdict.info { background: #e7f0fc; border-color: #bed3f1; color: #1b3f73; }
.verify-details { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .9rem 1rem; font-size: .92rem; }
.verify-form { border-top: 1px solid var(--border); padding-top: 1rem; }
code.wrap { word-break: break-all; }
.warn-text { color: var(--warn); font-weight: 600; }
@media (max-width: 640px) {
  .quote-totals { justify-content: stretch; }
  .quote-totals dl { min-width: 0; width: 100%; }
}
/* Grid columns may shrink below their content's width (wide tables scroll inside .tablewrap instead). */
.grid2 > *, .grid3 > * { min-width: 0; }
input[type=file] { max-width: 100%; }
/* Export menu on the Customers page */
details.menu { position: relative; }
details.menu > summary { list-style: none; cursor: pointer; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu[open] > summary { background: var(--brand-soft); border-color: var(--brand); }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: min(330px, calc(100vw - 2.5rem)); background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 32px -12px rgba(16,24,40,.25); padding: .35rem; display: flex; flex-direction: column; }
.menu-list a { display: flex; flex-direction: column; gap: .1rem; padding: .6rem .75rem; border-radius: 8px; color: var(--text); }
.menu-list a:hover { background: var(--bg); text-decoration: none; }
.menu-list a span { color: var(--muted); font-size: .82rem; }
.narrow-form { max-width: 640px; }
@media (max-width: 640px) {
  .pagehead { position: relative; }
  details.menu { position: static; }
  .menu-list { left: 0; right: 0; width: auto; top: auto; margin-top: 6px; }
}
