/* Plain CSS, no build step. Colours live in the variables at the top. */
:root {
    --bg: #eef0f2;
    --card: #ffffff;
    --fg: #1c2530;
    --muted: #5d6975;
    --line: #d7dce1;
    --field: #f8f9fa;
    --accent: #1f5f7a;
    --accent-hover: #194d63;
    --accent-soft: #e2eef3;
    --ok: #2c7a4b;
    --ok-soft: #e3f2e8;
    --danger: #b3261e;
    --danger-soft: #fbe9e7;
    --warn: #8a5a00;
    --warn-soft: #fff3d6;
    --radius: 8px;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 14px; }
code { font-family: var(--mono); font-size: 12px; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); margin: 4px 0 0; }
.small { font-size: 12px; }
.num { text-align: right; }
.inline { display: inline; }

/* Top bar */
.topbar { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; padding: 12px 24px; background: var(--fg); }
.brand { color: #fff; font-weight: 600; text-decoration: none; font-size: 15px; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 4px; }
.topbar nav a { color: #c8d0d8; text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.topbar nav a:hover { color: #fff; }
.topbar nav a.active { color: #fff; background: rgba(255, 255, 255, .12); }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card.narrow { max-width: 720px; }
.card.empty { text-align: center; padding: 40px 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid > .card { margin-bottom: 0; }
.form-grid + .card, .form-grid + section { margin-top: 16px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 800px) {
    .form-grid, .row { grid-template-columns: 1fr; }
}

/* Flash messages */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--danger-soft); color: var(--danger); }

/* Form fields */
.field { margin-bottom: 10px; min-width: 0; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.req { color: var(--danger); margin-left: 2px; }
input, select, textarea {
    width: 100%; font: inherit; color: inherit; background: var(--field);
    border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); background-color: #fff; }

/*
 * Selects: hide the browser's arrow (it hugs the far edge on macOS) and draw our own
 * chevron 12px in from the right. Uses background-color elsewhere so states don't wipe the icon.
 */
select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 34px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%235d6975' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
    cursor: pointer;
    text-overflow: ellipsis;
}
select:hover { border-color: #b9c1c9; }
select:focus {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%231f5f7a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");
}
.field.num input, input.num { text-align: right; }
.is-invalid { border-color: var(--danger) !important; background-color: var(--danger-soft); }
.error { color: var(--danger); font-size: 12px; margin: 3px 0 0; }
.error:empty { display: none; }
.hint { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; cursor: pointer; }
.check input { width: auto; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

/* Buttons */
.btn {
    display: inline-block; font: inherit; font-size: 13px; line-height: 1.2; padding: 8px 14px; border-radius: 6px;
    border: 1px solid var(--line); background: var(--card); color: var(--fg); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { border-color: var(--danger); }
.btn-small { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px 10px; font-size: 16px; line-height: 1; color: var(--muted); }

/* Tables */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 14px; border-bottom: 1px solid #eef0f2; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table .actions { text-align: right; white-space: nowrap; }
.overdue { color: var(--danger); font-weight: 600; }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; margin-right: 4px; }
.badge-paid { background: var(--ok-soft); color: var(--ok); }
.badge-unpaid { background: var(--warn-soft); color: var(--warn); }
.badge-sent { background: var(--accent-soft); color: var(--accent); }

/* Line items */
.item-row { display: grid; grid-template-columns: 1fr 90px 120px 120px 40px; gap: 8px; align-items: start; margin-bottom: 6px; }
.item-head { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.item-row .amount { padding-top: 8px; }
.items-foot { display: grid; grid-template-columns: 1fr 320px; gap: 20px; margin-top: 12px; }
.totals dl { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 6px 0 0; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; }
.totals .grand { font-weight: 700; font-size: 16px; color: var(--fg); border-top: 1px solid var(--line); padding-top: 6px; }
@media (max-width: 800px) {
    .item-row { grid-template-columns: 1fr 70px 90px 36px; }
    .item-row .amount, .item-head span:nth-child(4) { display: none; }
    .items-foot { grid-template-columns: 1fr; }
}

/* Invoice preview */
.doc-view { max-width: 820px; margin: 0 auto; }
.paper { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 44px 48px; box-shadow: 0 1px 3px rgba(0, 0, 0, .05); }
@media (max-width: 700px) { .paper { padding: 20px; overflow-x: auto; } }

/* Pagination (simple-default) */
.pagination { display: flex; gap: 8px; list-style: none; padding: 0; }
.pagination li > * { display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); text-decoration: none; }
.pagination .disabled { opacity: .5; }

/* Business switcher in the top bar */
.switcher { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.switcher label { color: #c8d0d8; font-size: 12px; }
.switcher select {
    width: auto; max-width: 240px; color: #fff; background-color: #2a3440; border-color: #3a4652; padding: 6px 32px 6px 10px;
    /* Light chevron so it shows on the dark top bar. */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%23c8d0d8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");
    background-position: right 10px center;
}
.switcher select:hover { border-color: #56636f; }
.switcher select:focus { background-color: #2a3440; outline-color: rgba(255, 255, 255, .2); border-color: #7cc0d9; }
.switcher select option { color: var(--fg); background: #fff; }
.for-business { color: var(--muted); font-weight: 400; }

/* The hidden attribute must win over display rules like .check { display: flex }. */
[hidden] { display: none !important; }
.pre-line { white-space: pre-line; }

/* Designation + name: a narrow select next to a wide input. */
.row.row-salutation { grid-template-columns: 150px 1fr; }

/* Line item service search */
.combo { position: relative; }
.combo-list {
    position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0;
    max-height: 260px; overflow-y: auto; background: var(--card);
    border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(28, 37, 48, .12); padding: 4px;
}
.combo-option { display: flex; justify-content: space-between; gap: 12px; padding: 7px 10px; border-radius: 4px; cursor: pointer; }
.combo-option:hover, .combo-option.active { background: var(--accent-soft); }
.combo-option[data-add-new] { color: var(--accent); font-weight: 600; border-top: 1px solid var(--line); margin-top: 2px; }
.combo-option:first-child[data-add-new] { border-top: 0; margin-top: 0; }
.combo-rate { color: var(--muted); font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.badge-new { background: var(--ok-soft); color: var(--ok); margin-top: 4px; }
@media (max-width: 800px) {
    .row.row-salutation { grid-template-columns: 110px 1fr; }
}

/* Business logo */
.logo-field { display: grid; grid-template-columns: 140px 1fr; gap: 14px; align-items: start; margin-bottom: 6px; }
.logo-preview {
    height: 84px; display: flex; align-items: center; justify-content: center; padding: 8px;
    border: 1px dashed var(--line); border-radius: 6px; background: var(--field);
}
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
input[type="file"] { padding: 5px; background-color: var(--card); cursor: pointer; }
.biz-logo { height: 22px; max-width: 70px; object-fit: contain; vertical-align: middle; margin-right: 8px; }
input[type="file"]::file-selector-button {
    font: inherit; font-size: 13px; margin-right: 10px; padding: 6px 12px; cursor: pointer;
    border: 1px solid var(--line); border-radius: 6px; background: var(--field); color: var(--fg);
}
input[type="file"]::file-selector-button:hover { border-color: var(--muted); }

/* Sign-in and account */
.topbar-right { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.topbar-right .switcher { margin-left: 0; }
.user-link { color: #c8d0d8; text-decoration: none; font-size: 13px; }
.user-link:hover, .user-link.active { color: #fff; }
.link-button { font: inherit; font-size: 13px; color: #c8d0d8; background: none; border: 0; padding: 0; cursor: pointer; }
.link-button:hover { color: #fff; text-decoration: underline; }
.auth-wrap { display: flex; justify-content: center; padding-top: 48px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { margin-bottom: 4px; }
.auth-card .muted { margin-bottom: 16px; }
.btn-block { width: 100%; padding: 10px; }
.section-gap { margin-top: 18px; }

/* Drafts and invoice numbering */
.badge-draft { background: #eceff2; color: var(--muted); }
.readonly-value { margin: 0; padding: 8px 0; min-height: 36px; }
.prefix-field input { text-transform: uppercase; font-family: var(--mono); letter-spacing: .04em; }
input[readonly] { background-color: #eceff2; color: var(--muted); cursor: not-allowed; }

/* Copy / move to another business */
.transfer-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 16px; }
.transfer-bar select { width: auto; max-width: 260px; }
.transfer-error { flex-basis: 100%; margin: 0; }
.check-col { width: 36px; }
.check-col input { width: auto; cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
