:root {
    --green: #356854;
    --blue: #0b3457;
    --blue-deep: #071a2c;
    --blue-panel: #0e2d49;
    --blue-soft: #d9eaf7;
    --silver: #a9c2d8;
    --ink: #1f2933;
    --muted: #607080;
    --line: #d0d7de;
    --bg: #071a2c;
    --panel: #ffffff;
    --pending: #fce8b2;
    --active: #d9eaf7;
    --completed: #e8ecef;
    --ok: #d8f3dc;
    --warn: #fff3cd;
    --bad: #f8d7da;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background:
        radial-gradient(circle at top left, rgba(75, 137, 183, .34), transparent 34rem),
        linear-gradient(145deg, var(--blue-deep), #0a2741 52%, #071320);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    min-height: 100vh;
}

a { color: #235f9b; text-decoration: none; }
a:hover { text-decoration: underline; }

.map-link {
    color: inherit;
}

.map-link:hover,
.map-link:focus-visible {
    color: #235f9b;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 70px;
    padding: 8px 22px;
    background: var(--blue-deep);
    border-bottom: 1px solid rgba(169, 194, 216, .28);
    box-shadow: 0 14px 30px rgba(0, 0, 0, .26);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(10px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    color: #fff;
    min-width: 300px;
}

.brand:hover {
    text-decoration: none;
}

.brand img {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 0 0 2px rgba(169, 194, 216, .54), 0 8px 22px rgba(0, 0, 0, .34);
}

.brand strong {
    display: block;
    font-size: 18px;
    letter-spacing: .2px;
}

.brand small {
    display: block;
    margin-top: 2px;
    color: var(--silver);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
}

.nav a {
    color: #fff;
    padding: 9px 11px;
    border-radius: 4px;
}

.nav a:hover,
.nav a.active {
    background: rgba(169, 194, 216, .18);
    text-decoration: none;
}

.nav a.nav-job-board,
.nav a[href="../index.php"],
.nav a[href="../../index.php"] {
    background: var(--blue-soft);
    color: var(--blue-deep);
    font-weight: 800;
}

.nav a.nav-job-board:hover,
.nav a.nav-job-board:focus-visible,
.nav a[href="../index.php"]:hover,
.nav a[href="../index.php"]:focus-visible,
.nav a[href="../../index.php"]:hover,
.nav a[href="../../index.php"]:focus-visible {
    background: var(--silver);
    color: var(--blue-deep);
    text-decoration: none;
}

.nav a.nav-design {
    background: #f2c94c;
    color: #fff;
    font-weight: 800;
}

.nav a.nav-design:hover,
.nav a.nav-design:focus-visible,
.nav a.nav-design.active {
    background: #d9aa22;
    color: #fff;
    text-decoration: none;
}

.nav a.nav-logout,
.nav a[href$="logout.php"],
.nav a[href*="logout"] {
    background: #b42318;
    color: #fff;
    font-weight: 800;
}

.nav a.nav-logout:hover,
.nav a.nav-logout:focus-visible,
.nav a[href$="logout.php"]:hover,
.nav a[href$="logout.php"]:focus-visible,
.nav a[href*="logout"]:hover,
.nav a[href*="logout"]:focus-visible {
    background: #8f1d16;
    color: #fff;
    text-decoration: none;
}

.page {
    width: min(1500px, calc(100vw - 28px));
    margin: 18px auto 34px;
}

.panel, .table-wrap {
    background: var(--panel);
    border: 1px solid rgba(169, 194, 216, .45);
    border-radius: 6px;
    padding: 14px;
    margin-bottom: 12px;
    box-shadow: 0 16px 34px rgba(0, 0, 0, .16);
}

.panel.narrow, .login-panel {
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
}

.customer-portal-entry {
    display: grid;
    gap: 10px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid rgba(169, 194, 216, .55);
}

.customer-portal-entry p {
    margin: 3px 0 0;
    color: var(--muted);
}

.customer-portal-entry .button {
    width: 100%;
}

h1, h2 {
    margin: 0;
    line-height: 1.2;
}

h1 { font-size: 22px; }
h2 { font-size: 15px; }

.panel-head, .board-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.actions, .board-actions {
    display: flex;
    gap: 8px;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
}

.form-actions .archive-action {
    margin-left: auto;
}

.button.danger {
    border-color: rgba(185, 62, 62, .35);
    background: #fff;
    color: #9a2626;
}

.button.danger:hover,
.button.danger:focus-visible {
    border-color: rgba(185, 62, 62, .65);
    background: #fff3f3;
}

.summary-strip {
    display: grid;
    grid-template-columns: repeat(6, minmax(110px, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.summary-strip div {
    background: rgba(255, 255, 255, .96);
    border: 1px solid rgba(169, 194, 216, .52);
    border-radius: 6px;
    padding: 10px 12px;
    box-shadow: 0 12px 24px rgba(0, 0, 0, .12);
}

.summary-strip span {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.summary-strip strong {
    display: block;
    font-size: 20px;
    margin-top: 2px;
}

.summary-strip small {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 11px;
}

.compact-summary {
    grid-template-columns: repeat(2, minmax(140px, 220px));
    margin-top: 12px;
}

.profitability-summary {
    grid-template-columns: repeat(6, minmax(130px, 1fr));
}

.board {
    display: grid;
    grid-template-columns: 1fr;
    gap: 22px;
    align-items: start;
}

.stage-column,
.stage-section {
    background: rgba(255, 255, 255, .98);
    border: 1px solid rgba(169, 194, 216, .58);
    border-radius: 8px;
    min-width: 0;
    overflow: hidden;
    box-shadow: 0 18px 36px rgba(0, 0, 0, .18);
}

.stage-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-height: 68px;
    padding: 14px 18px;
    border-bottom: 4px solid var(--green);
    color: #fff;
    background: var(--blue);
}

.stage-column.pending .stage-header,
.stage-section.pending .stage-header { background: linear-gradient(90deg, #0b3457, #104d73); border-bottom-color: #f2c94c; }
.stage-column.active .stage-header,
.stage-section.active .stage-header { background: linear-gradient(90deg, #0b3457, #17658d); border-bottom-color: #7bbce8; }
.stage-column.completed .stage-header,
.stage-section.completed .stage-header { background: linear-gradient(90deg, #0b3457, #31556f); border-bottom-color: #a9c2d8; }

.stage-kicker {
    display: block;
    color: #cfe0ee;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    margin-bottom: 3px;
}

.stage-header h2 {
    color: #fff;
    font-size: 20px;
    letter-spacing: .2px;
}

.stage-stats {
    min-width: 110px;
    padding-left: 12px;
    border-left: 1px solid rgba(255, 255, 255, .28);
    text-align: right;
}

.stage-stats strong {
    display: block;
    font-size: 22px;
    line-height: 1;
}

.stage-stats span {
    display: block;
    margin-top: 3px;
    color: #dbe8f2;
    font-size: 12px;
}

.job-card {
    padding: 11px 13px;
    border-bottom: 1px solid var(--line);
    background: #fff;
    transition: background .15s ease, box-shadow .15s ease;
}

.section-table {
    width: 100%;
    overflow-x: auto;
}

.section-row {
    display: grid;
    grid-template-columns: 58px 128px minmax(132px, .72fr) 176px minmax(176px, 1fr) 76px 86px 108px 100px 112px;
    gap: 8px;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
}

.section-row-head {
    background: #f3f6f8;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .7px;
}

.board-sort-button {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
}

.board-sort-button::after {
    content: "Sort";
    padding: 1px 4px;
    border: 1px solid rgba(11, 52, 87, .22);
    border-radius: 4px;
    color: var(--muted);
    font-size: 9px;
    letter-spacing: .4px;
}

.board-sort-button[data-sort-direction="asc"]::after {
    content: "A-Z";
}

.board-sort-button[data-sort-direction="desc"]::after {
    content: "Z-A";
}

.board-sort-button[data-sort-age][data-sort-direction="desc"]::after {
    content: "Old";
}

.board-sort-button[data-sort-age][data-sort-direction="asc"]::after {
    content: "New";
}

.board-sort-button:hover,
.board-sort-button:focus-visible {
    color: var(--blue);
    outline: none;
}

.job-row {
    background: #fff;
}

.job-row.has-job-notes {
    cursor: help;
}

.job-row:hover {
    background: #fbfdff;
    box-shadow: inset 4px 0 0 var(--green);
}

.job-notes-tooltip {
    position: fixed;
    z-index: 2000;
    display: none;
    max-width: min(520px, calc(100vw - 32px));
    padding: 10px 12px;
    background: #102c42;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 6px;
    box-shadow: 0 18px 38px rgba(0, 0, 0, .28);
    font-size: 12px;
    line-height: 1.45;
    white-space: pre-wrap;
    pointer-events: none;
}

.job-number {
    font-weight: 700;
    font-size: 12px;
    white-space: nowrap;
}

.job-customer {
    font-weight: 700;
}

.job-customer,
.job-address,
.job-type,
.job-next,
.truncate {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.age-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    min-width: 0;
}

[data-age-toggle] {
    min-height: 22px;
    padding: 2px 7px;
    border-color: rgba(11, 52, 87, .24);
    border-radius: 4px;
    background: #fff;
    color: var(--blue);
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    text-transform: uppercase;
}

[data-age-toggle]:hover,
[data-age-toggle]:focus-visible {
    background: var(--blue-soft);
}

.job-age {
    min-width: 0;
}

.age-days,
.age-dates {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 5px;
    row-gap: 1px;
    align-items: baseline;
    line-height: 1.1;
}

.age-dates {
    display: none;
}

html[data-age-mode="dates"] .age-days {
    display: none;
}

html[data-age-mode="dates"] .age-dates {
    display: grid;
}

.job-age strong {
    color: var(--ink);
    font-size: 12px;
    white-space: nowrap;
}

.job-age small {
    color: var(--muted);
    font-size: 10px;
    text-transform: uppercase;
    white-space: nowrap;
}

.job-card:hover {
    background: #fbfdff;
    box-shadow: inset 4px 0 0 var(--green);
}

.job-card:last-child { border-bottom: 0; }

.job-card-head, .job-meta, .card-actions {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
}

.job-title {
    font-weight: 700;
    margin-top: 7px;
    font-size: 15px;
}

.muted {
    color: var(--muted);
}

.job-meta {
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
}

.job-details {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 5px;
    color: #738190;
    font-size: 11px;
}

.next-step {
    margin: 8px 0 0;
    line-height: 1.35;
    padding: 8px 9px;
    background: #f6f8f9;
    border-left: 3px solid var(--blue-soft);
    border-radius: 4px;
}

.card-actions {
    margin-top: 10px;
}

.badge {
    display: inline-block;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 12px;
    white-space: nowrap;
    font-weight: 700;
}

.badge.ok { background: var(--ok); }
.badge.warn { background: var(--warn); }
.badge.bad { background: var(--bad); }
.badge.neutral { background: #eef1f3; }

.block {
    display: block;
    margin-top: 3px;
}

.button, button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    cursor: pointer;
}

.button:hover, button:hover {
    text-decoration: none;
    background: #eef1f3;
}

.button.primary, button.primary {
    background: linear-gradient(180deg, #3d7b63, var(--green));
    border-color: #407d65;
    color: #fff;
}

.button.board-primary {
    background: linear-gradient(180deg, #17658d, var(--blue));
    border-color: #0b3457;
    color: #fff;
    font-weight: 800;
}

.button.board-primary:hover,
.button.board-primary:focus-visible {
    background: var(--blue-deep);
    border-color: var(--blue-deep);
    color: #fff;
    text-decoration: none;
}

.button.compact,
button.compact {
    min-height: 28px;
    padding: 4px 9px;
    font-size: 12px;
}

.tiny {
    font-size: 12px;
}

.button.primary:hover, button.primary:hover {
    background: #2c5646;
}

input, select, textarea {
    width: 100%;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 7px 9px;
    background: #fff;
    color: var(--ink);
    font: inherit;
}

textarea {
    resize: vertical;
}

label {
    display: grid;
    gap: 5px;
    color: var(--muted);
    font-size: 12px;
}

label input, label select, label textarea {
    color: var(--ink);
    font-size: 14px;
}

.form-grid, .job-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 12px;
}

.form-grid {
    grid-template-columns: 1fr;
}

.job-form .wide {
    grid-column: span 3;
}

.section-kicker {
    display: block;
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .8px;
    text-transform: uppercase;
}

.cost-control {
    display: grid;
    gap: 12px;
    margin-top: 4px;
    padding: 14px;
    background: #f7f9fb;
    border: 1px solid var(--line);
    border-radius: 7px;
}

.billable-hours-panel {
    display: grid;
    gap: 6px;
    padding: 8px 10px;
    background: #fff;
    border: 1px solid rgba(169, 194, 216, .7);
    border-radius: 6px;
}

.billable-hours-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.billable-hours-head h2 {
    margin: 0;
    color: var(--text);
    font-size: 12px;
    line-height: 1.2;
}

.billable-hours-head span {
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

.billable-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(92px, 1fr));
    gap: 6px;
}

.billable-grid label {
    display: grid;
    grid-template-columns: auto minmax(64px, 1fr);
    align-items: center;
    gap: 5px;
    font-size: 11px;
}

.billable-grid label span {
    color: var(--muted);
    font-weight: 700;
    line-height: 1.1;
}

.billable-grid input {
    min-height: 30px;
    padding: 5px 7px;
}

.cost-control-head,
.table-headline {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.cost-control-head {
    margin-bottom: 0;
}

.cost-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    gap: 8px;
}

.cost-metrics div {
    min-width: 0;
    padding: 10px;
    background: #fff;
    border: 1px solid rgba(169, 194, 216, .58);
    border-radius: 6px;
}

.cost-metrics span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.cost-metrics strong {
    display: block;
    margin-top: 3px;
    color: var(--ink);
    font-size: 17px;
}

.cost-metrics small {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 11px;
}

.cost-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(170px, 1fr));
    gap: 12px;
}

.cost-grid .wide {
    grid-column: span 3;
}

.cost-breakdown-grid {
    grid-template-columns: repeat(4, minmax(140px, 1fr));
}

.cost-breakdown-grid .wide {
    grid-column: span 4;
}

.cost-formulas {
    display: grid;
    gap: 3px;
    padding: 10px 12px;
    background: #fff;
    border-left: 4px solid var(--green);
    border-radius: 5px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.cost-formulas strong {
    color: var(--ink);
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ink);
}

.checkbox input {
    width: auto;
    min-height: auto;
}

.filters, .user-create {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 170px 170px auto;
    gap: 8px;
    margin-top: 12px;
}

.profitability-filters {
    grid-template-columns: minmax(240px, 1fr) 150px 180px minmax(170px, auto) auto;
}

.labor-filters {
    grid-template-columns: minmax(240px, 1fr) 160px 150px minmax(170px, auto) auto;
}

.include-previous {
    align-self: center;
    min-height: 34px;
    padding: 7px 10px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 5px;
}

.user-create {
    grid-template-columns: 1fr 1fr 130px 1fr auto;
}

.user-list {
    display: grid;
    gap: 8px;
}

.user-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 140px 100px minmax(180px, 1fr) auto;
    gap: 10px;
    align-items: end;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px;
}

.user-row strong,
.user-row span {
    display: block;
}

.inline-stage {
    margin: 0;
}

.inline-stage select {
    min-height: 30px;
    padding: 4px 7px;
}

.labor-summary {
    grid-template-columns: repeat(5, minmax(120px, 1fr));
}

.labor-payment-form {
    display: grid;
    gap: 12px;
}

.labor-payment-bar {
    display: grid;
    grid-template-columns: minmax(180px, 1.2fr) repeat(3, minmax(110px, .7fr)) auto;
    gap: 10px;
    align-items: end;
}

.labor-payment-bar div {
    min-height: 42px;
    padding: 8px 10px;
    background: #fff;
    border: 1px solid rgba(169, 194, 216, .58);
    border-radius: 6px;
}

.labor-payment-bar span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.labor-payment-bar strong {
    display: block;
    margin-top: 2px;
    font-size: 18px;
}

.labor-ledger-table th,
.labor-ledger-table td {
    white-space: nowrap;
}

.labor-ledger-table .compact-input {
    width: 92px;
    min-height: 32px;
    padding: 5px 7px;
}

.block {
    display: block;
}

.permit-forms-shell .panel-head {
    align-items: flex-start;
}

.permit-forms-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.permit-forms-grid .wide,
.permit-field-grid .wide {
    grid-column: 1 / -1;
}

.permit-card,
.permit-rule-card {
    border: 1px solid rgba(169, 194, 216, .58);
    border-radius: 6px;
    background: #fff;
    padding: 12px;
}

.permit-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(169, 194, 216, .45);
}

.permit-card-head h2,
.permit-rule-card strong {
    margin: 0;
    color: var(--blue);
    font-size: 15px;
}

.permit-card-head span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.permit-field-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.permit-field-grid.one {
    grid-template-columns: 1fr;
}

.permit-generate-row {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) auto;
    gap: 10px;
    align-items: end;
}

.permit-rule-card {
    margin-bottom: 12px;
    background: #f8fbfd;
}

.permit-rule-card p {
    margin: 6px 0 10px;
}

.permit-rule-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.permit-rule-links a {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 6px 9px;
    border: 1px solid rgba(169, 194, 216, .75);
    border-radius: 4px;
    background: #fff;
    font-weight: 700;
}

.permit-lookup-helper {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) auto;
    gap: 12px;
    align-items: start;
    margin-top: 12px;
    padding: 10px 12px;
    border: 1px solid #d7e0e8;
    border-radius: 8px;
    background: #f8fbfd;
}

.permit-lookup-main {
    min-width: 0;
}

.permit-lookup-helper strong,
.permit-lookup-helper span {
    display: block;
}

.permit-lookup-helper span {
    margin-top: 2px;
    color: #5b6f82;
    font-size: 12px;
}

.permit-lookup-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.permit-lookup-secondary {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
    margin-top: -4px;
}

.permit-lookup-chip {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 8px;
    border: 1px solid #cdd9e4;
    border-radius: 999px;
    background: #fff;
    color: #0f385d;
    font-size: 12px;
    font-weight: 800;
    text-decoration: none;
}

.permit-lookup-chip.as-button {
    margin: 0;
    appearance: none;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.2;
}

.permit-lookup-chip:hover {
    border-color: #7da4c4;
    color: #0a2a45;
}

.permit-lookup-parser {
    grid-column: 1 / -1;
    padding-top: 8px;
    border-top: 1px solid #d7e0e8;
}

.permit-lookup-parser summary {
    cursor: pointer;
    color: #0f385d;
    font-weight: 800;
}

.permit-lookup-parser textarea {
    margin-top: 8px;
    min-height: 92px;
}

.permit-parser-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
}

.permit-parser-status {
    margin-top: 8px;
    color: #5b6f82;
    font-size: 12px;
    font-weight: 700;
}

.permit-template-table {
    min-width: 980px;
}

.button.small {
    min-height: 30px;
    padding: 6px 9px;
    font-size: 12px;
}

.inline-form {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.table-wrap.flat {
    box-shadow: none;
    padding: 0;
    margin: 0;
    overflow-x: auto;
}

.permit-view-toolbar {
    margin-bottom: 10px;
}

.permit-output-panel {
    background: #fff;
}

.permit-output {
    max-width: 8.5in;
    margin: 0 auto;
    color: #000;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
}

.permit-output-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #111;
    text-transform: uppercase;
}

.permit-output-header strong,
.permit-output-header span {
    display: block;
}

.permit-output-header strong {
    font-size: 14px;
    letter-spacing: .3px;
}

.permit-output-header span {
    margin-top: 3px;
    font-size: 12px;
}

.permit-generated-section {
    margin-bottom: 14px;
    break-inside: avoid;
}

.permit-generated-section h2 {
    margin: 0;
    padding: 6px 8px;
    border: 1px solid #111;
    border-bottom: 0;
    background: #f1f1f1;
    color: #000;
    font-size: 14px;
    text-align: center;
    text-transform: uppercase;
}

.permit-generated-section h3 {
    margin: 10px 0 4px;
    color: #000;
    font-size: 12px;
    text-transform: uppercase;
}

.permit-source-line {
    margin: 0;
    padding: 5px 7px;
    border: 1px solid #111;
    border-bottom: 0;
    color: #222;
    font-size: 10px;
}

.permit-output-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #111;
}

.permit-output-table.compact th,
.permit-output-table.compact td {
    width: auto;
}

.permit-output-table th,
.permit-output-table td {
    border: 1px solid #111;
    padding: 6px 7px;
    color: #000;
    vertical-align: top;
}

.permit-output-table th {
    width: 30%;
    background: #f7f7f7;
    color: #000;
    font-weight: 800;
    text-transform: uppercase;
}

.permit-output-table thead th {
    text-align: center;
}

.permit-blank {
    display: inline-block;
    min-width: 220px;
    color: #444;
}

.permit-warning-text {
    margin: 8px 0 0;
    padding: 8px;
    border: 1px solid #111;
    font-weight: 700;
    line-height: 1.35;
}

.permit-draft-warning {
    border: 2px solid #a65f00;
    padding: 8px;
}

.permit-draft-warning h2 {
    border: 0;
    padding: 0 0 4px;
    color: #7a4300;
    background: transparent;
    text-align: left;
}

.permit-draft-warning ul,
.permit-output-list {
    margin: 6px 0 0;
    padding-left: 20px;
}

.permit-signature-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 16px;
}

.permit-signature-grid div {
    min-height: 50px;
}

.permit-signature-grid strong {
    display: block;
    margin-bottom: 24px;
    font-size: 10px;
    text-transform: uppercase;
}

.permit-signature-grid span {
    display: block;
    border-bottom: 1px solid #111;
}

.permit-official-shell {
    display: grid;
    gap: 12px;
}

.permit-official-status {
    padding: 10px 12px;
    border: 1px solid #bcd0e3;
    border-radius: 8px;
    background: #f3f8fc;
    color: #17324a;
    font-weight: 700;
}

.permit-official-status.warn {
    border-color: #f0b4b4;
    background: #fff1f1;
    color: #8a1616;
}

.permit-official-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.permit-official-field-check {
    max-height: 260px;
    overflow: auto;
    border: 1px solid #d7e0e8;
    border-radius: 8px;
}

.permit-official-field-check table {
    margin: 0;
}

.permit-official-preview-wrap {
    min-height: 72vh;
    border: 1px solid #d7e0e8;
    border-radius: 8px;
    overflow: hidden;
    background: #eef3f7;
}

.permit-official-preview-wrap iframe {
    display: block;
    width: 100%;
    min-height: 72vh;
    border: 0;
    background: #fff;
}

.permit-admin-list {
    display: grid;
    gap: 10px;
}

.permit-admin-row {
    display: grid;
    grid-template-columns: minmax(220px, 1.2fr) minmax(150px, .7fr) minmax(140px, .6fr) auto;
    gap: 10px;
    align-items: end;
    padding: 12px;
    border: 1px solid rgba(169, 194, 216, .58);
    border-radius: 6px;
    background: #fff;
}

.permit-admin-row > div span {
    display: block;
    color: var(--muted);
    margin-top: 3px;
}

.permit-admin-row .wide {
    grid-column: 1 / -1;
}

table {
    width: 100%;
    border-collapse: collapse;
}

.jobs-table {
    min-width: 1180px;
    table-layout: fixed;
}

.jobs-table th:nth-child(1) { width: 56px; }
.jobs-table th:nth-child(2) { width: 128px; }
.jobs-table th:nth-child(3) { width: 140px; }
.jobs-table th:nth-child(4) { width: 180px; }
.jobs-table th:nth-child(5) { width: 180px; }
.jobs-table th:nth-child(6) { width: 230px; }
.jobs-table th:nth-child(7) { width: 72px; }
.jobs-table th:nth-child(8) { width: 88px; }
.jobs-table th:nth-child(9) { width: 112px; }
.jobs-table th:nth-child(10) { width: 110px; }

.profit-table {
    min-width: 1120px;
}

th, td {
    border-bottom: 1px solid var(--line);
    padding: 8px 9px;
    text-align: left;
    vertical-align: top;
}

th {
    background: var(--blue);
    color: #fff;
    font-weight: 700;
    white-space: nowrap;
}

th .age-head {
    color: #fff;
}

tr:last-child td {
    border-bottom: 0;
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 24px;
}

.empty-stage {
    padding: 22px 12px;
    color: var(--muted);
    text-align: center;
}

.notice, .flash {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: #fff;
}

.notice.warn, .flash.error {
    background: var(--bad);
}

.flash.success {
    background: var(--ok);
}

.flash.info {
    background: var(--active);
}

code {
    background: #eef1f3;
    border-radius: 4px;
    padding: 1px 4px;
}

@media (max-width: 1000px) {
    .summary-strip {
        grid-template-columns: repeat(2, 1fr);
    }

    .profitability-summary,
    .labor-summary,
    .cost-metrics,
    .cost-grid,
    .billable-grid,
    .labor-payment-bar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .section-table {
        overflow-x: auto;
    }

    .section-row {
        min-width: 1240px;
    }

    .filters, .profitability-filters, .labor-filters, .user-create, .user-row, .job-form, .permit-forms-grid, .permit-field-grid, .permit-generate-row, .permit-admin-row {
        grid-template-columns: 1fr;
    }

    .job-form .wide,
    .cost-grid .wide,
    .permit-forms-grid .wide,
    .permit-field-grid .wide,
    .permit-admin-row .wide {
        grid-column: auto;
    }

    .table-wrap {
        overflow-x: auto;
    }
}

@media (max-width: 720px) {
    body {
        font-size: 13px;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
        padding: 10px 14px;
        position: static;
    }

    .brand {
        min-width: 0;
    }

    .brand img {
        width: 48px;
        height: 48px;
    }

    .nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
        width: 100%;
    }

    .nav a {
        padding: 10px 8px;
        background: rgba(169, 194, 216, .12);
        text-align: center;
    }

    .page {
        width: calc(100vw - 14px);
        margin: 10px auto 24px;
    }

    .panel {
        padding: 10px;
    }

    .panel-head {
        align-items: flex-start;
    }

    .actions,
    .board-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
        width: 100%;
    }

    .actions .button,
    .board-actions .button {
        width: 100%;
    }

    .permit-lookup-helper {
        align-items: stretch;
        grid-template-columns: 1fr;
    }

    .permit-lookup-actions {
        justify-content: stretch;
    }

    .permit-lookup-actions .button {
        flex: 1 1 150px;
    }

    .permit-lookup-secondary {
        justify-content: stretch;
    }

    .permit-lookup-chip {
        flex: 1 1 130px;
        justify-content: center;
    }

    .summary-strip,
    .compact-summary,
    .profitability-summary,
    .labor-summary,
    .cost-metrics,
    .cost-grid,
    .billable-grid,
    .labor-payment-bar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
    }

    .summary-strip div {
        padding: 8px 9px;
    }

    .summary-strip strong {
        font-size: 18px;
    }

    .board {
        gap: 14px;
    }

    .stage-header {
        align-items: flex-start;
        min-height: 0;
        padding: 12px;
    }

    .stage-header h2 {
        font-size: 17px;
    }

    .stage-stats {
        min-width: 74px;
        padding-left: 9px;
    }

    .section-table {
        overflow-x: auto;
    }

    .section-row-head {
        display: grid;
    }

    .section-row,
    .section-row.job-row {
        grid-template-columns: 58px 128px minmax(132px, .72fr) 176px minmax(176px, 1fr) 76px 86px 108px 100px 112px;
        gap: 8px;
        min-width: 1240px;
        padding: 8px 10px;
    }

    .job-row > span {
        min-width: 0;
    }

    .job-row .job-number {
        font-size: 12px;
    }

    .job-next {
        line-height: 1.25;
    }

    .job-age .age-days,
    .job-age .age-dates {
        grid-template-columns: auto 1fr auto 1fr;
    }

    input,
    select,
    textarea {
        min-height: 38px;
    }

    .inline-stage select {
        min-height: 34px;
    }

    .table-wrap {
        overflow-x: auto;
        padding: 10px;
        background: var(--panel);
        border: 1px solid rgba(169, 194, 216, .45);
        box-shadow: 0 16px 34px rgba(0, 0, 0, .16);
    }

    .table-wrap table,
    .jobs-table {
        display: table;
        width: 100%;
        min-width: 1180px;
    }

    .table-wrap thead {
        display: table-header-group;
    }

    .table-wrap tbody {
        display: table-row-group;
    }

    .table-wrap tr {
        display: table-row;
        background: transparent;
        border: 0;
        box-shadow: none;
    }

    .table-wrap td {
        display: table-cell;
        padding: 8px 10px;
        border-bottom: 1px solid var(--line);
    }

    .table-wrap td.empty {
        display: table-cell;
        padding: 24px;
        text-align: center;
    }
}

@media print {
    body {
        background: #fff !important;
        color: #000;
        font-size: 12px;
    }

    .topbar,
    .flash,
    .permit-view-toolbar,
    .nav {
        display: none !important;
    }

    .page {
        width: auto;
        margin: 0;
    }

    .panel,
    .permit-output-panel {
        border: 0;
        box-shadow: none;
        padding: 0;
        margin: 0;
    }

    .permit-output {
        max-width: none;
        margin: 0;
    }

    .permit-output-table th,
    .permit-output-table td,
    .permit-generated-section h2,
    .permit-source-line,
    .permit-warning-text {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
