/* ===============================
   GLOBAL
================================== */

:root {
    --blue: #1e73be;
    --blue-dark: #155a8c;
    --navy: #003d73;
    --bg: #e5e9de;
    --text: #333;
    --muted: #666;
    --border: #d9d9d9;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: Calibri, Arial, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
}

h2 {
    text-align: center;
    font-size: 26px;
    margin: 0 0 12px;
    font-weight: bold;
}

section {
    border-top: 3px solid #c9c9c9;
    padding-top: 10px;
}

button {
    font-family: inherit;
    cursor: pointer;
}

.hint {
    color: var(--muted);
    font-size: 14px;
    text-align: center;
    margin: 0 0 12px;
}

[hidden] {
    display: none !important;
}


/* ===============================
   SESSION STATES (loading / login / app)
================================== */

#authLoading {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    z-index: 20000;
}

body.auth-pending #authLoading { display: flex; }
body.auth-pending #loginScreen,
body.auth-pending #appShell { display: none; }

body:not(.signed-in) #appShell { display: none; }
body.signed-in #loginScreen { display: none; }

.spinner {
    width: 42px;
    height: 42px;
    border: 4px solid #cfd8e3;
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }


/* ===============================
   LOGIN
================================== */

#loginScreen {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #1e73be, #003d73);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: #fff;
    padding: 28px 24px;
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.login-logo {
    font-size: 42px;
    text-align: center;
}

.login-card h1 {
    margin: 0;
    text-align: center;
    font-size: 24px;
    color: var(--navy);
}

.login-subtitle {
    margin: 0 0 10px;
    text-align: center;
    color: var(--muted);
}

.login-card label,
.modal-card label {
    font-weight: bold;
    font-size: 14px;
    margin-top: 6px;
}

.password-wrap {
    position: relative;
}

.password-wrap input {
    padding-right: 70px !important;
}

.password-wrap .link-button {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
}

.login-card .btn-primary {
    margin-top: 12px;
}

.login-message {
    min-height: 20px;
    margin: 4px 0 0;
    color: #9c0006;
    font-size: 14px;
}

.login-message.ok {
    color: #375623;
}

.login-links {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
}

.link-button {
    background: none;
    border: none;
    color: var(--blue);
    font-size: 14px;
    padding: 6px;
}


/* ===============================
   BUTTONS
================================== */

.btn-primary {
    background: var(--blue);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 16px;
    font-weight: bold;
}

.btn-primary:disabled,
.action-button:disabled {
    opacity: 0.6;
}

.btn-secondary {
    background: #fff;
    color: var(--blue);
    border: 2px solid var(--blue);
    border-radius: 8px;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: bold;
}

.btn-outline-danger {
    color: #c62828;
    border-color: #c62828;
}

.btn-small {
    background: var(--blue);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 13px;
    margin: 2px;
}

.btn-danger {
    background: #c62828;
}

.btn-ghost {
    background: transparent;
    border: 1px solid #c9d3df;
    color: var(--navy);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.section-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 14px;
}


/* ===============================
   TOP BAR
================================== */

#topBar {
    position: sticky;
    top: 0;
    z-index: 9999;
    background: #fff;
    padding: 8px 12px 10px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    width: 100%;
}

.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.brand {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.brand-title {
    font-weight: bold;
    color: var(--navy);
    font-size: 18px;
}

.current-project-label {
    font-size: 12px;
    color: var(--muted);
}

.top-total {
    font-size: 15px;
}

.top-total strong {
    color: var(--blue);
    font-size: 18px;
}

.user-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.action-button {
    background: #222;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 12px;
    font-weight: bold;
}

.action-save {
    background: #2e7d32;
}


/* ===========================
   TABS — HEADER BUTTONS
=========================== */

.tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
    padding: 6px 4px;
}

.tab-button {
    border: none;
    color: #fff;
    background-color: var(--blue);   /* Project info, Materials, Configuration */
    padding: 10px 15px;
    font-size: 11px;
    font-weight: bold;
    border-radius: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}

.tab-button[data-tab="business"]      { background-color: #4CAF50; }  /* verde */
.tab-button[data-tab="serviceLabor"]  { background-color: #370141; }  /* morado */
.tab-button[data-tab="costSummary"]   { background-color: #FF9800; }  /* naranja */
.tab-button[data-tab="finalQuote"]    { background-color: #E91E63; }  /* rosa */
.tab-button[data-tab="masterSummary"] { background-color: #607D8B; }  /* gris azulado */

.tab-button:hover {
    filter: brightness(0.88);
}

/* Animated border around the active tab */
.tab-button.active {
    position: relative;
    background-color: #003d73 !important;
    z-index: 1;
}

.tab-button.active::before {
    content: "";
    position: absolute;
    top: -4px;
    left: -4px;
    width: calc(100% + 8px);
    height: calc(100% + 8px);
    border-radius: 8px;
    background: linear-gradient(90deg, #00eaff, #0066ff, #00eaff, #0066ff);
    background-size: 900% 300%;
    animation: runLight 2.1s linear infinite;
    z-index: -1;
}

.tab-button.active::after {
    content: "";
    position: absolute;
    inset: 0;
    background: #003d73;
    border-radius: 6px;
    z-index: -1;
}

@keyframes runLight {
    0%   { background-position: 50% 100%; }
    33%  { background-position: 200% 50%; }
    66%  { background-position: 300% 100%; }
    100% { background-position: 50% 100%; }
}


/* ===========================
   CONTENT PANELS
=========================== */

#appMain {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px 12px 60px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}


/* ===============================
   TABLES — BLUE HEADER THEME
================================== */

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    background: #fff;
}

table th {
    background-color: var(--blue);
    color: #fff;
    padding: 10px 12px;
    font-weight: bold;
    border-bottom: 2px solid var(--blue-dark);
    text-align: left;
}

table td {
    border: 1px solid #c9c9c9;
    padding: 8px 10px;
    font-size: 15px;
    vertical-align: middle;
}

.info-table td:first-child {
    width: 45%;
}

.section-row td {
    background: #dbe8f6;
    color: var(--navy);
    font-weight: bold;
    letter-spacing: 0.5px;
    font-size: 14px;
}

.total-row td {
    background-color: #eaf3ff !important;
    font-weight: bold;
}

.grand-total td {
    background-color: #1e73be !important;
    color: #fff;
    font-size: 17px;
}

.cost-table td:last-child,
.labor-table td:last-child,
.labor-table th:last-child {
    text-align: right;
}

.labor-subtotal-row td,
.materials-subtotal-row td {
    font-weight: bold;
    text-align: right;
    background: #eaf3ff;
}

.zero-row td {
    color: #999;
}

.empty-row {
    text-align: center;
    color: var(--muted);
    padding: 20px !important;
}

/* Hide Interior or Exterior rows depending on the project type */
body[data-ptype="Interior"] #projectInfo [data-section="exterior"],
body[data-ptype="Exterior"] #projectInfo [data-section="interior"] {
    display: none;
}

.check-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    cursor: pointer;
}


/* ===============================
   INPUTS
   (16px font avoids the automatic zoom on iPhone)
================================== */

input[type="text"],
input[type="number"],
input[type="date"],
input[type="tel"],
input[type="email"],
input[type="password"],
input[type="search"],
select,
textarea {
    width: 100%;
    max-width: 640px;
    min-height: 44px;
    padding: 8px 10px;
    font-size: 16px;
    font-family: inherit;
    border: 1px solid #b5b5b5;
    border-radius: 6px;
    background: #fff;
    color: var(--text);
}

textarea {
    resize: vertical;
}

#config input,
#business input,
#business select {
    max-width: 240px;
}

input:focus,
select:focus,
textarea:focus {
    background-color: #fff7cc !important;
    outline: none !important;
    border-color: #e6c200 !important;
}

input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}


/* ===============================
   MATERIALS TABLE
================================== */

.materials-table td input[type="number"] {
    width: 100%;
    max-width: 110px;
}

.materials-table th:nth-child(1), .materials-table td:nth-child(1) { width: 6%;  text-align: center; }
.materials-table th:nth-child(2), .materials-table td:nth-child(2) { width: 11%; }
.materials-table th:nth-child(3), .materials-table td:nth-child(3) { width: 24%; }
.materials-table th:nth-child(4), .materials-table td:nth-child(4) { width: 7%;  }
.materials-table th:nth-child(5), .materials-table td:nth-child(5) { width: 8%;  }
.materials-table th:nth-child(6), .materials-table td:nth-child(6) { width: 12%; }
.materials-table th:nth-child(7), .materials-table td:nth-child(7) { width: 8%;  }
.materials-table th:nth-child(8), .materials-table td:nth-child(8) { width: 12%; }
.materials-table th:nth-child(9), .materials-table td:nth-child(9) { width: 12%; text-align: right; }

.material-used td {
    background-color: #e6f7e6 !important;
}


/* ===============================
   FINAL QUOTE
================================== */

#finalQuoteContent {
    padding: 24px;
    background: #fff;
    border: 2px solid #c9c9c9;
}

#finalQuoteContent h3 {
    margin: 30px 0 10px;
    font-size: 22px;
    border-bottom: 2px solid #c9c9c9;
    padding-bottom: 6px;
}

.fq-table {
    margin-top: 10px;
}

.fq-table td {
    border: none;
    padding: 7px 10px;
}

.fq-table tr:nth-child(even) td { background-color: #e8ebf0; }
.fq-table tr:nth-child(odd) td  { background-color: #f7f9fc; }

.fq-total td {
    background-color: #dbe8f6 !important;
    font-size: 17px;
}

.currency {
    text-align: right;
    white-space: nowrap;
}

.included,
.excluded,
.warning {
    padding: 6px 10px;
    border-radius: 4px;
}

.included {
    background: #e2f0d9 !important;
    color: #375623 !important;
    font-weight: bold;
}

.excluded {
    background: #fce4d6 !important;
    color: #9c0006 !important;
    font-weight: bold;
}

.warning {
    background: #fff4ce;
    color: #7a5b00;
    font-weight: bold;
    border-left: 4px solid #e6c200;
}

.fq-notes {
    background: #f7f9fc;
    padding: 8px 10px;
    border-left: 4px solid var(--blue);
}

.terms-list li {
    margin-bottom: 8px;
}

.signatures p {
    margin: 22px 0;
}

/* On screen the page break is a dashed line */
.page-break {
    border-top: 2px dashed #c9c9c9;
    margin: 30px 0;
}


/* ===============================
   MASTER SUMMARY
================================== */

.summary-toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.summary-toolbar input {
    flex: 1 1 260px;
}

#summaryTable thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.summary-actions {
    white-space: nowrap;
}

.current-project td {
    background: #fff7cc;
}

.details-panel {
    background: #fff;
    border: 2px solid var(--blue);
    border-radius: 8px;
    padding: 16px;
    margin-top: 20px;
}

.details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.details-header h3 {
    margin: 0;
}


/* ===============================
   ACCOUNT WINDOW + TOAST
================================== */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 15000;
}

.modal-card {
    background: #fff;
    width: 100%;
    max-width: 420px;
    border-radius: 12px;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.modal-card h3 {
    margin: 0 0 6px;
    color: var(--navy);
}

.modal-card .hint {
    text-align: left;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 10px;
}

#toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%) translateY(20px);
    background: #222;
    color: #fff;
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 15px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 16000;
    max-width: 90vw;
    text-align: center;
}

#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}


/* ===============================
   PHONES AND SMALL TABLETS
================================== */

@media (max-width: 768px) {

    h2 {
        font-size: 20px;
    }

    #topBar {
        padding: 6px 8px 8px;
    }

    .brand-title {
        font-size: 16px;
    }

    .user-actions {
        width: 100%;
        justify-content: flex-end;
    }

    /* Tabs in one row that scrolls sideways */
    .tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin-bottom: 6px;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .actions .action-button {
        flex: 1 1 0;
        padding: 10px 6px;
        font-size: 11px;
    }

    #appMain {
        padding: 10px 8px 60px;
    }

    table td,
    table th {
        padding: 7px 8px;
        font-size: 14px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .info-table td:first-child {
        width: 48%;
    }

    #config input,
    #business input,
    #business select {
        max-width: 100%;
    }

    /* Material list, labor and master summary become cards */
    .materials-table thead,
    .labor-table thead,
    .summary-table thead {
        display: none;
    }

    .materials-table,
    .materials-table tbody,
    .materials-table tr,
    .labor-table,
    .labor-table tbody,
    .labor-table tr,
    .summary-table,
    .summary-table tbody,
    .summary-table tr {
        display: block;
        width: 100%;
    }

    .materials-table tbody tr,
    .labor-table tbody tr,
    .summary-table tbody tr {
        background: #fff;
        border: 1px solid #c9c9c9;
        border-radius: 8px;
        margin-bottom: 10px;
        padding: 6px 10px;
    }

    .materials-table tbody td,
    .labor-table tbody td,
    .summary-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
        width: 100% !important;
        border: none;
        border-bottom: 1px solid #eee;
        padding: 6px 0;
        text-align: right !important;
        background: transparent !important;
    }

    .materials-table tbody td:last-child,
    .labor-table tbody td:last-child,
    .summary-table tbody td:last-child {
        border-bottom: none;
    }

    .materials-table tbody td::before,
    .labor-table tbody td::before,
    .summary-table tbody td::before {
        content: attr(data-label);
        font-weight: bold;
        color: var(--muted);
        text-align: left;
        flex-shrink: 0;
        max-width: 50%;
    }

    .materials-table tbody tr.material-used {
        background: #e6f7e6;
        border-color: #9ccc9c;
    }

    .materials-table .mat-material {
        font-weight: bold;
    }

    .materials-table td input[type="number"] {
        max-width: 130px;
    }

    .materials-table tfoot,
    .labor-table tfoot {
        display: block;
    }

    .materials-table tfoot tr,
    .labor-table tfoot tr {
        display: flex;
        justify-content: space-between;
        background: #eaf3ff;
        border-radius: 8px;
    }

    .materials-table tfoot td,
    .labor-table tfoot td {
        border: none;
        width: auto !important;
    }

    .summary-table .summary-actions {
        justify-content: flex-end;
    }

    .summary-table .summary-actions::before {
        content: none;
    }

    .empty-row::before {
        content: none !important;
    }

    .summary-table .empty-row,
    .labor-table .empty-row {
        justify-content: center;
        text-align: center !important;
    }

    #finalQuoteContent {
        padding: 12px;
    }

    #finalQuoteContent h3 {
        font-size: 18px;
    }

    .fq-table td,
    .fq-table th {
        font-size: 13px;
    }
}
