:root {
    color-scheme: light;
    --bg: #f3f4f6;
    --panel: #ffffff;
    --panel-dark: #25262a;
    --nav-dark: #34363b;
    --border: #d9dde3;
    --grid-border: #d9dde3;
    --text: #1c1c1c;
    --body-text: #575d66;
    --muted: #7b838f;
    --workspace-button: #f4770a;
    --workspace-button-hover: #ab5307;
    --accent: #f4770a;
    --accent-dark: #ab5307;
    --brand: #312783;
    --danger: #b42318;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Roboto, Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--body-text);
}

button,
input {
    font: inherit;
}

.hidden {
    display: none !important;
}

.app-shell,
.workspace {
    min-height: 100vh;
}

.signed-out {
    max-width: 560px;
    margin: 18vh auto 0;
    padding: 32px;
    background: var(--panel);
    border: 1px solid var(--border);
}

.workspace {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.crm-shell-top {
    flex: 0 0 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 6px 10px;
    border-bottom: 3px solid var(--accent);
    background: #202125;
    color: var(--text);
    box-shadow: none;
}

.crm-brand {
    display: flex;
    align-items: center;
    min-width: 0;
}

.crm-brand-title {
    color: #ffffff;
    font-size: 13px;
    line-height: 17px;
    font-weight: 700;
    white-space: nowrap;
}

.tenant-label {
    display: inline-flex;
    align-items: center;
    margin-left: 12px;
    padding-left: 12px;
    border-left: 1px solid rgba(255, 255, 255, 0.18);
    color: #d9dde3;
    font-size: 11px;
    font-weight: 500;
}

.crm-top-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
}

.crm-shell-user {
    font-size: 11px;
    color: #d9dde3;
}

.module-content {
    flex: 1;
    min-height: 0;
    padding: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

h1,
h2,
p {
    margin: 0;
}

.panel,
.toolbar {
    background: var(--panel);
    border: 1px solid var(--border);
}

label {
    display: grid;
    gap: 3px;
    color: var(--body-text);
    font-size: 11px;
}

.cc-input,
input,
select {
    width: 100%;
    border: 1px solid var(--border);
    height: 30px;
    padding: 4px 8px;
    border-radius: 4px;
    color: var(--text);
    background: #fff;
}

.cc-button {
    min-height: 30px;
    border: 1px solid var(--workspace-button);
    border-radius: 6px;
    background: var(--workspace-button);
    color: #fff;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.cc-button:hover {
    background: var(--accent-dark);
}

.cc-button:disabled {
    cursor: wait;
    opacity: .7;
}

.cc-button.secondary {
    border-color: var(--border);
    background: #fff;
    color: var(--body-text);
}

.cc-inline-button {
    height: 24px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fff;
    color: var(--body-text);
    padding: 0 8px;
    font-size: 12px;
    cursor: pointer;
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(300px, 380px) minmax(620px, 1fr);
    gap: 8px;
    flex: 1;
    height: auto;
    min-height: 0;
}

.invoice-toolbar {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    align-items: end;
    gap: 7px;
}

.invoice-toolbar #invoiceCount {
    min-width: 26px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
}

.panel {
    min-width: 0;
    min-height: 0;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(23, 39, 54, 0.08);
    display: flex;
    flex-direction: column;
}

.panel-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 45px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    background: #f7f8fa;
}

.panel-heading h2 {
    font-size: 14px;
    line-height: 18px;
}

.panel-heading p {
    margin-top: 1px;
    color: var(--muted);
    font-size: 11px;
}

.table-wrap {
    overflow: auto;
    flex: 1;
    min-height: 0;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12px;
}

th,
td {
    height: 28px;
    padding: 4px 7px;
    border-right: 1px solid var(--grid-border);
    border-bottom: 1px solid var(--grid-border);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

th:first-child,
td:first-child {
    border-left: 1px solid var(--grid-border);
}

th {
    position: sticky;
    top: 0;
    z-index: 1;
    height: 29px;
    background: #f7f8fa;
    color: var(--text);
    font-size: 11px;
    font-weight: 700;
    text-transform: none;
    letter-spacing: 0;
    border-top: 1px solid var(--grid-border);
}

tbody tr:nth-child(even) {
    background: #fbfbfc;
}

tbody tr {
    cursor: pointer;
}

tbody tr:hover {
    background: #fff6ed;
}

tbody tr.selected {
    background: #fff1e3;
    outline: 1px solid var(--accent);
    outline-offset: -1px;
}

.number {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.empty-cell,
.detail-empty {
    color: var(--muted);
}

.error {
    color: var(--danger);
}

td[data-linked="1"] {
    color: var(--text);
    font-weight: 700;
}

.hidden-column {
    display: none;
}

.detail-panel {
    align-self: start;
    height: 100%;
}

#detailContent {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 10px;
}

.detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 7px 8px;
    border-bottom: 1px solid var(--border);
    background: #f7f8fa;
}

.details {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.detail-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    border: 1px solid var(--grid-border);
    background: #f7f8fa;
}

.detail-title span {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.detail-kpis {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
}

.detail-kpi {
    min-height: 48px;
    padding: 7px 9px;
    border: 1px solid var(--grid-border);
    background: #fff;
}

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

.detail-kpi strong {
    display: block;
    margin-top: 3px;
    font-size: 16px;
    line-height: 19px;
}

.config-section {
    border: 1px solid var(--grid-border);
    background: #fff;
}

.config-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--grid-border);
    background: #f7f8fa;
}

.config-head h3 {
    margin: 0;
    font-size: 13px;
}

.config-head span,
.subhead {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.config-content {
    padding: 8px;
    min-height: 0;
    overflow: auto;
}

.config-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    justify-content: flex-end;
    padding: 8px 0 0;
    background: #fff;
}

.subhead {
    margin-bottom: 5px;
}

.edit-grid input {
    height: 24px;
    min-width: 70px;
    border: 1px solid var(--border);
    border-radius: 2px;
    padding: 2px 5px;
    font-size: 12px;
}

.edit-grid .number-input {
    text-align: right;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(32, 36, 42, 0.42);
}

.modal-window {
    width: min(1180px, calc(100vw - 48px));
    height: min(760px, calc(100vh - 48px));
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--border);
    box-shadow: 0 16px 48px rgba(20, 31, 42, 0.28);
}

.modal-head {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

.modal-head h2 {
    font-size: 14px;
    line-height: 18px;
}

.modal-head p {
    color: var(--muted);
    font-size: 11px;
    line-height: 15px;
}

.modal-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 10px;
}

.modal-body .config-section {
    min-height: 100%;
}

@media (max-width: 980px) {
    .workspace {
        width: min(100vw - 24px, 1680px);
    }

    .crm-shell-top,
    .content-grid,
    .invoice-toolbar {
        grid-template-columns: 1fr;
    }

    .content-grid {
        height: auto;
    }

    .detail-kpis {
        grid-template-columns: 1fr;
    }

    .crm-shell-top {
        display: grid;
        height: auto;
        min-height: 54px;
        padding: 12px 16px;
    }
}
