:root {
    --bg: #f8fafc;
    --panel: #ffffff;
    --panel-soft: #f1f5f9;
    --text: #0f172a;
    --muted: #64748b;
    --line: #dbe4ef;
    --brand: #0f766e;
    --brand-dark: #115e59;
    --warn-bg: #fff7ed;
    --warn-line: #fed7aa;
    --warn-text: #9a3412;
    --radius: 18px;
    --shadow: 0 12px 32px rgba(15, 23, 42, .08);
}

* {
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.45;
}

a {
    color: var(--brand);
    font-weight: 650;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
.button,
a[href$="/new"],
a[href*="/import"],
a[href*="/quotes/new"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    min-height: 40px;
    padding: .65rem .95rem;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--brand);
    color: #fff;
    cursor: pointer;
    font-weight: 750;
    text-decoration: none;
}

button:hover,
.button:hover,
a[href$="/new"]:hover,
a[href*="/import"]:hover,
a[href*="/quotes/new"]:hover {
    background: var(--brand-dark);
    text-decoration: none;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: .7rem .8rem;
    background: #fff;
}

label {
    color: var(--text);
    font-weight: 650;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto auto 1fr auto;
}

.test-banner {
    background: var(--warn-bg);
    color: var(--warn-text);
    border-bottom: 1px solid var(--warn-line);
    padding: .6rem 1rem;
    font-size: .92rem;
    font-weight: 750;
    text-align: center;
}

.app-header {
    background: #fff;
    border-bottom: 1px solid var(--line);
    padding: .9rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand-block {
    display: flex;
    flex-direction: column;
    gap: .1rem;
}

.brand-name {
    font-size: 1.25rem;
    font-weight: 900;
    letter-spacing: -.03em;
    color: var(--text);
}

.tenant-name {
    color: var(--muted);
    font-size: .92rem;
}

.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .75rem;
    flex-wrap: wrap;
}

.user-chip,
.role-chip {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
    background: var(--panel-soft);
    border-radius: 999px;
    padding: .35rem .65rem;
    color: var(--muted);
    font-size: .85rem;
    font-weight: 750;
}

.role-chip {
    color: var(--brand-dark);
    background: #ecfdf5;
    border-color: #a7f3d0;
}

.logout-link {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: .4rem .7rem;
    background: #fff;
}

.app-layout {
    width: min(1440px, 100%);
    margin: 0 auto;
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 1.25rem;
    padding: 1.25rem;
}

.app-sidebar {
    align-self: start;
    position: sticky;
    top: 86px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
}

.nav-title {
    margin: 0 0 .75rem;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 850;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.app-nav {
    display: grid;
    gap: .35rem;
}

.app-nav a {
    display: flex;
    align-items: center;
    min-height: 40px;
    padding: .65rem .75rem;
    border-radius: 12px;
    color: var(--text);
    font-weight: 750;
}

.app-nav a:hover {
    background: var(--panel-soft);
    text-decoration: none;
}

.app-nav a.active {
    background: #ccfbf1;
    color: var(--brand-dark);
}

.app-content {
    min-width: 0;
}

.breadcrumbs {
    margin: 0 0 .85rem;
    color: var(--muted);
    font-size: .9rem;
}

.breadcrumbs span {
    color: var(--text);
    font-weight: 750;
}

.content-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}

.page-header {
    background: linear-gradient(135deg, #ecfdf5, #eff6ff);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.35rem;
    margin: 0 0 1rem;
    box-shadow: var(--shadow);
}

.page-header h1 {
    margin: .15rem 0 .35rem;
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    letter-spacing: -.04em;
}

.page-header p {
    margin: .25rem 0;
    color: var(--muted);
}

.eyebrow {
    margin: 0;
    color: var(--brand-dark);
    font-size: .8rem;
    font-weight: 900;
    letter-spacing: .08em;
    text-transform: uppercase;
}

section,
.card {
    max-width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #f8fafc;
    color: #334155;
    font-size: .84rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    box-shadow: 0 1px 0 var(--line), 0 4px 10px rgba(15, 23, 42, .06);
}

th,
td {
    padding: .75rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

tr:hover td {
    background: #fbfdff;
}

dl {
    margin: 0;
}

dt {
    color: var(--muted);
    font-weight: 850;
}

dd {
    margin: 0;
}

.app-footer,
footer {
    border-top: 1px solid var(--line);
    background: #fff;
    padding: 1rem;
    text-align: center;
    color: var(--muted);
    font-size: .9rem;
}

.public-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr auto;
}

.public-main {
    width: min(960px, 100%);
    margin: 0 auto;
    padding: 1.25rem;
}

.public-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}

@media (max-width: 860px) {
    .app-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .header-actions {
        justify-content: flex-start;
    }

    .app-layout {
        grid-template-columns: 1fr;
        padding: .85rem;
        gap: .85rem;
    }

    .app-sidebar {
        position: static;
    }

    .app-nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .content-card {
        padding: .85rem;
    }

    .page-header {
        padding: 1rem;
    }

    table {
        min-width: 720px;
    }

    main,
    .app-content,
    section,
    div[style*="overflow-x:auto"] {
        overflow-x: auto;
    }
}

@media (max-width: 520px) {
    html {
        font-size: 15px;
    }

    .app-nav {
        grid-template-columns: 1fr;
    }

    .user-chip,
    .role-chip,
    .logout-link {
        width: 100%;
        justify-content: center;
    }
}


.content-card table,
.public-card table {
    border: 1px solid var(--line);
    border-radius: 14px;
}

.content-card div[style*="overflow-x:auto"],
.public-card div[style*="overflow-x:auto"] {
    max-height: 70vh;
    overflow: auto;
    border-radius: 14px;
}

.content-card > table,
.public-card > table {
    display: block;
    max-height: 70vh;
    overflow: auto;
}


/* Any table wrapper with horizontal overflow should also allow vertical scrolling
   so sticky table headers can stay visible inside long tables. */
.content-card div[style*="overflow-x:auto"],
.public-card div[style*="overflow-x:auto"],
.table-scroll {
    max-height: 70vh;
    overflow: auto !important;
    border-radius: 14px;
    border: 1px solid var(--line);
}

.content-card div[style*="overflow-x:auto"] table,
.public-card div[style*="overflow-x:auto"] table,
.table-scroll table {
    border: 0;
}

thead th {
    position: sticky;
    top: 0;
    z-index: 20;
}


.mobile-menu-toggle {
    display: none;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--brand-dark);
    border-radius: 999px;
    min-height: 40px;
    padding: .55rem .85rem;
    font-weight: 850;
}

@media (max-width: 860px) {
    .test-banner {
        padding: .45rem .75rem;
        font-size: .82rem;
        line-height: 1.25;
    }

    .app-header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: .75rem;
        padding: .8rem .85rem;
        position: sticky;
        top: 0;
    }

    .brand-name {
        font-size: 1.35rem;
        line-height: 1.1;
    }

    .tenant-name {
        font-size: .9rem;
    }

    .mobile-menu-toggle {
        display: inline-flex;
    }

    .header-actions {
        display: none;
        grid-column: 1 / -1;
        width: 100%;
        padding-top: .75rem;
    }

    .mobile-menu-open .header-actions {
        display: grid;
        gap: .55rem;
    }

    .app-layout {
        padding-top: .75rem;
    }

    .app-sidebar {
        display: none;
    }

    .mobile-menu-open .app-sidebar {
        display: block;
    }

    .breadcrumbs {
        margin-bottom: .65rem;
        font-size: .86rem;
    }

    .content-card {
        border-radius: 14px;
    }
}


.mobile-page-title {
    display: none;
}

@media (max-width: 860px) {
    .app-header {
        grid-template-columns: minmax(0, 1fr) auto;
        padding: .55rem .75rem;
        min-height: 56px;
    }

    .app-header .brand-block {
        display: none;
    }

    .mobile-page-title {
        display: block;
        min-width: 0;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: 1.15rem;
        font-weight: 900;
        letter-spacing: -.03em;
        color: var(--text);
    }

    .mobile-menu-toggle {
        min-height: 38px;
        min-width: 44px;
        padding: .45rem .7rem;
        border-radius: 12px;
        font-size: 1.1rem;
        line-height: 1;
    }

    .test-banner {
        font-size: .76rem;
        padding: .35rem .6rem;
    }

    .breadcrumbs {
        display: none;
    }

    .app-layout {
        padding-top: .55rem;
    }
}


/* Disable sticky table headers on small screens.
   Mobile tables need cleaner horizontal scrolling first; sticky headers can overlap
   unrelated content while the page scrolls. */
@media (max-width: 860px) {
    th,
    thead th {
        position: static;
        top: auto;
        z-index: auto;
    }

    .content-card div[style*="overflow-x:auto"],
    .public-card div[style*="overflow-x:auto"],
    .table-scroll {
        max-height: none;
        overflow-x: auto !important;
        overflow-y: visible !important;
    }
}

/* Fast edit table actions */
.zs-table-actions {
    white-space: nowrap;
    text-align: right;
    width: 1%;
}

.zs-icon-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 34px;
    border-radius: 10px;
    border: 1px solid transparent;
    text-decoration: none;
    font-size: 18px;
    line-height: 1;
}

.zs-icon-action:hover,
.zs-icon-action:focus {
    background: var(--panel-soft);
    border-color: var(--line);
    text-decoration: none;
}

@media (max-width: 700px) {
    .zs-icon-action {
        min-width: 42px;
        min-height: 42px;
        font-size: 20px;
    }
}

.admin-tenant-switcher {
    background: #fefce8;
    border-bottom: 1px solid #fde68a;
    padding: .55rem 1.25rem;
}

.admin-tenant-switcher form {
    width: min(1440px, 100%);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .65rem;
    flex-wrap: wrap;
}

.admin-tenant-switcher label {
    color: #854d0e;
    font-size: .85rem;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.admin-tenant-switcher select {
    width: auto;
    min-width: 280px;
    max-width: 100%;
    border-color: #facc15;
    background: #fff;
}

@media (max-width: 700px) {
    .admin-tenant-switcher form {
        justify-content: stretch;
    }

    .admin-tenant-switcher select {
        width: 100%;
        min-width: 0;
    }
}

.admin-view-as-banner {
    width: min(1440px, 100%);
    margin: .55rem auto 0;
    border: 1px solid #f59e0b;
    background: #fffbeb;
    color: #92400e;
    border-radius: 12px;
    padding: .55rem .75rem;
    font-size: .9rem;
    font-weight: 850;
}

.admin-view-as-exit {
    min-height: 38px;
    padding: .55rem .75rem;
    background: #fff7ed;
    color: #9a3412;
    border-color: #fed7aa;
}

/* Field Mode MVP */
.field-mode {
    display: grid;
    gap: 1rem;
}

.field-hero {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: stretch;
    flex-wrap: wrap;
}

.field-hero h1 {
    margin: .1rem 0 .35rem;
    font-size: clamp(1.6rem, 5vw, 2.4rem);
    letter-spacing: -.04em;
}

.eyebrow {
    margin: 0;
    color: var(--brand-dark);
    font-size: .78rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .08em;
}

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

.field-status-card,
.field-card,
.field-warning {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    padding: 1rem;
}

.field-status-card {
    min-width: min(100%, 280px);
    display: grid;
    gap: .6rem;
}

.field-status-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid var(--line);
    padding-bottom: .5rem;
}

.field-status-row:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.status-online {
    color: var(--brand-dark);
}

.status-offline {
    color: var(--warn-text);
}

.field-actions {
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
}

.secondary-button {
    background: #fff;
    color: var(--brand-dark);
}

.secondary-button:hover {
    color: #fff;
}

.field-warning {
    background: var(--warn-bg);
    color: var(--warn-text);
    border-color: var(--warn-line);
    font-weight: 750;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.field-card h2 {
    margin: 0 0 .25rem;
}

.field-card-wide {
    grid-column: 1 / -1;
}

.field-list {
    display: grid;
    gap: .5rem;
}

.field-list-row {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: .7rem;
    background: var(--panel-soft);
    display: grid;
    gap: .2rem;
}

.field-list-row span {
    color: var(--muted);
    font-size: .9rem;
}

@media (max-width: 760px) {
    .field-hero {
        display: grid;
    }

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

    .field-actions {
        display: grid;
    }

    .field-actions > * {
        width: 100%;
    }
}

/* Mobile admin controls should not dominate workspace pages */
@media (max-width: 760px) {
    .admin-tenant-switcher {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr;
        gap: .5rem;
        padding: .65rem;
        margin-top: .5rem;
        border-radius: 12px;
    }

    .admin-tenant-switcher form {
        display: grid;
        gap: .25rem;
    }

    .admin-tenant-switcher label {
        font-size: .72rem;
        letter-spacing: .06em;
        text-transform: uppercase;
    }

    .admin-tenant-switcher select {
        min-height: 42px;
        padding: .45rem .6rem;
        border-radius: 10px;
        font-size: .95rem;
    }

    .admin-view-as-banner {
        width: 100%;
        font-size: .8rem;
        padding: .55rem .7rem;
        border-radius: 10px;
    }
}

.field-disclosure {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8fafc;
    box-shadow: var(--shadow);
    padding: 1rem;
    display: grid;
    gap: .5rem;
}

.field-disclosure h2 {
    margin: 0;
    font-size: 1.05rem;
}

.field-disclosure p {
    margin: 0;
    color: var(--muted);
}

.field-disclosure .secondary-button {
    justify-self: start;
    margin-top: .25rem;
}

@media (max-width: 760px) {
    .field-disclosure .secondary-button {
        width: 100%;
    }
}

/* Auth hardening: POST logout button styled like the old logout link */
.header-actions form {
    margin: 0;
}

button.logout-link {
    appearance: none;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: #111827;
    border-radius: 999px;
    padding: 0.55rem 1rem;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

button.logout-link:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

/* Auth hardening: make POST logout visibly clickable */
.header-actions form button.logout-link {
    appearance: none;
    border: 1px solid #99f6e4;
    background: #ccfbf1;
    color: #115e59;
    border-radius: 999px;
    padding: 0.55rem 1rem;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    line-height: 1;
}

.header-actions form button.logout-link:hover,
.header-actions form button.logout-link:focus {
    background: #99f6e4;
    border-color: #5eead4;
    outline: 2px solid #5eead4;
    outline-offset: 2px;
}

/* Guest/auth screens */
.guest-body {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at top left, rgba(153, 246, 228, 0.35), transparent 32rem),
        linear-gradient(135deg, #f8fafc 0%, #eef2ff 100%);
    color: #0f172a;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.guest-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem;
    box-sizing: border-box;
}

.login-card {
    width: min(100%, 430px);
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #dbeafe;
    border-radius: 24px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.14);
    padding: 2.25rem;
}

.login-card h1 {
    margin: 0 0 0.65rem;
    font-size: clamp(2rem, 5vw, 2.75rem);
    line-height: 1.05;
    letter-spacing: -0.04em;
    color: #0f172a;
}

.login-card h1::after {
    content: "Secure foundation workspace";
    display: block;
    margin-top: 0.65rem;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #0f766e;
}

.login-card p {
    color: #475569;
    line-height: 1.55;
}

.login-card form {
    display: grid;
    gap: 0.85rem;
    margin-top: 1.35rem;
}

.login-card label {
    font-weight: 800;
    color: #334155;
    font-size: 0.95rem;
}

.login-card input[type="email"],
.login-card input[type="password"] {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    padding: 0.85rem 1rem;
    font: inherit;
    background: #ffffff;
    color: #0f172a;
    outline: none;
}

.login-card input[type="email"]:focus,
.login-card input[type="password"]:focus {
    border-color: #14b8a6;
    box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.16);
}

.login-card button[type="submit"] {
    margin-top: 0.35rem;
    border: 0;
    border-radius: 999px;
    padding: 0.9rem 1rem;
    background: #0f766e;
    color: #ffffff;
    font: inherit;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 12px 28px rgba(15, 118, 110, 0.26);
}

.login-card button[type="submit"]:hover,
.login-card button[type="submit"]:focus {
    background: #115e59;
}

.login-card a {
    color: #0f766e;
    font-weight: 800;
}

.login-card .errors {
    margin: 1rem 0;
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #991b1b;
    border-radius: 14px;
    padding: 0.85rem 1rem;
    font-weight: 700;
}

.login-card .notice {
    margin: 1rem 0;
    border: 1px solid #99f6e4;
    background: #f0fdfa;
    color: #115e59;
    border-radius: 14px;
    padding: 0.85rem 1rem;
    font-weight: 700;
}

@media (max-width: 520px) {
    .guest-shell {
        padding: 1rem;
        align-items: start;
        padding-top: 4rem;
    }

    .login-card {
        padding: 1.5rem;
        border-radius: 20px;
    }
}

/* Final override: keep POST logout button visible in all app header states */
.header-actions form .logout-link,
.header-actions form button.logout-link,
button.logout-link {
    appearance: none !important;
    border: 1px solid #99f6e4 !important;
    background: #ccfbf1 !important;
    color: #115e59 !important;
    border-radius: 999px !important;
    padding: 0.55rem 1rem !important;
    font: inherit !important;
    font-weight: 800 !important;
    cursor: pointer !important;
    line-height: 1 !important;
    text-decoration: none !important;
}

.header-actions form .logout-link:hover,
.header-actions form button.logout-link:hover,
button.logout-link:hover,
.header-actions form .logout-link:focus,
.header-actions form button.logout-link:focus,
button.logout-link:focus {
    background: #99f6e4 !important;
    border-color: #5eead4 !important;
    color: #0f766e !important;
    outline: 2px solid #5eead4 !important;
    outline-offset: 2px !important;
}


/* Hardening smoke fix: make logout label impossible to disappear */
.header-actions button.logout-link,
.header-actions form button.logout-link,
button.logout-link[type="submit"] {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 4.75rem !important;
    min-height: 2.15rem !important;
    opacity: 1 !important;
    visibility: visible !important;
    text-indent: 0 !important;
    overflow: visible !important;
    white-space: nowrap !important;
    background-color: #ccfbf1 !important;
    border-color: #99f6e4 !important;
    color: #115e59 !important;
    -webkit-text-fill-color: #115e59 !important;
}

/* Field Mode offline estimate draft builder */
.field-draft-grid {
    display: grid;
    gap: 0.85rem;
    grid-template-columns: minmax(0, 1fr);
    margin: 1rem 0;
}

.field-draft-grid label {
    display: grid;
    gap: 0.35rem;
    font-weight: 700;
}

.field-draft-grid select,
.field-draft-grid input {
    width: 100%;
    min-height: 2.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.75rem;
    padding: 0.65rem 0.75rem;
    font: inherit;
}

.field-draft-preview {
    border: 1px solid #cbd5e1;
    border-radius: 0.85rem;
    padding: 0.85rem;
    margin: 0.75rem 0;
    font-weight: 800;
    background: #f8fafc;
}

@media (min-width: 760px) {
    .field-draft-grid {
        grid-template-columns: minmax(0, 1.25fr) minmax(0, 1.25fr) minmax(7rem, 0.35fr);
    }
}
