* { box-sizing: border-box; }
body {
    font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    margin: 0;
    background: #f4f5f7;
    color: #1f2933;
}
.topnav {
    background: #1f2933;
    padding: 0 1.5rem;
    display: flex;
    gap: 0.25rem;
    align-items: stretch;
    flex-wrap: wrap;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.topnav .nav-link,
.topnav .nav-toggle {
    color: #e4e7eb;
    text-decoration: none;
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 500;
    padding: 0.85rem 0.9rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin: 0;
    width: auto;
}
.topnav .nav-link:hover,
.topnav .nav-toggle:hover,
.topnav .nav-group:focus-within .nav-toggle,
.topnav .nav-group.open .nav-toggle {
    background: #323f4b;
    color: #fff;
}
.topnav .is-active > .nav-toggle,
.topnav .nav-link.is-active {
    border-bottom-color: #4dabf7;
    color: #fff;
}
.topnav .caret { font-size: 0.65rem; opacity: 0.7; }
.topnav .nav-group { position: relative; display: flex; }
.topnav .nav-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 230px;
    background: #fff;
    border: 1px solid #d9dde3;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
    padding: 0.35rem 0;
    z-index: 100;
}
.topnav .nav-group:hover .nav-menu,
.topnav .nav-group:focus-within .nav-menu,
.topnav .nav-group.open .nav-menu { display: block; }
.topnav .nav-menu a {
    display: block;
    padding: 0.5rem 1rem;
    color: #1f2933;
    text-decoration: none;
    font-size: 0.88rem;
}
.topnav .nav-menu a:hover { background: #eef2f7; }
.topnav .nav-menu a.current {
    background: #e7f1fb;
    font-weight: 600;
    border-left: 3px solid #4dabf7;
    padding-left: calc(1rem - 3px);
}
.topnav .nav-right { margin-left: auto; display: flex; }
/* ---------- Foundations (shared by every page) ---------- */
:root {
    --ink: #1f2933;
    --muted: #616e7c;
    --line: #d9dde3;
    --line-soft: #e4e7eb;
    --accent: #4dabf7;
    --link: #1b4f8a;
    --primary: #1c6ab1;
    --primary-hover: #155a99;
    --danger: #e03131;
    --danger-hover: #c92a2a;
    --ok: #2f9e44;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}
body { line-height: 1.45; -webkit-font-smoothing: antialiased; }
.container { max-width: 1200px; margin: 0 auto; padding: 1.75rem 1.5rem 3rem; }

h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; font-weight: 700; margin: 2rem 0 0.75rem; padding-bottom: 0.4rem; border-bottom: 2px solid var(--line-soft); }
.card h2, details h2 { border-bottom: none; padding-bottom: 0; }
.card > h2:first-child { margin-top: 0; }
p { margin: 0 0 0.75rem; }
.container p > em:only-child { font-style: normal; color: var(--muted); font-size: 0.88rem; }

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
a.btn:hover, .kpi:hover, .topnav a:hover { text-decoration: none; }

table { width: 100%; border-collapse: collapse; background: #fff; margin-bottom: 1.5rem; border: 1px solid var(--line); }
th, td { border: 1px solid var(--line-soft); padding: 0.55rem 0.75rem; text-align: left; font-size: 0.9rem; }
th { background: #eef1f5; color: #3e4c59; font-weight: 700; font-size: 0.82rem; }
tr:hover > td { background: #f8fafc; }
tr.overdue { background: #fdeaea; }
tr.red-flag { background: #fbdada; }
tr.due-soon { background: #fff6da; }

.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.4rem; margin-bottom: 1.5rem; box-shadow: var(--shadow); }
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
form.inline { display: inline; }

label { display: block; font-size: 0.82rem; margin: 0.9rem 0 0.25rem; font-weight: 600; color: #3e4c59; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=url], select, textarea {
    display: block;
    width: 100%;
    max-width: 420px;
    padding: 0.5rem 0.65rem;
    border: 1px solid #c3c9d1;
    border-radius: 6px;
    font: inherit;
    font-size: 0.92rem;
    background: #fff;
    color: var(--ink);
}
textarea { max-width: 600px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(77, 171, 247, 0.25); }
form.inline input, form.inline select { display: inline-block; width: auto; }
.checkbox-list label { font-weight: normal; display: flex; align-items: center; gap: 0.4rem; color: var(--ink); }
.checkbox-list input { width: auto; display: inline-block; }

button, input[type=submit], a.btn {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.25;
    text-decoration: none;
    transition: background 0.12s;
}
button:hover, input[type=submit]:hover, a.btn:hover { background: var(--primary-hover); }
button.secondary, a.btn.secondary { background: #52606d; }
button.secondary:hover, a.btn.secondary:hover { background: #3e4c59; }
button.danger, a.btn.danger { background: var(--danger); }
button.danger:hover, a.btn.danger:hover { background: var(--danger-hover); }
button:focus-visible, a.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
form:not(.inline) button, form:not(.inline) input[type=submit] { margin-top: 1rem; margin-right: 0.4rem; }
td form button, td form input[type=submit] { margin-top: 0; }
a.btn { margin: 0 0.4rem 0.5rem 0; }

.flash { padding: 0.8rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem; border: 1px solid transparent; border-left-width: 4px; }
.flash-success { background: #e6f4ea; color: #1e6b34; border-color: #b7dfc1; border-left-color: var(--ok); }
.flash-error { background: #fff5f5; color: #a61e1e; border-color: #f3c2c2; border-left-color: var(--danger); }

.badge { display: inline-block; padding: 0.12rem 0.6rem; border-radius: 999px; font-size: 0.76rem; font-weight: 600; background: #eceff3; color: #52606d; }
.badge.draft { background: #fff3bf; color: #8a5a00; }
.badge.active { background: #e6f4ea; color: #2b7a3d; }
.badge.voided { background: #ffe3e3; color: #c92a2a; }

.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); align-items: center; justify-content: center; z-index: 200; }
.modal-box { background: #fff; border-radius: 10px; padding: 1.5rem; width: 100%; max-width: 420px; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25); max-height: 90vh; overflow-y: auto; }
.modal-close { float: right; cursor: pointer; background: none; color: #6b7280; padding: 0; margin: 0; }
.modal-close:hover { background: none; color: var(--ink); }

/* Client detail page: label on the left, value on the right, wrapped lines line up under the value */
.card.details { padding-top: 0.6rem; padding-bottom: 0.6rem; }
.card.details p { margin: 0; padding: 0.55rem 0 0.55rem 230px; text-indent: -230px; border-bottom: 1px solid var(--line-soft); }
.card.details p:last-child { border-bottom: none; }
.card.details p > strong:first-child { display: inline-block; width: 230px; text-indent: 0; padding-right: 12px; color: var(--muted); font-weight: 600; font-size: 0.85rem; vertical-align: top; }

/* Search/filter forms: fields in one row instead of a tall stack */
.filter-bar { display: grid; grid-template-rows: auto auto; grid-auto-flow: column; grid-auto-columns: minmax(150px, 260px); column-gap: 1rem; justify-content: start; align-items: end; }
.filter-bar label { margin-top: 0; }
.filter-bar input, .filter-bar select { max-width: none; }
.filter-bar button { grid-row: 2; justify-self: start; margin: 0; }

/* Sign-in page: centred card under the product name */
.guest .container { max-width: 440px; padding-top: 9vh; }
.guest h1 { text-align: center; font-size: 1.35rem; margin-bottom: 1rem; }
.guest-brand { text-align: center; font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-bottom: 0.35rem; }
.guest .card { max-width: none; padding: 1.5rem; box-shadow: 0 6px 20px rgba(16, 24, 40, 0.1); }
.guest input { max-width: none; }
.guest form button { display: block; width: 100%; padding: 0.65rem 1rem; margin-right: 0; }

@media (max-width: 700px) {
    .card.details p { padding-left: 0; text-indent: 0; }
    .card.details p > strong:first-child { display: block; width: auto; }
    .filter-bar { display: block; }
    .filter-bar label { margin-top: 0.9rem; }
    .filter-bar button { margin-top: 1rem; }
    .container { padding: 1.25rem 1rem 2.5rem; }
}

/* ---------- Dashboard ---------- */
.today { color: #616e7c; font-size: .9rem; margin: -.6rem 0 1rem; }
.dash-actions { margin: 0 0 .5rem; }
.section-label { font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: #616e7c; font-weight: 700; margin: 1.5rem 0 .5rem; }

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .9rem; }
.kpi { display: block; background: #fff; border: 1px solid #d9dde3; border-left: 6px solid #9aa5b1; border-radius: 8px; padding: .9rem 1rem; text-decoration: none; color: inherit; cursor: pointer; transition: box-shadow .15s, transform .15s; }
.kpi:hover { box-shadow: 0 4px 12px rgba(0, 0, 0, .12); transform: translateY(-1px); }
.kpi-num { display: block; font-size: 2.1rem; font-weight: 700; line-height: 1.1; }
.kpi-label { display: block; font-size: .9rem; font-weight: 600; margin-top: .15rem; }
.kpi-sub { display: block; font-size: .78rem; color: #616e7c; margin-top: .15rem; }
.kpi-danger { border-left-color: #e03131; background: #fff5f5; } .kpi-danger .kpi-num { color: #c92a2a; }
.kpi-warn   { border-left-color: #f59f00; background: #fff9e6; } .kpi-warn .kpi-num { color: #b76e00; }
.kpi-ok     { border-left-color: #2f9e44; }                      .kpi-ok .kpi-num { color: #2f9e44; }
.kpi-info   { border-left-color: #4dabf7; }
.kpi-small { padding: .65rem .9rem; }
.kpi-small .kpi-num { font-size: 1.6rem; }

.tabs { display: flex; gap: .25rem; border-bottom: 2px solid #d9dde3; margin-top: 2rem; }
.tab { margin-top: 0; background: none; color: #616e7c; border: none; border-bottom: 3px solid transparent; border-radius: 0; margin-bottom: -2px; padding: .7rem 1.1rem; font-size: .95rem; font-weight: 600; cursor: pointer; width: auto; }
.tab:hover { color: #1f2933; background: #eef2f7; }
.tab.active { color: #1f2933; border-bottom-color: #4dabf7; }
.tab .count { display: inline-block; min-width: 1.4rem; text-align: center; background: #e03131; color: #fff; border-radius: 999px; font-size: .72rem; padding: .05rem .4rem; margin-left: .35rem; }
.tab .count.amber { background: #f59f00; }
.panel { display: none; padding-top: 1rem; }
.panel.active { display: block; }

/* The outer Moorgreen / Evans Accounting dashboard tabs — same look as .tabs/.tab,
   but a separate class so dashboard.js's topic-tab switching (Accounts/CS/Reminders)
   never toggles these by accident. */
.bl-tabs { display: flex; gap: .25rem; border-bottom: 2px solid #d9dde3; margin-top: 2rem; }
.bl-tab { margin-top: 0; background: none; color: #616e7c; border: none; border-bottom: 3px solid transparent; border-radius: 0; margin-bottom: -2px; padding: .7rem 1.1rem; font-size: .95rem; font-weight: 600; cursor: pointer; width: auto; }
.bl-tab:hover { color: #1f2933; background: #eef2f7; }
.bl-tab.active { color: #1f2933; border-bottom-color: #4dabf7; }
.bl-panel { display: none; }
.bl-panel.active { display: block; }

.pills { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .8rem; }
.pill { margin-top: 0; background: #fff; color: #1f2933; border: 1px solid #c3c9d1; border-radius: 999px; padding: .3rem .8rem; font-size: .82rem; cursor: pointer; width: auto; }
.pill:hover { background: #eef2f7; }
.pill.active { background: #1f2933; color: #fff; border-color: #1f2933; }

.badge.b-late, .badge.b-soon, .badge.b-ok, .badge.b-info, .badge.b-grey { padding: .12rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; }
.b-late { background: #ffe3e3; color: #c92a2a; }
.b-soon { background: #fff3bf; color: #8a5a00; }
.b-ok   { background: #e6f4ea; color: #2b7a3d; }
.b-info { background: #e7f1fb; color: #1c6ab1; }
.b-grey { background: #eceff3; color: #52606d; }
tr.row-late td:first-child  { border-left: 4px solid #e03131; }
tr.row-soon td:first-child  { border-left: 4px solid #f59f00; }
tr.row-ready td:first-child { border-left: 4px solid #2f9e44; }
.allclear { background: #e6f4ea; border: 1px solid #b7dfc1; border-radius: 8px; padding: 1rem 1.2rem; color: #2b7a3d; font-weight: 600; margin: 1rem 0; }
.hint { color: #616e7c; font-size: .85rem; margin: .2rem 0 .9rem; }
.show-all-btn { margin: -.8rem 0 1.5rem; background: none; color: #1c6ab1; border: none; padding: .3rem 0; font-size: .85rem; width: auto; cursor: pointer; text-decoration: underline; }
.show-all-btn:hover { background: none; color: #114a80; }
details.review-card { background: #fff; border: 1px solid #d9dde3; border-left: 6px solid #f59f00; border-radius: 8px; margin-bottom: .7rem; max-width: 760px; }
details.review-card > summary { padding: .75rem 1rem; cursor: pointer; font-size: .92rem; }
details.review-card[open] > summary { border-bottom: 1px solid #e4e7eb; }
details.review-card form { padding: 0 1rem 1rem; }
.kpi-row.kpi-row-tight { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }
/* A client's name, wherever it appears as a link (dashboard, lists, reports, client pages) */
a.client-link { color: var(--link); font-weight: 600; text-decoration: none; }
a.client-link:hover { text-decoration: underline; }
.panel table button { margin-top: 0; padding: .3rem .65rem; font-size: .8rem; white-space: nowrap; }
.table-scroll { overflow-x: auto; }

/* Fields inside table cells (bulk edit grid etc.) size to their content instead of being squeezed */
td input[type=text], td input[type=date], td input[type=number], td input[type=url], td select { width: auto; min-width: 135px; max-width: 200px; }
td input.grid-field[data-field=notes] { min-width: 180px; max-width: 260px; }

input[type=file] { display: block; font: inherit; font-size: 0.9rem; margin: 0.25rem 0; }
input[type=radio], input[type=checkbox] { accent-color: var(--primary); }

/* Small screens: wide tables scroll within themselves instead of stretching the whole page */
.card.details p { overflow-wrap: anywhere; }
pre { overflow-x: auto; max-width: 100%; }
@media (max-width: 700px) {
    table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* Anything marked hidden must stay hidden, whatever display style its element type has */
[hidden] { display: none !important; }

/* Sortable tables: click a heading to sort; the column in use shows an arrow */
table.sortable-table th[data-sort] { cursor: pointer; user-select: none; }
table.sortable-table th[data-sort]:hover { background: #e3e8ef; }
table.sortable-table th[data-sort]::after { content: "\21C5"; margin-left: 0.4em; font-size: 0.8em; opacity: 0.35; }
table.sortable-table th.sort-asc::after { content: "\25B2"; opacity: 0.85; }
table.sortable-table th.sort-desc::after { content: "\25BC"; opacity: 0.85; }
table.sortable-table th[data-sort]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Bulk Edit Grid: text wraps inside cells and the edit boxes shrink to their column, so the table keeps the normal page width */
#bulk-grid th, #bulk-grid td { padding-left: .5rem; padding-right: .5rem; }
#bulk-grid td input, #bulk-grid td select { width: 100%; min-width: 0; max-width: none; box-sizing: border-box; padding-left: .35rem; padding-right: .3rem; font-size: .85rem; }
#bulk-grid { table-layout: fixed; }
#bulk-grid th:nth-child(1) { width: 10%; }
#bulk-grid th:nth-child(2) { width: 14%; }
#bulk-grid th:nth-child(3) { width: 8%; }
#bulk-grid th:nth-child(4), #bulk-grid th:nth-child(5) { width: 9%; }
#bulk-grid th:nth-child(6), #bulk-grid th:nth-child(8) { width: 13%; }
#bulk-grid th:nth-child(9) { width: 10%; }
#bulk-grid th:nth-child(7) { width: 14%; }

/* Sign-in helpers: "Forgot your password?" link and the code box */
.guest-links { text-align: center; margin: 1rem 0 0; font-size: 0.9rem; }
.guest-links a { color: var(--primary); text-decoration: none; }
.guest-links a:hover { text-decoration: underline; }
.guest .note { color: var(--muted); font-size: 0.9rem; margin: 0 0 1rem; }
input.code-box { font-size: 1.5rem; letter-spacing: 0.35em; text-align: center; font-variant-numeric: tabular-nums; }

/* Create Invoice Now button row above a table */
form[action*="create_now.php"] { margin: 0 0 1rem; }
form[action*="create_now.php"] .hint { display: inline-block; margin: 0 0 0 .6rem; }

/* Client page: tabs (same look as the dashboard's), neutral count bubbles, and "+ Add ..." forms that fold away */
#client-tabs { margin-top: 1rem; flex-wrap: wrap; }
.tab .count.plain { background: #e3e8ef; color: #3e4c59; }
details.add-box { margin: .25rem 0 1.25rem; }
details.add-box > summary { display: inline-block; cursor: pointer; list-style: none; color: var(--primary); font-weight: 600; font-size: .92rem; padding: .35rem .8rem; border: 1px dashed #9db5d3; border-radius: 6px; background: #fff; }
details.add-box > summary::-webkit-details-marker { display: none; }
details.add-box > summary:hover { background: #eef4fb; }
details.add-box[open] > summary { margin-bottom: .6rem; border-style: solid; }
details.add-box .card { margin-top: 0; }
.panel[data-panel] h2:first-child { margin-top: 0; }

/* Tabs wrap onto a second line on narrow screens instead of running off the side */
.tabs { flex-wrap: wrap; }
