:root {
    --bg: #f5f6f8; --card: #fff; --line: #e2e5ea; --text: #1b2330; --muted: #6a7585;
    --brand: #0b5cff; --up: #17a34a; --down: #dc2626; --warn: #d99a06; --idle: #c9ced6;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.topbar { background: #0E1F2B; color: #fff; padding: .75rem 1.25rem; display: flex; gap: 1rem; align-items: center; }
.topbar a { color: #cdd5e1; }
.topbar .brand { display: flex; align-items: center; }
.topbar .brand img, .powered img { display: block; }
.powered { display: block; width: fit-content; margin: .4rem auto 0; }
.login-logo { margin: .4rem 0 1.4rem; }
.login-logo img { display: block; margin: 0 auto; }
.user-menu { margin-left: auto; }
.user-menu summary { cursor: pointer; color: #cdd5e1; font-size: .9rem; padding: .3rem .6rem; border-radius: 6px; }
.user-menu summary:hover, .user-menu[open] summary { background: #1c2f3d; color: #fff; }
.user-menu .menu-list { min-width: 12rem; }
.mainnav { display: flex; gap: .25rem; margin-left: 1rem; }
.mainnav a { padding: .3rem .7rem; border-radius: 6px; }
.mainnav a:hover { background: #1d2939; text-decoration: none; }
.mainnav a.on { background: #344054; color: #fff; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.wrap.narrow { max-width: 760px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1.25rem; margin-bottom: 1.25rem; }
.card-head { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.card-head h2 { margin: 0 auto 0 0; }

.btn { display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 7px; padding: .45rem .9rem; font: inherit; cursor: pointer; }
.btn:hover { background: #f1f3f6; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #094ad1; }
.btn.danger { color: var(--down); }
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; background: #e7f6ec; border: 1px solid #b7e2c4; }
.flash.error { background: #fdecec; border-color: #f5bcbc; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; color: #fff; background: var(--idle); white-space: nowrap; }
.badge.up, .badge.synced { background: var(--up); }
.badge.down, .badge.failed { background: var(--down); }
.badge.pending { background: var(--warn); }
.badge.paused, .badge.unknown { background: #8892a0; }

.field { margin-bottom: .9rem; }
.field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .2rem; }
.field input[type=text], .field input[type=search], .field input[type=number], .field input[type=date], .field input[type=email], .field input[type=password], .field input[type=url], .field select, .field textarea {
    width: 100%; padding: .5rem .6rem; border: 1px solid #cfd4dc; border-radius: 7px; font: inherit; background: #fff;
}
.field textarea { min-height: 5rem; }
.field ul { list-style: none; margin: .25rem 0 0; padding: 0; color: var(--down); font-size: .85rem; }
.check { display: flex; gap: .4rem; align-items: center; font-weight: 500; }
.grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.address { display: grid; grid-template-columns: 1fr auto; gap: 0 .5rem; }

.row { border: 1px solid var(--line); border-radius: 8px; padding: .9rem .9rem .2rem; margin-bottom: .75rem; background: #fbfcfd; }
.row-head { display: flex; gap: .5rem; align-items: center; margin-bottom: .6rem; }
.row-head .spacer { margin-left: auto; }
.row-error { color: var(--down); font-size: .85rem; margin: 0 0 .7rem; }

/* Public status page */
.status-hero { border-radius: 10px; padding: 1.1rem 1.25rem; color: #fff; font-size: 1.15rem; font-weight: 600; margin-bottom: 1.25rem; background: #8892a0; }
.status-hero.up { background: var(--up); }
.status-hero.down { background: var(--down); }
.monitor { padding: .9rem 0; border-bottom: 1px solid var(--line); }
.monitor:last-child { border-bottom: 0; }
.monitor-head { display: flex; gap: .6rem; align-items: center; margin-bottom: .5rem; }
.monitor-head strong { margin-right: auto; }
.bars { display: flex; gap: 2px; height: 30px; }
.bars span { flex: 1; border-radius: 2px; background: var(--idle); position: relative; transition: transform .1s; }
.bars span:hover { transform: scaleY(1.2); filter: brightness(.88); z-index: 5; }
/* Tooltip. Inside a scaled bar, so the vertical stretch is undone on the bubble itself. */
.bars span:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 5px); left: 50%; transform: translateX(-50%) scaleY(.8333); transform-origin: bottom; white-space: nowrap; padding: .3rem .55rem; border-radius: 6px; background: #0e1f2b; color: #fff; font-size: .78rem; line-height: 1.2; pointer-events: none; box-shadow: 0 4px 12px rgba(16, 24, 40, .2); }
/* Near the edges the bubble is anchored to the bar's side so it stays on the page. */
.bars span:nth-child(-n+30):hover::after { left: 0; transform: scaleY(.8333); }
.bars span:nth-last-child(-n+30):hover::after { left: auto; right: 0; transform: scaleY(.8333); }
.bars .ok { background: var(--up); }
.bars .some { background: var(--warn); }
.bars .bad { background: var(--down); }
.bars-key { display: flex; flex-wrap: wrap; gap: .35rem 1.1rem; list-style: none; margin: .9rem 0 0; padding: 0; font-size: .8rem; color: var(--muted); }
.bars-key li { display: flex; align-items: center; gap: .4rem; }
.bars-key span { width: .75rem; height: .75rem; border-radius: 2px; background: var(--idle); }
.bars-key .ok { background: var(--up); }
.bars-key .some { background: var(--warn); }
.bars-key .bad { background: var(--down); }
.bars-legend { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; margin-top: 2rem; }

.login { max-width: 380px; margin: 12vh auto 0; }

/* Admin table, search and pagination */
.search { display: flex; gap: .5rem; margin-bottom: 1rem; }
.search input { flex: 1; padding: .5rem .7rem; border: 1px solid #cfd4dc; border-radius: 7px; font: inherit; background: #fff; }
.table-card { padding: 0; overflow-x: auto; }
table.data th { background: #f8f9fb; position: sticky; top: 0; }
table.data th, table.data td { padding: .65rem .9rem; }
table.data tbody tr:hover { background: #fafbfc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.page-line { display: flex; gap: .45rem; align-items: baseline; flex-wrap: wrap; padding: .1rem 0; }
.row-actions { white-space: nowrap; text-align: right; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.pager-links { display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; }
.btn.current { background: #101828; border-color: #101828; color: #fff; cursor: default; }
.nowrap { white-space: nowrap; }
.wrap.wide { max-width: 1500px; }
/* Room for long company names; they wrap only past ~40 characters. */
table.data .customer-name { min-width: 22rem; }
.badge.sub-verified { background: var(--up); }
.badge.sub-pending { background: var(--warn); }
.badge.sub-unsubscribed { background: #8892a0; }

/* Page setup: header, tabs, compact one-line rows, sticky save bar */
.crumbs { margin: 0 0 .4rem; }
.page-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.spacer { margin-left: auto; }
.hint { margin-left: auto; text-align: right; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; overflow-x: auto; }
.tabs button { border: 0; background: none; font: inherit; padding: .6rem .9rem; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); font-weight: 600; border-bottom-color: var(--brand); }
.tabs .count { background: #e8ebf0; border-radius: 999px; padding: 0 .45rem; font-size: .75rem; font-weight: 600; color: var(--muted); }

.items:empty::before { content: attr(data-empty); display: block; color: var(--muted); padding: .9rem 0; }
.item { border-top: 1px solid var(--line); padding: .55rem 0; }
.item-header { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding-bottom: .35rem; }
.item-line, .item-header { display: grid; gap: .6rem; align-items: center; }
.monitor-cols { grid-template-columns: 1.1rem minmax(0, 1.1fr) minmax(0, 2fr) 11.5rem 5.5rem 5.6rem 2rem; }
.contact-cols { grid-template-columns: 6.6rem minmax(0, 1.7fr) minmax(0, 1fr) 9.5rem 7.2rem 5.6rem 2rem; }
.cell input, .cell select, .item-extra input {
    width: 100%; padding: .42rem .55rem; border: 1px solid #cfd4dc; border-radius: 7px; font: inherit; background: #fff; min-width: 0;
}
.cell input:focus, .cell select:focus, .item-extra input:focus, .field input:focus, .field select:focus, .field textarea:focus, .search input:focus {
    outline: 2px solid #b9d0ff; border-color: var(--brand);
}
.cell ul, .item > ul { list-style: none; margin: .2rem 0 0; padding: 0; color: var(--down); font-size: .82rem; }
.item-state { display: flex; align-items: center; }
.dot { width: .7rem; height: .7rem; border-radius: 50%; background: var(--idle); display: inline-block; }
.dot.up { background: var(--up); } .dot.down { background: var(--down); } .dot.paused { background: #8892a0; }
.dot.new { background: #fff; border: 2px dashed #a9b1bd; }
.switch { display: flex; gap: .35rem; align-items: center; font-size: .85rem; white-space: nowrap; cursor: pointer; }
.switch.off { visibility: hidden; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; width: 2rem; height: 2rem; border-radius: 7px; }
.icon-btn:hover { background: #fdecec; color: var(--down); }
.item-extra { display: grid; justify-content: start; grid-template-columns: auto minmax(0, 24rem); gap: .6rem; align-items: center; margin: .45rem 0 0 1.7rem; font-size: .85rem; }
.item-extra[hidden] { display: none; }
.item-note { margin: .4rem 0 0 1.7rem; font-size: .85rem; color: var(--muted); }
.item-note.failed { color: var(--down); }
.btn.add { margin-top: .6rem; border-style: dashed; color: var(--brand); }
details.help { margin-top: .9rem; font-size: .88rem; color: var(--muted); }
details.help summary { cursor: pointer; color: var(--brand); }
details.help ul { margin: .5rem 0 0; padding-left: 1.1rem; }
.under { margin: -.55rem 0 .9rem; }
.checks { display: flex; gap: 0 1.5rem; flex-wrap: wrap; }
.checks .field { margin-bottom: 0; }
.empty { padding: 1.25rem; margin: 0; }

.savebar { position: sticky; bottom: 0; z-index: 5; display: flex; gap: .5rem; align-items: center; background: rgba(255, 255, 255, .96); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .9rem; box-shadow: 0 -4px 16px rgba(16, 24, 40, .08); margin-bottom: 1.25rem; }
.savebar [data-dirty-note] { color: #b45309; font-weight: 600; }

details.menu { position: relative; }
details.menu summary { list-style: none; }
details.menu summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + .3rem); z-index: 10; background: #fff; border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 8px 24px rgba(16, 24, 40, .14); padding: .3rem; min-width: 17rem; }
.menu-list a { display: block; padding: .5rem .7rem; border-radius: 6px; color: var(--text); }
.topbar .menu-list a { color: var(--text); }
.menu-list a:hover { background: #f1f3f6; text-decoration: none; }
.menu-list button { display: block; width: 100%; text-align: left; border: 0; background: none; font: inherit; padding: .5rem .7rem; border-radius: 6px; cursor: pointer; color: var(--text); }
.menu-list button:hover { background: #f1f3f6; }
.menu-list button.danger { color: var(--down); }

/* Customers table */
table.data .customer-name { min-width: 12rem; }
table.data th, table.data td { padding: .65rem .7rem; }
.page-line { flex-wrap: nowrap; white-space: nowrap; }
.logins { font-weight: 400; margin-top: .15rem; }

@media (max-width: 860px) {
    .item-header { display: none; }
    .item-line { grid-template-columns: 1fr 1fr auto; }
    .item-line .item-state { grid-column: 1 / -1; }
    .item-line .cell { grid-column: 1 / -1; }
    .cell::before { content: attr(data-label); display: block; font-size: .78rem; font-weight: 600; color: var(--muted); margin-bottom: .15rem; }
    .item-line .icon-btn { grid-column: 3; justify-self: end; }
    .monitor-cols .switch { grid-column: 1 / 3; }
    .switch.off { display: none; }
    .item-extra { grid-template-columns: 1fr; margin-left: 0; }
    .item-note { margin-left: 0; }
    .hint { display: none; }
    .page-head .spacer { display: none; }
}
[data-dirty-form] { display: flex; flex-direction: column; }
[data-dirty-form] > .card.first { order: -1; }

/* Clickable rows and the read-only customer view */
tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover { background: #f3f6fc; }
a.row-link { color: var(--text); }
.facts { display: flex; gap: .4rem 2rem; flex-wrap: wrap; margin: 0; }
.facts div { min-width: 8rem; }
.facts dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; }
.view-page { scroll-margin-top: 1rem; }
.view-page:target { border-color: var(--brand); box-shadow: 0 0 0 2px #d6e4ff; }
.view-page h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin: 1.1rem 0 .3rem; }
.view-page table td, .view-page table th { padding: .4rem .5rem; }
.url { word-break: break-all; }
.dot.unknown { background: var(--idle); }

/* Customer view: invoice card and the per-page overview */
.invoice { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1rem 2rem; }
.invoice h3, .view-cols h3 { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 .4rem; }
.invoice p { margin: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .15rem .9rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv dt { white-space: nowrap; }
.note-warn { background: #fff7e6; border: 1px solid #f3d9a4; color: #8a5a00; border-radius: 8px; padding: .5rem .8rem; margin: 0 0 1rem; font-size: .9rem; }
.tag-private { font-size: .72rem; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: .05rem .5rem; }

.view-page .page-head { margin-bottom: .75rem; }
.mon-list { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.mon { display: grid; grid-template-columns: 1rem minmax(0, 1.4fr) minmax(8rem, .8fr) minmax(0, 1.5fr) 4.6rem; gap: 1rem; align-items: center; padding: .65rem .9rem; border-top: 1px solid var(--line); }
.mon:first-child { border-top: 0; }
.mon.is-down { background: #fef4f4; }
.mon-name { font-weight: 600; }
.mon-url { display: block; font-size: .82rem; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mon-error { grid-column: 2 / -1; margin: -.3rem 0 0; font-size: .82rem; color: var(--down); }
.mini-bars { display: flex; gap: 1px; height: 22px; }
.mini-bars span { flex: 1; border-radius: 1px; background: var(--idle); }
.mini-bars .ok { background: var(--up); } .mini-bars .some { background: var(--warn); } .mini-bars .bad { background: var(--down); }
.percent { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.view-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 1.25rem 2rem; margin-top: 1.1rem; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; gap: .6rem; align-items: baseline; padding: .4rem 0; border-top: 1px solid var(--line); }
.rows li:first-child { border-top: 0; }
.rows .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.rows .when { white-space: nowrap; font-variant-numeric: tabular-nums; }
.rows .dur { white-space: nowrap; width: 4.5rem; text-align: right; font-variant-numeric: tabular-nums; }
.chip { min-width: 3.1rem; text-align: center; font-size: .72rem; font-weight: 700; letter-spacing: .03em; color: var(--muted); background: #eef0f4; border-radius: 5px; padding: .05rem .4rem; white-space: nowrap; }
@media (max-width: 860px) {
    .mon { grid-template-columns: 1rem minmax(0, 1fr) 4.6rem; }
    .mon-check { grid-column: 2 / -1; }
    .mon .mini-bars { grid-column: 2 / -1; grid-row: 3; }
    .view-cols { grid-template-columns: 1fr; }
}

/* Invoices */
.line-cols { grid-template-columns: 1.4rem minmax(0, 3fr) 5.5rem 5rem 8.5rem 8rem 2rem; align-items: start; }
.line-cols .cell textarea { width: 100%; padding: .42rem .55rem; border: 1px solid #cfd4dc; border-radius: 7px; font: inherit; resize: vertical; min-height: 2.4rem; }
.line-cols .line-no, .line-cols .line-total { padding-top: .5rem; }
.line-total, .sum { text-align: right; font-variant-numeric: tabular-nums; }
.invoice-sum { display: flex; justify-content: flex-end; gap: 1rem; align-items: baseline; margin-top: .8rem; font-size: 1.1rem; font-weight: 700; }
.badge.inv-paid { background: var(--up); } .badge.inv-open { background: #3b82f6; } .badge.inv-overdue { background: var(--down); } .badge.inv-cancelled { background: #8892a0; }
tr.cancelled td { color: var(--muted); text-decoration: line-through; }
tr.cancelled td.keep { text-decoration: none; }
.pdf-frame { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.split { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.logo-preview { max-height: 48px; border: 1px solid var(--line); border-radius: 6px; padding: .3rem; background: #fff; }
@media (max-width: 860px) {
    .topbar { flex-wrap: wrap; }
    .mainnav { order: 3; width: 100%; margin-left: 0; }
    .line-cols .line-no { display: none; }
}
.search select { padding: .5rem .6rem; border: 1px solid #cfd4dc; border-radius: 7px; font: inherit; background: #fff; }
.section-title { font-size: 1rem; margin: 1.6rem 0 .6rem; }
.ua { max-width: 26rem; overflow-wrap: anywhere; }
.text-down { color: var(--down); }
.lookup { position: relative; }
.lookup-wrap { position: relative; }
.field .lookup-list { position: absolute; left: 0; right: 0; top: calc(100% + .25rem); z-index: 20; margin: 0; padding: .3rem; list-style: none; color: inherit; font-size: .92rem; background: #fff; border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 8px 24px rgba(16, 24, 40, .14); max-height: 19rem; overflow-y: auto; }
.lookup-list li { padding: .45rem .6rem; border-radius: 6px; cursor: pointer; }
.lookup-list li strong { display: block; font-weight: 600; }
.lookup-list li span { color: var(--muted); font-size: .85rem; }
.lookup-list li:hover, .lookup-list li[aria-selected="true"] { background: #eef3ff; }
