* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    background: #f1f5f9;
    color: #0f172a;
    font-size: 14px;
}

a {
    color: inherit;
    text-decoration: none;
}

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

button {
    cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.hidden {
    display: none !important;
}

.app,
.screen {
    min-height: 100vh;
    padding: 16px;
    max-width: 1500px;
    margin: 0 auto;
}

.hero {
    background: #020617;
    color: #ffffff;
    border-radius: 28px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.22);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

.hero p {
    margin: 0 0 8px;
    color: #bfdbfe;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.28em;
}

.hero h1 {
    margin: 0;
    font-size: 32px;
    line-height: 1.15;
    font-weight: 900;
}

.hero span {
    display: block;
    margin-top: 9px;
    color: #cbd5e1;
    font-size: 14px;
}

.hero small {
    display: block;
    margin-top: 6px;
    color: #bfdbfe;
    font-size: 12px;
    font-weight: 700;
}

.menu {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 330px;
}

.menu form {
    margin: 0;
}

.btn {
    border: 0;
    border-radius: 10px;
    min-height: 34px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    line-height: 1;
}

.btn.dark {
    background: #020617;
    color: #ffffff;
}

.btn.dark:hover {
    background: #111827;
}

.btn.light {
    background: #ffffff;
    color: #020617;
    border: 1px solid #cbd5e1;
}

.btn.light:hover {
    background: #f8fafc;
}

.btn.red {
    background: #dc2626;
    color: #ffffff;
}

.btn.red:hover {
    background: #b91c1c;
}

.btn.small,
.btn-sm {
    min-height: 30px;
    padding: 7px 11px;
    font-size: 12px;
    border-radius: 9px;
}

.btn.disabled,
a.disabled {
    pointer-events: none;
    opacity: 0.55;
}

.card {
    background: #ffffff;
    border-radius: 24px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.08);
}

.card h2 {
    margin: 0 0 14px;
    font-size: 19px;
    font-weight: 900;
}

.filters {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 12px;
    align-items: end;
}

.filters label,
.edit-grid label {
    display: block;
}

.filters label > span,
.edit-grid label > span {
    display: block;
    margin-bottom: 5px;
    color: #64748b;
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.input,
select.input,
textarea.input {
    width: 100%;
    min-height: 42px;
    border: 1px solid #cbd5e1;
    border-radius: 16px;
    background: #ffffff;
    color: #0f172a;
    padding: 10px 12px;
    font-size: 14px;
    outline: none;
}

.input:focus,
select.input:focus,
textarea.input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

textarea.input,
.textarea {
    min-height: 105px;
    resize: vertical;
}

.stage-grid {
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.stage-card {
    min-height: 104px;
    border-radius: 18px;
    border: 1px solid rgba(15, 23, 42, 0.14);
    padding: 10px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
    overflow: hidden;
}

.stage-card b {
    display: inline;
    font-size: 20px;
    font-weight: 900;
}

.stage-card strong {
    display: block;
    margin-top: 4px;
    font-size: 18px;
    font-weight: 900;
}

.stage-card span {
    display: block;
    margin-top: 8px;
    font-size: 11px;
    font-weight: 900;
    line-height: 1.25;
}

.stage-card small {
    display: block;
    margin-top: 3px;
    font-size: 9px;
    font-weight: 700;
}

.table-wrap {
    width: 100%;
    max-height: 590px;
    overflow: auto;
    border-radius: 18px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
}

table {
    width: 100%;
    min-width: 2400px;
    border-collapse: collapse;
    font-size: 13px;
}

thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #0f172a;
    color: #ffffff;
}

th,
td {
    padding: 11px 12px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid rgba(148, 163, 184, 0.28);
}

th {
    font-size: 12px;
    font-weight: 900;
}

td {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
}

td.wide {
    min-width: 280px;
    max-width: 360px;
}

tbody tr {
    cursor: pointer;
}

tbody tr:hover {
    filter: brightness(0.96);
}

.alert {
    border-radius: 16px;
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 700;
}

.alert.amber {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fcd34d;
}

.alert.red {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.alert.blue {
    background: #eff6ff;
    color: #1e3a8a;
    border: 1px solid #bfdbfe;
}

.login-page {
    min-height: 100vh;
    background: #020617;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 80px 16px;
}

.login-card {
    width: 100%;
    max-width: 430px;
    background: #ffffff;
    border-radius: 28px;
    padding: 26px;
    box-shadow: 0 22px 65px rgba(0, 0, 0, 0.35);
}

.login-card h1 {
    margin: 0 0 18px;
    font-size: 30px;
    font-weight: 900;
}

.login-card .input {
    margin-bottom: 10px;
}

.hint {
    margin-top: 12px;
    color: #64748b;
    font-size: 12px;
}

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

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

.row .input {
    flex: 1;
    min-width: 220px;
}

.user-box {
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    padding: 12px;
    margin-bottom: 10px;
    background: #ffffff;
}

.user-box b {
    display: block;
    margin-bottom: 4px;
    font-size: 15px;
}

.user-box > div {
    color: #64748b;
    font-size: 13px;
    margin-bottom: 8px;
}

.chips {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 15px;
    padding: 10px 12px;
    background: #ffffff;
    margin: 0;
}

.chip span:first-child {
    overflow-wrap: anywhere;
    font-weight: 700;
}

.readonly-chip {
    background: #f8fafc;
}

.readonly-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #e2e8f0;
    color: #334155;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 900;
    white-space: nowrap;
}

.empty-state {
    width: 100%;
    padding: 12px;
    border-radius: 14px;
    background: #f8fafc;
    color: #64748b;
    font-size: 13px;
    font-weight: 700;
}

.tests {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 12px;
    margin-bottom: 16px;
}

.tests div {
    border-radius: 16px;
    padding: 12px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
    font-size: 13px;
    font-weight: 700;
}

.drawer-bg {
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(0, 0, 0, 0.34);
    display: flex;
    justify-content: flex-end;
}

.drawer {
    width: 100%;
    max-width: 620px;
    height: 100vh;
    overflow: auto;
    background: #ffffff;
    padding: 20px;
    box-shadow: -18px 0 60px rgba(0, 0, 0, 0.25);
}

.drawer-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.drawer-head h2 {
    margin: 0;
    font-size: 25px;
    font-weight: 900;
}

.drawer-head p {
    margin: 5px 0 0;
    color: #64748b;
}

.x {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #0f172a;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 900;
    line-height: 1;
}

.drawer-stages {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 18px;
}

.drawer-stages form {
    margin: 0;
}

.drawer-stages button {
    width: 100%;
    min-height: 42px;
    border: 1px solid rgba(15, 23, 42, 0.18);
    border-radius: 15px;
    padding: 9px 10px;
    text-align: left;
    font-size: 12px;
    font-weight: 900;
}

.drawer b {
    display: block;
    margin: 14px 0 7px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 18px;
}

.detail-grid > div {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 12px;
}

.detail-grid span {
    display: block;
    margin-bottom: 6px;
    color: #64748b;
    font-size: 10px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.detail-grid p {
    margin: 0;
    overflow-wrap: anywhere;
    font-size: 13px;
}

.modal-bg {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.42);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal {
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow: auto;
    background: #ffffff;
    border-radius: 28px;
    padding: 20px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

.modal.wide {
    max-width: 1080px;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.modal-head h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 900;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 18px;
}

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

.edit-grid .span2 {
    grid-column: 1 / -1;
}

.quote-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.quote-row .input {
    flex: 1;
}

.quote-row button {
    width: 38px;
    height: 38px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: #ffffff;
    color: #0f172a;
    font-weight: 900;
}

.other-currency {
    width: 66px;
    height: 38px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    text-align: center;
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.money-input {
    position: relative;
    width: 100%;
}

.money-input span {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    color: #64748b;
    font-weight: 900;
    pointer-events: none;
}

.money-input .input {
    position: relative;
    z-index: 1;
    width: 100%;
    padding-left: 34px !important;
}

.soft-box {
    border-radius: 16px;
    padding: 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

@media (max-width: 1250px) {
    .stage-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .filters {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .filters .btn {
        grid-column: 1 / -1;
        width: fit-content;
    }
}

@media (max-width: 900px) {
    .hero {
        flex-direction: column;
    }

    .menu {
        justify-content: flex-start;
        min-width: 0;
    }

    .filters,
    .grid2,
    .edit-grid,
    .detail-grid,
    .tests {
        grid-template-columns: 1fr;
    }

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

    .drawer-stages {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .app,
    .screen {
        padding: 10px;
    }

    .hero,
    .card,
    .modal {
        border-radius: 18px;
        padding: 14px;
    }

    .hero h1 {
        font-size: 24px;
    }

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

    .drawer {
        max-width: 100%;
        padding: 14px;
    }

    .chip,
    .row {
        align-items: stretch;
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .menu .btn,
    .modal-actions .btn,
    .row .btn {
        width: auto;
    }
}

/* Fixed floating Excel-style filters and collapsed date tree */
.th-filter-menu{
    position:fixed !important;
    z-index:999999 !important;
    width:320px;
    max-height:430px;
    overflow:auto;
    background:#ffffff;
    color:#0f172a;
    border:1px solid #cbd5e1;
    border-radius:14px;
    box-shadow:0 22px 70px rgba(15,23,42,.35);
}
.th-filter-menu.open{display:block !important;}
.date-tree-node{margin:2px 0;}
.date-tree-row{display:flex;align-items:center;gap:6px;}
.date-tree-row label{display:flex;align-items:center;gap:7px;min-width:0;flex:1;cursor:pointer;}
.date-tree-toggle{width:22px;height:22px;min-width:22px;border:1px solid #cbd5e1;border-radius:7px;background:#f8fafc;color:#0f172a;font-size:14px;font-weight:900;line-height:1;display:inline-flex;align-items:center;justify-content:center;padding:0;}
.date-tree-toggle:hover{background:#e2e8f0;}
.date-tree-children{display:none;}
.date-tree-node.open > .date-tree-children{display:block;}
.date-month-node{margin-left:18px;}
.date-day-group{margin-left:22px;}
.th-filter-option.date-month{padding-left:4px;}
.th-filter-option.date-day{padding-left:8px;}


/* Lead drawer instant auto-save for BD Comments and Q&A */
.drawer-comment-panel {
    margin-top: 12px;
}

.drawer-comment-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 7px;
}

.drawer-comment-title-row b,
.drawer-comment-panel b {
    margin: 0 0 7px;
}

.instant-save-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    border-radius: 999px;
    padding: 4px 10px;
    background: #f1f5f9;
    color: #64748b;
    font-size: 11px;
    font-weight: 900;
    white-space: nowrap;
}

.instant-save-status.saving {
    background: #fffbeb;
    color: #92400e;
}

.instant-save-status.saved {
    background: #ecfdf5;
    color: #047857;
}

.instant-save-status.error {
    background: #fef2f2;
    color: #b91c1c;
}

/* Main CRM compact viewport mode: keep the whole dashboard inside one browser window */
@media (min-width: 901px) {
    .app {
        height: 100vh;
        min-height: 0;
        max-width: 1440px;
        padding: 10px 12px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .app .hero {
        flex-shrink: 0;
        padding: 15px 20px;
        margin-bottom: 10px;
        border-radius: 22px;
        gap: 14px;
    }

    .app .hero p {
        margin-bottom: 5px;
        font-size: 11px;
        letter-spacing: 0.24em;
    }

    .app .hero h1 {
        font-size: 27px;
        line-height: 1.08;
    }

    .app .hero span {
        margin-top: 6px;
        font-size: 12px;
    }

    .app .hero small {
        margin-top: 4px;
        font-size: 11px;
    }

    .app .menu {
        gap: 7px;
        min-width: 0;
    }

    .app .menu .btn {
        min-height: 30px;
        padding: 7px 11px;
        font-size: 12px;
        border-radius: 9px;
    }

    .app > .card.filters {
        flex-shrink: 0;
        padding: 11px 14px;
        margin-bottom: 10px;
        border-radius: 20px;
        gap: 10px;
    }

    .app .filters label > span {
        margin-bottom: 4px;
        font-size: 10px;
    }

    .app .input,
    .app select.input,
    .app textarea.input {
        min-height: 36px;
        padding: 8px 11px;
        font-size: 13px;
        border-radius: 13px;
    }

    .app .stage-grid.stage-grid-compact {
        flex-shrink: 0;
        margin-bottom: 10px;
        gap: 8px;
        grid-template-columns: repeat(11, minmax(0, 1fr));
    }

    .app .stage-grid.stage-grid-compact .stage-card {
        min-height: 74px;
        padding: 7px 8px;
        border-radius: 14px;
        box-shadow: 0 4px 10px rgba(15, 23, 42, 0.08);
    }

    .app .stage-grid.stage-grid-compact .stage-card b {
        font-size: 18px;
    }

    .app .stage-grid.stage-grid-compact .stage-card strong {
        font-size: 14px;
        line-height: 1.05;
        margin-top: 3px;
    }

    .app .stage-grid.stage-grid-compact .stage-card span {
        margin-top: 5px;
        font-size: 8.5px;
        line-height: 1.1;
    }

    .app .stage-grid.stage-grid-compact .stage-card small {
        font-size: 7.5px;
        line-height: 1.05;
    }

    .app > .card:has(.table-wrap) {
        flex: 1 1 auto;
        min-height: 0;
        display: flex;
        flex-direction: column;
        padding: 12px;
        margin-bottom: 0;
        border-radius: 20px;
    }

    .app > .card:has(.table-wrap) .table-wrap {
        flex: 1 1 auto;
        height: 100%;
        max-height: none;
        min-height: 0;
        border-radius: 14px;
    }

    .app table {
        font-size: 12px;
    }

    .app th,
    .app td {
        padding: 8px 10px;
    }

    .app .lead-filter-summary {
        flex-shrink: 0;
        margin-top: 8px;
        padding: 8px 10px;
        font-size: 12px;
    }
}

@media (min-width: 901px) and (max-height: 820px) {
    .app {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .app .hero {
        padding: 12px 18px;
        margin-bottom: 8px;
    }

    .app .hero h1 {
        font-size: 25px;
    }

    .app > .card.filters {
        padding: 9px 12px;
        margin-bottom: 8px;
    }

    .app .stage-grid.stage-grid-compact {
        margin-bottom: 8px;
    }

    .app .stage-grid.stage-grid-compact .stage-card {
        min-height: 66px;
        padding: 6px 7px;
    }

    .app .stage-grid.stage-grid-compact .stage-card b {
        font-size: 16px;
    }

    .app .stage-grid.stage-grid-compact .stage-card strong {
        font-size: 12px;
    }

    .app .stage-grid.stage-grid-compact .stage-card span {
        font-size: 8px;
        margin-top: 4px;
    }

    .app > .card:has(.table-wrap) {
        padding: 10px;
    }

    .app th,
    .app td {
        padding-top: 7px;
        padding-bottom: 7px;
    }
}
