:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --text: #1d2330;
    --muted: #697386;
    --border: #dfe3e8;
    --primary: #1f5fbf;
    --primary-dark: #174a96;
    --danger: #b42318;
    --success-bg: #e8f5ec;
    --success-text: #1d6b39;
    --error-bg: #fdecea;
    --error-text: #9b1c13;
    --radius: 8px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
small { font-weight: normal; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 0.9em; }
.prewrap { white-space: pre-wrap; margin: 0; }
.pad { padding: 0 20px 16px; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 56px; background: #16202f; color: #fff; }
.topbar .brand { color: #fff; font-weight: 700; }
.mainnav { display: flex; gap: 4px; flex: 1; }
.mainnav a, .mainnav .soon { color: #c7cfdb; padding: 6px 12px; border-radius: 6px; }
.mainnav a:hover { background: #24324a; text-decoration: none; color: #fff; }
.mainnav a.active { background: #2b3d5a; color: #fff; }
.mainnav .soon { opacity: 0.45; cursor: default; }
.userbox { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; }
.userbox small { color: #9aa6b8; margin-left: 4px; }
.userbox form { margin: 0; }
.btn-link { background: none; border: 0; color: #c7cfdb; cursor: pointer; font: inherit; padding: 0; }
.btn-link:hover { color: #fff; text-decoration: underline; }

.container { max-width: 1200px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.crumbs { margin: 0 0 4px; font-size: 0.85rem; color: var(--muted); }
.actions { display: flex; gap: 8px; }
.actions form { margin: 0; }

/* Cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.card-flush { padding: 0; overflow-x: auto; }
.card-head { padding: 16px 20px 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }
.grid-2 .card { margin-bottom: 0; }
.grid-2 + * { margin-top: 20px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; display: flex; flex-direction: column; }
.stat-num { font-size: 1.8rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.85rem; }

.details { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 20px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; background: #fafbfc; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f8fafc; }
.num { text-align: right !important; }

/* Badges */
.badge { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #eef1f5; color: #46516a; }
.badge-active { background: #e3f4e8; color: #1d6b39; }
.badge-prospect { background: #e7effc; color: #1f5fbf; }
.badge-inactive { background: #f1f1f1; color: #777; }

/* Buttons */
.btn { display: inline-block; padding: 8px 16px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.btn:hover { background: #f1f3f6; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f0c4c0; }
.btn-danger:hover { background: var(--error-bg); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: wait; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; }
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }

/* Forms */
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.9rem; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=tel], input[type=url], input[type=number], input[type=date], select, textarea {
    font: inherit; font-weight: normal; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b8cff2; border-color: var(--primary); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.field-error { color: var(--danger); font-weight: normal; font-size: 0.85rem; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: normal; }
label.check input { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 12px 16px 16px; margin: 0; }
legend { font-weight: 600; padding: 0 6px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.form-grid.inner { gap: 12px 20px; }
.span-2 { grid-column: span 2; }
.address-grid { grid-template-columns: 2fr 1.4fr 1fr; }
.span-full { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

.filters { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.filters input[type=search] { max-width: 340px; }
.filters select { width: auto; }

.pager { display: flex; justify-content: center; gap: 20px; margin: 16px 0; color: var(--muted); }

/* Auth pages */
.auth-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 32px; width: 100%; max-width: 400px; }
.auth-card h1 { font-size: 1.25rem; margin-bottom: 16px; }
.brand-lg { font-weight: 700; font-size: 1.1rem; margin-bottom: 20px; color: var(--primary); }

@media (max-width: 720px) {
    .topbar { flex-wrap: wrap; height: auto; padding: 12px 16px; gap: 8px 16px; }
    .mainnav { order: 3; width: 100%; overflow-x: auto; }
    .container { padding: 16px; }
    .form-grid, .address-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .details { grid-template-columns: 1fr; gap: 2px; }
    .details dd { margin-bottom: 8px; }
}

/* Sites */
.card-head-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-bottom: 12px; }
.card-head-row h2 { margin: 0; }
.btn-sm { padding: 4px 12px; font-size: 0.85rem; }
.secret summary { cursor: pointer; color: var(--primary); font-weight: 600; }
.secret[open] summary { margin-bottom: 10px; }
.notes { margin: 0; padding: 12px 14px; background: #fbf8ec; border: 1px solid #ece3c3; border-radius: 6px;
         font-family: var(--mono); font-size: 0.9rem; white-space: pre-wrap; word-break: break-word; }
textarea.mono { font-family: var(--mono); font-size: 0.9rem; }

/* ---- Tickets ------------------------------------------------------------- */
.nowrap { white-space: nowrap; }
.small { font-size: 0.85rem; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 0; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label { font-weight: 600; font-size: 0.9rem; }
.align-end { align-self: end; padding-bottom: 8px; }
label.inline { flex-direction: row; align-items: center; gap: 8px; font-weight: normal; }
label.inline select { width: auto; }

.prio-critical { background: #fde2e1; color: #a1160d; }
.prio-high     { background: #fff0d9; color: #9a5300; }
.prio-normal   { background: #e7effc; color: #1f5fbf; }
.prio-low      { background: #eef1f5; color: #5b6578; }
.st-open        { background: #e7effc; color: #1f5fbf; }
.st-in_progress { background: #efe8fb; color: #5b33a6; }
.st-waiting     { background: #fff0d9; color: #9a5300; }
.st-resolved    { background: #e3f4e8; color: #1d6b39; }
.st-closed      { background: #f1f1f1; color: #777; }
.badge-internal { background: #fff3c4; color: #7a5b00; }

.picker { position: relative; }
.picker-results { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); background: #fff;
                  border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 8px 24px rgba(20, 30, 50, 0.12);
                  max-height: 320px; overflow-y: auto; }
.picker-option { padding: 8px 12px; cursor: pointer; display: flex; flex-direction: column; border-bottom: 1px solid #f0f2f5; }
.picker-option:last-child { border-bottom: 0; }
.picker-option.is-active { background: #eef4fd; }
.picker-name { font-weight: 600; }
.picker-meta { color: var(--muted); font-size: 0.85rem; }
.picker-empty { padding: 10px 12px; color: var(--muted); }

.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.ticket-side .card { margin-bottom: 16px; }
.details-stack { grid-template-columns: 1fr; gap: 2px; }
.details-stack dd { margin-bottom: 10px; }
.message { padding: 16px 20px; margin-bottom: 12px; border-left: 4px solid var(--border); }
.message-original { border-left-color: #8aa4c8; }
.message-staff { border-left-color: var(--primary); }
.message-customer { border-left-color: #2e9e5b; }
.message-internal { border-left-color: #e0b100; background: #fffbea; }
.message-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.message-head time { margin-left: auto; font-size: 0.85rem; }
.message-body { white-space: pre-wrap; word-break: break-word; }
.reply-form { display: flex; flex-direction: column; gap: 12px; }
.reply-form.is-internal { background: #fffbea; border-color: #ecd98a; }
.reply-form .form-actions { justify-content: space-between; }
.segmented { display: flex; gap: 16px; }
.segmented label { flex-direction: row; align-items: center; gap: 6px; font-weight: 600; }
.ticket-side input[readonly] { background: #f6f7f9; }

/* Customer-facing pages */
.public-head { padding: 16px 24px; background: #16202f; }
.public-head .brand { color: #fff; font-weight: 700; }
.container-narrow { max-width: 820px; }
.public-foot { margin-top: 24px; }

@media (max-width: 900px) {
    .ticket-layout { grid-template-columns: 1fr; }
}
a.stat-link { color: inherit; }
a.stat-link:hover { text-decoration: none; border-color: #b8cff2; }
.stat-alert { border-color: #f0b4ae; background: #fff6f5; }
.stat-alert .stat-num { color: #a1160d; }

/* ---- Labor --------------------------------------------------------------- */
.labor-form { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; padding: 16px 20px; border-top: 1px solid var(--border); background: #fafbfc; }
.labor-form label { min-width: 120px; }
.labor-form .labor-desc { flex: 1 1 260px; }
.labor-form label.check { min-width: 0; padding-bottom: 8px; }
.input-duration { max-width: 120px; font-family: var(--mono); }
.reply-time { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 12px; background: #f6f7f9; border-radius: 6px; }
.reply-form.is-internal .reply-time { background: #fff6d6; }
.row-actions { display: flex; gap: 10px; align-items: center; }
.row-actions form { margin: 0; }
.btn-text { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.btn-text:hover { text-decoration: underline; }
.btn-text.danger { color: var(--danger); }
.form-narrow { max-width: 720px; }

/* ---- Products ------------------------------------------------------------ */
.input-prefix { display: flex; align-items: stretch; }
.input-prefix > span { display: flex; align-items: center; padding: 0 10px; border: 1px solid var(--border); border-right: 0;
                       border-radius: 6px 0 0 6px; background: #f6f7f9; color: var(--muted); font-weight: normal; }
.input-prefix > input { border-radius: 0 6px 6px 0; }
.has-error .input-prefix > span { border-color: var(--danger); }
.billing-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px; }
.badge-recurring { background: #e6f4f1; color: #116b5c; }
[hidden] { display: none !important; }

/* ---- Billing ------------------------------------------------------------- */
.text-danger { color: var(--danger); }
.row-muted td { color: var(--muted); }
.inv-open     { background: #e7effc; color: #1f5fbf; }
.inv-partial  { background: #fff0d9; color: #9a5300; }
.inv-paid     { background: #e3f4e8; color: #1d6b39; }
.inv-void     { background: #f1f1f1; color: #777; }
.inv-overdue  { background: #fde2e1; color: #a1160d; }
.table tfoot td { border-top: 1px solid var(--border); border-bottom: 0; }

.invoice-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.invoice-doc { padding: 32px; position: relative; }
.invoice-head { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.invoice-from { font-weight: 700; font-size: 1.1rem; }
.invoice-title { font-size: 1.6rem; margin: 4px 0 0; letter-spacing: 0.02em; color: var(--muted); font-weight: 600; }
.invoice-meta { display: grid; grid-template-columns: auto auto; gap: 4px 16px; margin: 0; text-align: right; }
.invoice-meta dt { color: var(--muted); }
.invoice-meta dd { margin: 0; }
.invoice-parties { display: flex; gap: 48px; margin-bottom: 24px; }
.invoice-parties .label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 4px; }
.invoice-lines th, .invoice-lines td { padding-left: 0; padding-right: 12px; }
.invoice-lines td:last-child, .invoice-lines th:last-child { padding-right: 0; }
.invoice-lines .total-row td { font-weight: 700; font-size: 1.05rem; }
.void-stamp { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-18deg); font-size: 5rem; font-weight: 800;
              color: rgba(180, 35, 24, 0.18); letter-spacing: 0.2em; pointer-events: none; margin: 0; }
.invoice-side .card { margin-bottom: 16px; }
.payment-list { list-style: none; margin: 0 0 12px; padding: 0; }
.payment-list li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.payment-form { border-top: 1px solid var(--border); padding-top: 12px; }
.payment-form h3 { margin: 0; font-size: 0.95rem; }
.page-head form { margin: 0; }

@media (max-width: 900px) {
    .invoice-layout { grid-template-columns: 1fr; }
}

@media print {
    .topbar, .no-print, .alert { display: none !important; }
    body { background: #fff; }
    .container { max-width: none; padding: 0; }
    .invoice-layout { display: block; }
    .invoice-doc { border: 0; padding: 0; }
}
.line-period { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.invoice-footer { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 12px; }
.link-label { margin-top: 12px; }

/* ---- Settings ------------------------------------------------------------ */
.subnav { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.subnav a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subnav a:hover { color: var(--text); text-decoration: none; }
.subnav a.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }
.settings-form .card h2 { margin: 0; }
.form-intro { margin: -8px 0 0; }
.input-suffix { display: flex; align-items: stretch; }
.input-suffix > input { border-radius: 6px 0 0 6px; max-width: 140px; }
.input-suffix > span { display: flex; align-items: center; padding: 0 10px; border: 1px solid var(--border); border-left: 0;
                       border-radius: 0 6px 6px 0; background: #f6f7f9; color: var(--muted); font-weight: normal; white-space: nowrap; }
.has-error .input-suffix > span { border-color: var(--danger); }
code { font-family: var(--mono); font-size: 0.9em; background: rgba(0,0,0,0.05); padding: 1px 4px; border-radius: 3px; }

/* ---- One-time invoice form ----------------------------------------------- */
.table-scroll { overflow-x: auto; }
.line-table { min-width: 860px; }
.line-table td { vertical-align: top; padding-top: 8px; padding-bottom: 8px; }
.line-table th, .line-table td { padding-left: 10px; padding-right: 10px; }
.line-table th:first-child, .line-table td:first-child { padding-left: 20px; }
.line-table .col-item { width: 22%; }
.line-table .col-qty { width: 80px; }
.line-table .col-money { width: 120px; }
.line-table select, .line-table input { font-size: 0.9rem; }
.num-input { text-align: right; font-family: var(--mono); }
.cost-col { background: #fbfaf3; }
.line-table td[data-line-total] { padding-top: 16px; }
.line-table tfoot td { border-top: 0; padding-top: 6px; padding-bottom: 6px; }
.line-table tfoot tr:first-child td { border-top: 1px solid var(--border); padding-top: 10px; }
.line-table tfoot .total-row td { font-weight: 700; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.mini-table td { padding: 4px 0; border-bottom: 1px solid #f0f2f5; vertical-align: top; }
.mini-table td.num { padding-left: 10px; white-space: nowrap; }
.mini-table .mini-total td { font-weight: 600; border-bottom: 0; }

/* ---- Reports ------------------------------------------------------------- */
.report-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
a.report-card { color: inherit; }
a.report-card:hover { text-decoration: none; border-color: #b8cff2; }
.report-card h2 { color: var(--primary); }
.chart-card { padding: 16px 20px; }
.bar-chart { width: 100%; height: auto; display: block; }
.bar-chart .axis { stroke: var(--border); }
.bar-chart .bar-revenue, .key-revenue { fill: #1f5fbf; background: #1f5fbf; }
.bar-chart .bar-cost, .key-cost { fill: #e0a43a; background: #e0a43a; }
.bar-chart .tick { font-size: 11px; fill: var(--muted); text-anchor: middle; }
.legend { display: flex; gap: 8px; align-items: center; font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.legend .key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: 10px; }
.legend .key:first-child { margin-left: 0; }
@media print { .filters, .actions { display: none !important; } }
.table tfoot .total-row td { font-weight: 700; }

/* ---- Quotes -------------------------------------------------------------- */
.qt-draft     { background: #eef1f5; color: #5b6578; }
.qt-sent      { background: #e7effc; color: #1f5fbf; }
.qt-accepted  { background: #e3f4e8; color: #1d6b39; }
.qt-cancelled { background: #f1f1f1; color: #777; }
.qt-expired   { background: #fff0d9; color: #9a5300; }
.alert-info { background: #e7effc; color: #1f4f99; }
.quote-title { margin: 0 0 12px; font-size: 1.15rem; }
.quote-terms { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 12px; }
.quote-terms .label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 4px; }
.quote-terms p { margin: 0; }
.accepted-note { margin: 20px 0 0; padding: 10px 14px; background: var(--success-bg); color: var(--success-text); border-radius: 6px; }
.accept-card { border: 2px solid #b8cff2; }
.accept-card h2 { margin-bottom: 4px; }
.btn-accept { align-self: flex-start; padding: 10px 22px; font-size: 1rem; }
.sum-groups { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.sum-group { display: flex; gap: 16px; }
.sum-meta { text-align: right; margin-top: 6px; }
.break { word-break: break-all; }
.bill-options { padding: 16px 20px; border-top: 1px solid var(--border); background: #fafbfc; }
.qty-input { max-width: 90px; }
tr.has-error td { background: #fff6f5; }
.plain-list { list-style: none; margin: 8px 0 0; padding: 0; }
.plain-list li { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.progress { height: 8px; background: #eef1f5; border-radius: 99px; overflow: hidden; margin: 4px 0 10px; }
.progress span { display: block; height: 100%; background: #2e9e5b; width: 0; }
.progress .pct-0 { width: 0%; }
.progress .pct-5 { width: 5%; }
.progress .pct-10 { width: 10%; }
.progress .pct-15 { width: 15%; }
.progress .pct-20 { width: 20%; }
.progress .pct-25 { width: 25%; }
.progress .pct-30 { width: 30%; }
.progress .pct-35 { width: 35%; }
.progress .pct-40 { width: 40%; }
.progress .pct-45 { width: 45%; }
.progress .pct-50 { width: 50%; }
.progress .pct-55 { width: 55%; }
.progress .pct-60 { width: 60%; }
.progress .pct-65 { width: 65%; }
.progress .pct-70 { width: 70%; }
.progress .pct-75 { width: 75%; }
.progress .pct-80 { width: 80%; }
.progress .pct-85 { width: 85%; }
.progress .pct-90 { width: 90%; }
.progress .pct-95 { width: 95%; }
.progress .pct-100 { width: 100%; }
.pager-section { margin: 0; padding: 12px 20px; border-top: 1px solid var(--border); font-size: 0.9rem; }
.pager-off { color: #c3c9d2; }
.is-loading { opacity: 0.55; transition: opacity 0.15s; }
.badge-labor { background: #fff4e0; color: #8a5a00; }
.text-warn { color: #a86400; }
.pad-x { padding: 12px 20px 0; margin: 0; }
.run-billing { display: flex; align-items: center; gap: 12px; }
.run-billing .check { margin: 0; }

/* ---- Customer portal ---- */
.portal-topbar .brand small { font-weight: 400; opacity: 0.7; margin-left: 6px; font-size: 0.8rem; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.tabs a { padding: 8px 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: inherit; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.auth-sub { margin: -8px 0 16px; }
.auth-links { margin-top: 12px; }
.alert-info a { font-weight: 600; }
.portal-card .card-head-row { padding-bottom: 0; align-items: flex-start; }
.portal-card h2 { margin-bottom: 4px; }
.portal-card p { margin: 0; }
.portal-card .actions { display: flex; gap: 8px; }
.portal .card-flush { overflow-x: auto; }
.portal .table td.mono { white-space: nowrap; }
@media (max-width: 720px) {
    .portal-topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 8px 16px; }
    .portal-topbar .brand { flex: 1; }
    .portal-topbar .userbox small { display: none; }
    .portal-topbar .mainnav { order: 3; flex-basis: 100%; overflow-x: auto; margin: 0 -8px; }
    .portal .container { padding: 16px; }
    .portal .page-head .actions { width: 100%; }
}
.logo-card { margin-bottom: 20px; }
.logo-row { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.logo-preview { width: 260px; height: 90px; border: 1px dashed var(--border); border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 8px; background: #fff; }
.logo-preview img { max-width: 100%; max-height: 100%; }
.logo-actions { display: flex; flex-direction: column; gap: 8px; }
.inline-upload { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.doc-logo { max-width: 240px; max-height: 84px; display: block; margin-left: auto; margin-bottom: 12px; }
.doc-section { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 20px 0 4px; }
.invoice-lines .section-total td { font-weight: 700; border-bottom: 2px solid #1d2330; }
.doc-totals { margin-top: 16px; }
.doc-totals td { padding-top: 6px; padding-bottom: 6px; }
.doc-taxid { margin-top: 16px; }
.invoice-head .invoice-meta { margin-left: auto; }
.auth-logo { display: block; max-width: 240px; max-height: 80px; margin: 0 auto 20px; }
.card-entry .label-text { display: block; font-weight: 600; margin-bottom: 6px; }
.card-element { border: 1px solid var(--border); border-radius: 6px; padding: 12px; background: #fff; min-height: 44px; }
.card-element.StripeElement--focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 95, 191, 0.15); }
.card-element.StripeElement--invalid { border-color: var(--danger); }
.saved-card { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.card-badge { font-family: var(--mono, monospace); background: #eef1f6; border-radius: 6px; padding: 6px 10px; }
.charge-form { border-bottom: 1px solid var(--border); padding-bottom: 14px; margin-bottom: 14px; }
.charge-form h3 { margin: 0; }
.attempts { margin: 0 0 14px; }
.attempts summary { cursor: pointer; color: var(--muted); }
.pay-card { margin-top: 20px; border: 2px solid #b8cff2; }
.pay-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.actions-row { display: flex; gap: 12px; align-items: center; margin-top: 12px; }
.danger-zone { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ---- Customer page: header, stat tiles, tabs, overview ---------------------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.alert-info { background: #eaf2fd; color: #1c4587; }
.icon { width: 18px; height: 18px; vertical-align: middle; }
.icon-sm { width: 14px; height: 14px; }
.icon-link { color: var(--muted); display: inline-flex; padding: 4px; border-radius: 6px; }
.icon-link:hover { color: var(--primary); background: #eef3fb; }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.link-button:hover { text-decoration: underline; }
.inline-form { display: inline; }
.customer-head { align-items: flex-start; }
.customer-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 6px 0 0; }
.customer-head .actions { align-items: flex-start; }

.menu { position: relative; }
.menu > summary { list-style: none; display: inline-flex; align-items: center; gap: 4px; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 180px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(16, 24, 40, 0.12); padding: 4px; }
.menu-list a { display: block; padding: 8px 12px; border-radius: 6px; color: var(--text); }
.menu-list a:hover { background: #f1f4f8; text-decoration: none; }

.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 0 0 20px; }
.stat-tile { display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; color: var(--text); }
.stat-tile:hover { border-color: #b9c4d3; text-decoration: none; }
.stat-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 1.45rem; font-weight: 700; line-height: 1.25; }
.stat-value small { font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.stat-sub { font-size: 0.85rem; color: var(--muted); }
.stat-alert { border-color: #f1b8b2; }
.stat-alert .stat-sub { color: var(--danger); font-weight: 600; }

.customer-tabs { margin-bottom: 16px; overflow-x: auto; white-space: nowrap; scrollbar-width: thin; }
.customer-tabs a { flex: 0 0 auto; }
.tab-count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 2px; border-radius: 999px; background: #eef1f5; color: var(--muted); font-size: 0.75rem; font-weight: 600; text-align: center; }
.customer-tabs a.active .tab-count { background: #e3ecfa; color: var(--primary); }
.tab-panel[hidden] { display: none; }

.overview-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
.overview-grid .card { margin-bottom: 20px; }
.head-links { font-size: 0.9rem; color: var(--muted); }
.head-note { margin: 4px 0 0; max-width: 60ch; }
.row-list { list-style: none; margin: 0; padding: 0; }
.row-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 20px; border-top: 1px solid var(--border); }
.row-list .row-end { text-align: right; white-space: nowrap; }
.row-list .row-end .badge + .badge { margin-left: 4px; }
.side-card h2 { margin: 0; }
.side-card > p { margin: 8px 0 0; }
.side-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.danger-card { border-color: #f1c4bf; }
.danger-card h2 { color: var(--danger); margin-bottom: 10px; }
.danger-card .stack { gap: 10px; }
.danger-card p { margin: 0; }

.note-form { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 16px; }
.note-form textarea { flex: 1; min-height: 42px; resize: vertical; font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.activity li:first-child { border-top: 0; }
.activity-dot { flex: 0 0 28px; height: 28px; border-radius: 50%; background: #eef1f5; color: #46516a; display: inline-flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; }
.activity-note .activity-dot { background: #fff4d6; color: #8a5a00; }
.activity-payment .activity-dot { background: var(--success-bg); color: var(--success-text); }
.activity-ticket .activity-dot { background: #e3ecfa; color: var(--primary); }
.activity-body { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.activity-note .prewrap { background: #fffbeb; border: 1px solid #f6e7b5; border-radius: 6px; padding: 8px 10px; margin-bottom: 4px; }
#activity .pager-section { padding: 12px 0 0; }

@media (max-width: 900px) {
    .overview-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
    .customer-head .actions { width: 100%; }
    .stat-tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-tile { padding: 12px; }
    .stat-value { font-size: 1.2rem; }
    .menu-list { left: 0; right: auto; }
    .note-form { flex-direction: column; align-items: stretch; }
    .row-list li { padding: 10px 16px; }
}
@media print { .stat-tiles, .customer-tabs, .note-form, .danger-card { display: none !important; } .tab-panel[hidden] { display: block; } }

/* ---- Move a location or service to another customer ------------------------- */
.form-actions-end { margin-left: auto; }
.move-from { margin: 0; line-height: 1.6; }
.move-list h2 { font-size: 0.95rem; margin: 18px 0 6px; }
.move-list h2:first-child { margin-top: 4px; }
.move-list ul { margin: 0; padding-left: 20px; }
.move-list li { margin: 4px 0; }
.move-list .check { margin: 6px 0; }
.move-list p { margin: 4px 0 0; }

/* ---- Product custom field ------------------------------------------------------ */
.custom-field-box .custom-field-grid { padding: 0; margin-top: 8px; }
.custom-field-box > p { margin: 4px 0 0; }
.field-value { margin-top: 2px; overflow-wrap: anywhere; }
.usage-month { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.usage-month input[type=month] { width: auto; }
.usage-bill { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding-top: 12px; }


/* ---- Password manager ------------------------------------------------------------ */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; margin-left: 2px;
            border: 1px solid transparent; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; vertical-align: middle; }
.icon-btn:hover, .icon-btn:focus-visible { color: var(--primary); background: #eef3fb; border-color: #d6e2f5; }
.icon-btn.is-done { color: var(--success-text); background: var(--success-bg); }
.icon-btn.is-failed { color: var(--danger); background: var(--error-bg); }
.icon-btn .when-shown, .icon-btn.is-revealed .when-hidden { display: none; }
.icon-btn.is-revealed .when-shown { display: inline-flex; }
.secret { display: inline-block; min-width: 9ch; letter-spacing: 0.08em; vertical-align: middle; }
.secret.is-revealed { letter-spacing: 0; background: #fffbeb; border-radius: 4px; padding: 1px 6px; user-select: all; }
.passwords-table td { vertical-align: top; }
.passwords-table .prewrap { max-width: 34ch; overflow-wrap: anywhere; }
.secret-input { display: flex; gap: 6px; align-items: center; }
.secret-input input { flex: 1; font-family: var(--mono); }

/* ---- Webby Portal: clients ------------------------------------------------- */
.badge-closed { background: #fde2e1; color: #a1160d; }
.text-success { color: var(--success-text); }
.tight { margin: 0 0 10px; }
.pad-top { padding-top: 16px; }
.grow { flex: 1; }
.field-label { font-weight: 600; font-size: 0.9rem; }
.topsearch input { width: 200px; padding: 6px 10px; border-radius: 6px; border: 1px solid #2b3d5a; background: #24324a; color: #fff; }
.topsearch input::placeholder { color: #9aa6b8; }
.client-company { margin: 2px 0 0; font-size: 1.05rem; color: var(--muted); }
.group-badge { background: #eef1f5; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.button-row form { margin: 0; }

.sticky-notes { display: grid; gap: 8px; margin: 0 0 16px; }
.sticky-note { background: #fff8db; border: 1px solid #f0dc8a; border-radius: var(--radius); padding: 10px 14px; }
.sticky-note .muted { margin-top: 4px; }
.badge-sticky { background: #fff0b3; color: #7a5b00; }

.note-compose { margin-bottom: 20px; }
.note-compose .form-actions { justify-content: space-between; flex-wrap: wrap; }
.note-list { list-style: none; margin: 0; padding: 0; }
.note-list li { padding: 12px 0; border-top: 1px solid var(--border); }
.note-list li.is-sticky { background: #fffbeb; margin: 0 -20px; padding: 12px 20px; }
.note-list .muted { margin-top: 4px; }
.note-edit { margin-top: 6px; }
.note-edit summary { cursor: pointer; color: var(--primary); display: inline; }
.note-edit[open] summary { margin-bottom: 8px; display: block; }
.note-edit form + form { margin-top: 6px; }

.credit-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-top: 12px; }
.credit-form label { min-width: 120px; }
.credit-form .segmented { padding-bottom: 8px; }

.pref-list { display: flex; flex-direction: column; gap: 10px; }
.pref-list label.check { align-items: flex-start; }
.pref-list label.check input { margin-top: 4px; }
.pref-summary { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
.pref-summary li { display: flex; justify-content: space-between; padding: 4px 0; border-top: 1px solid #f0f2f5; }
.pref-summary li:first-child { border-top: 0; }
.pref-summary li span { font-weight: 600; }
.pref-summary li.on span { color: var(--success-text); }
.pref-summary li.off span { color: var(--muted); }

.card.danger-zone { display: block; margin-top: 0; border-top: 1px solid var(--border); }
.card.danger-zone hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.card.danger-zone form { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
form.card.danger-zone { display: flex; }

.log-list li { padding: 10px 0; }
.change-table { margin: 6px 0 2px; max-width: 640px; }
.change-table td:first-child { color: var(--muted); padding-right: 12px; white-space: nowrap; }
.change-table td { overflow-wrap: anywhere; }

.email-pending, .email-sending { background: #e7effc; color: #1f5fbf; }
.email-sent { background: #e3f4e8; color: #1d6b39; }
.email-failed { background: #fde2e1; color: #a1160d; }
.email-body { white-space: pre-wrap; word-break: break-word; font: 0.92rem/1.55 var(--mono); margin: 0; }

.impersonation-bar { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; padding: 8px 16px; background: #fff3c4; color: #5c4400; font-size: 0.9rem; border-bottom: 1px solid #ecd98a; }
.impersonation-bar form { margin: 0; }

@media (max-width: 720px) {
    .topsearch { order: 2; flex: 1; }
    .topsearch input { width: 100%; }
    .credit-form { flex-direction: column; align-items: stretch; }
}
.card.danger-zone p { margin: 0; }

/* ---- Packages ------------------------------------------------------------------ */
.package-group .card-head-row { align-items: flex-start; }
.package-table td:first-child { max-width: 380px; }
.package-desc { overflow-wrap: anywhere; }
.price-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.money-input { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.money-input span { padding: 0 2px 0 10px; color: var(--muted); font-weight: normal; }
.money-input input { border: 0; outline-offset: -2px; }
.has-error .money-input { border-color: var(--danger); }
.inline-add { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
@media (max-width: 720px) { .price-grid { grid-template-columns: 1fr 1fr; } }

/* ---- Modules ------------------------------------------------------------------- */
.module-list { display: grid; gap: 12px; }
.module-card { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 0; }
.module-card.is-enabled { border-left: 4px solid var(--success-text); }
.module-card h2 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.module-main { flex: 1; min-width: 260px; }
.module-main p { margin: 0 0 6px; }
.module-actions { display: flex; gap: 8px; align-items: center; }
.module-actions form { margin: 0; }
.module-check { display: flex; flex-direction: column; gap: 2px; }
.module-check small { padding-left: 26px; }
.enable-row { padding-top: 8px; border-top: 1px solid var(--border); }
.module-options { padding: 14px 16px; background: #f8fafc; border: 1px solid var(--border); border-radius: 6px; }
.module-options h3 { margin: 0; font-size: 0.95rem; }
.module-badge { margin-left: 6px; background: #e7effc; color: #1f5fbf; }
.lookup-result { margin-top: 12px; }

/* ---- Services ------------------------------------------------------------------ */
.svc-active { background: #e3f4e8; color: #1d6b39; }
.svc-pending { background: #e7effc; color: #1f5fbf; }
.svc-suspended { background: #fff0d9; color: #9a5300; }
.svc-cancelled { background: #f1f1f1; color: #777; }
.service-table tr.is-muted td { color: var(--muted); }
.service-table .inline-form { display: inline; margin: 0; }
.head-links .inline-form { display: inline; margin: 0; }
.service-extra { display: grid; gap: 0; margin-top: 20px; }
.service-extra form.card { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.service-extra h2 { margin: 0; }
.service-extra p { margin: 0; }
.portal-services td { vertical-align: middle; }

/* ---- Server accounts ------------------------------------------------------------ */
.account-card { margin-top: 20px; }
.account-card h2 { display: flex; gap: 8px; align-items: center; }
.account-card h3 { font-size: 0.95rem; margin: 16px 0 8px; }
.account-actions { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.account-actions form { margin: 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.account-actions .inline-add { align-items: flex-end; }
.terminate-form { padding-top: 12px; border-top: 1px dashed var(--border); }
.acct-active { background: #e3f4e8; color: #1d6b39; }
.acct-suspended { background: #fff0d9; color: #9a5300; }
.acct-terminated { background: #f1f1f1; color: #777; }
.secret-value { font-family: var(--mono); background: #fff8db; padding: 2px 6px; border-radius: 4px; user-select: all; }
.acct-line { margin-top: 2px; font-size: 0.8rem; }

/* ---- Servers -------------------------------------------------------------------- */
.capacity { height: 4px; background: #eef1f5; border-radius: 2px; margin-top: 4px; width: 90px; margin-left: auto; overflow: hidden; }
.capacity span { display: block; height: 100%; width: 0; background: var(--primary); }
.capacity span.is-high { background: #d97706; }
a.strong { font-weight: 700; }
