:root {
    color-scheme: light;
    --crm-bg: #f2f5f8;
    --crm-surface: #ffffff;
    --crm-surface-muted: #f8fafc;
    --crm-sidebar: #182438;
    --crm-sidebar-muted: #8f9bad;
    --crm-sidebar-hover: #24344d;
    --crm-text: #202938;
    --crm-text-muted: #667085;
    --crm-border: #dfe5ec;
    --crm-border-strong: #cbd4df;
    --crm-primary: #2f80ed;
    --crm-primary-hover: #216dcc;
    --crm-primary-soft: #eaf3ff;
    --crm-danger: #c83f4d;
    --crm-danger-soft: #fff0f2;
    --crm-success: #22875a;
    --crm-success-soft: #e7f7ef;
    --crm-warning: #8a6512;
    --crm-warning-soft: #fff5d6;
    --crm-radius: 8px;
    --crm-shadow: 0 1px 3px rgba(20, 35, 55, 0.07);
    --crm-focus: 0 0 0 3px rgba(47, 128, 237, 0.16);
}

.client-card-layout { display:grid; gap:18px; margin-bottom:18px; }
.client-card-top { display:grid; grid-template-columns:repeat(2, minmax(0, 1fr)); gap:18px; align-items:stretch; }
.client-card-top > .panel { width:100%; height:100%; margin:0; }
.client-card-top > .panel:only-child { grid-column:1 / -1; }
.client-comment-card { width:100%; margin:0; }
.client-access-card .details { margin-bottom:12px; }
.card-access-actions { display:flex; flex-wrap:wrap; gap:8px; }
.max-toggle { border:1px solid transparent; color:#fff; }
.max-toggle.max-enabled { background:#198754; border-color:#157347; }
.max-toggle.max-enabled:hover { background:#157347; }
.max-toggle.max-disabled { background:#c43d4b; border-color:#aa303d; }
.max-toggle.max-disabled:hover { background:#aa303d; }
@media (max-width: 760px) {
    .client-card-top { grid-template-columns:1fr; }
}
* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--crm-bg);
}

body {
    margin: 0;
    background: var(--crm-bg);
    color: var(--crm-text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

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

a {
    color: var(--crm-primary);
    text-decoration: none;
}

a:hover {
    color: var(--crm-primary-hover);
}

.topbar {
    position: sticky;
    z-index: 20;
    top: 0;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px 0 18px;
    border-bottom: 1px solid var(--crm-border);
    background: var(--crm-surface);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--crm-text);
}

.brand:hover {
    color: var(--crm-text);
}

.brand-mark {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 7px;
    background: var(--crm-primary);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.brand-copy {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.brand-copy strong {
    font-size: 15px;
    font-weight: 750;
}

.brand-copy small {
    margin-top: 3px;
    color: var(--crm-text-muted);
    font-size: 11px;
}

.topbar-context {
    color: var(--crm-text-muted);
    font-size: 13px;
}

.app-shell {
    display: grid;
    min-height: calc(100vh - 56px);
    grid-template-columns: 76px minmax(0, 1fr);
    transition: grid-template-columns 0.22s ease;
}

.app-shell:has(.sidebar:hover),
.app-shell:has(.sidebar:focus-within) {
    grid-template-columns: 216px minmax(0, 1fr);
}

.sidebar {
    min-width: 0;
    padding: 18px 12px;
    overflow: hidden;
    background: var(--crm-sidebar);
    color: #fff;
}

.nav-link {
    display: flex;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 8px 10px;
    border-radius: 6px;
    color: #dbe3ee;
    font-size: 14px;
    font-weight: 600;
    transition:
        gap 0.22s ease,
        padding 0.22s ease,
        background-color 0.14s ease,
        color 0.14s ease;
}

.sidebar:hover .nav-link,
.sidebar:focus-within .nav-link {
    justify-content: flex-start;
    gap: 9px;
}

.nav-label {
    max-width: 0;
    overflow: hidden;
    opacity: 0;
    white-space: nowrap;
    transform: translateX(-4px);
    transition:
        max-width 0.22s ease,
        opacity 0.14s ease,
        transform 0.22s ease;
}

.sidebar:hover .nav-label,
.sidebar:focus-within .nav-label {
    max-width: 150px;
    opacity: 1;
    transform: translateX(0);
}

.nav-icon-svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

a.nav-link:hover {
    background: var(--crm-sidebar-hover);
    color: #fff;
}

.nav-link.active {
    background: var(--crm-primary);
    color: #fff;
}

.nav-link-disabled {
    color: #738197;
    cursor: default;
}

.content {
    width: 100%;
    max-width: 1440px;
    padding: 24px 30px 48px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.page-header {
    min-height: 46px;
    margin-bottom: 16px;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 3px;
    font-size: clamp(24px, 3vw, 28px);
    font-weight: 720;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

h2 {
    margin-bottom: 14px;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
}

.eyebrow {
    margin-bottom: 4px;
    color: var(--crm-primary);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.subtitle {
    margin-bottom: 0;
    color: var(--crm-text-muted);
    font-size: 13px;
}

.panel {
    padding: 20px;
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    background: var(--crm-surface);
    box-shadow: var(--crm-shadow);
}

.button {
    display: inline-flex;
    min-height: 36px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 7px 13px;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 650;
    line-height: 1.2;
    transition: border-color 0.14s ease, background-color 0.14s ease, color 0.14s ease;
}

.button:focus-visible {
    outline: none;
    box-shadow: var(--crm-focus);
}

.button-primary {
    background: var(--crm-primary);
    color: #fff;
}

.button-primary:hover {
    background: var(--crm-primary-hover);
    color: #fff;
}

.button-secondary {
    border-color: var(--crm-border-strong);
    background: var(--crm-surface);
    color: var(--crm-text);
}

.button-secondary:hover {
    border-color: #aeb9c7;
    background: var(--crm-surface-muted);
    color: var(--crm-text);
}

.crm-card-back {
    margin: 0 0 12px;
}

a.crm-back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    max-width: 100%;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--crm-text-muted);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    text-decoration: none;
    box-shadow: none;
}

a.crm-back-link:hover {
    background: var(--crm-primary-soft);
    color: var(--crm-primary);
    text-decoration: none;
}

a.crm-back-link:focus-visible {
    outline: 2px solid var(--crm-primary);
    outline-offset: 2px;
}

.button-ghost {
    border-color: transparent;
    background: transparent;
    color: var(--crm-text-muted);
}

.button-ghost:hover {
    background: var(--crm-surface-muted);
    color: var(--crm-text);
}

.button-danger {
    border-color: #efc7cc;
    background: var(--crm-danger-soft);
    color: var(--crm-danger);
}

.button-danger:hover {
    border-color: #e8afb6;
    background: #ffe5e8;
    color: #a92e3a;
}

.button-compact {
    min-height: 30px;
    padding: 5px 10px;
    font-size: 13px;
}

.table-panel {
    padding: 0;
    overflow: hidden;
}

.table-toolbar {
    display: flex;
    min-height: 62px;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--crm-border);
    background: var(--crm-surface-muted);
}

.client-list-controls {
    display: flex;
    min-width: 0;
    flex: 1;
    align-items: center;
    gap: 12px;
}

.status-filter {
    display: inline-flex;
    flex: 0 0 auto;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--crm-border);
    border-radius: 6px;
    background: #edf1f5;
}

.status-filter-link {
    display: inline-flex;
    min-height: 30px;
    align-items: center;
    padding: 5px 10px;
    border-radius: 4px;
    color: var(--crm-text-muted);
    font-size: 13px;
    font-weight: 650;
    white-space: nowrap;
}

.status-filter-link:hover {
    color: var(--crm-text);
}

.status-filter-link.active {
    background: var(--crm-surface);
    color: var(--crm-primary-hover);
    box-shadow: 0 1px 2px rgba(20, 35, 55, 0.12);
}

.search-form {
    display: flex;
    width: min(100%, 520px);
    min-width: 0;
    gap: 8px;
    margin: 0;
}

input,
select,
textarea {
    width: 100%;
    min-height: 40px;
    padding: 8px 11px;
    border: 1px solid var(--crm-border-strong);
    border-radius: 6px;
    background: var(--crm-surface);
    color: var(--crm-text);
    font-size: 15px;
    line-height: 1.35;
}

input::placeholder,
textarea::placeholder {
    color: #98a2b3;
}

textarea {
    min-height: 104px;
    resize: vertical;
}

input:hover,
select:hover,
textarea:hover {
    border-color: #aeb9c7;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--crm-primary);
    outline: none;
    box-shadow: var(--crm-focus);
}

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

.table-summary {
    flex: 0 0 auto;
    color: var(--crm-text-muted);
    font-size: 13px;
    white-space: nowrap;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th,
td {
    padding: 11px 16px;
    border-bottom: 1px solid var(--crm-border);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

th {
    background: #fbfcfd;
    color: var(--crm-text-muted);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: 0.045em;
    text-transform: uppercase;
}

tbody tr {
    transition: background-color 0.12s ease;
}

tbody tr:hover {
    background: #f7faff;
}

tbody tr.client-row-archived > td,
tbody tr.archived-row > td {
    background: #f1f3f6;
    color: var(--crm-text-muted);
    transition: background-color 0.12s ease;
}

tbody tr.client-row-archived:hover > td,
tbody tr.archived-row:hover > td {
    background: #e9edf2;
}

.client-row-archived td:first-child,
.archived-row td:first-child {
    box-shadow: inset 3px 0 0 #98a2b3;
}

.client-row-archived .client-name-link,
.archived-row .client-name-link {
    color: #596579;
}

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

a.client-name-link,
a.client-name-link:visited {
    color: #175ea8;
    font-weight: 700;
    text-decoration: none;
    text-decoration-line: none;
    border-bottom: 0;
    box-shadow: none;
}

a.client-name-link:hover {
    color: var(--crm-primary-hover);
    text-decoration: none;
    text-decoration-line: none;
    border-bottom: 0;
    box-shadow: none;
}

a.client-name-link:focus-visible {
    color: var(--crm-primary-hover);
    text-decoration: none;
    text-decoration-line: none;
    border-bottom: 0;
    border-radius: 3px;
    outline: 2px solid var(--crm-primary);
    outline-offset: 2px;
    box-shadow: none;
}

.phone-cell {
    color: #344054;
    font-variant-numeric: tabular-nums;
}

.status {
    display: inline-flex;
    min-height: 24px;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
}

.status-active {
    background: var(--crm-success-soft);
    color: var(--crm-success);
}

.status-archived {
    background: #edf0f4;
    color: #667085;
}

.status-planned {
    background: var(--crm-primary-soft);
    color: var(--crm-primary-hover);
}

.status-completed {
    background: var(--crm-success-soft);
    color: var(--crm-success);
}

.status-cancelled {
    background: var(--crm-danger-soft);
    color: var(--crm-danger);
}

.client-status-control {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.client-status-control form {
    display: inline-flex;
    margin: 0;
}

.form-panel {
    max-width: 900px;
}

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

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

.form-field label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 650;
}

.form-field small {
    display: block;
    margin-top: 5px;
    color: var(--crm-text-muted);
    font-size: 12px;
}

.required,
.field-error {
    color: var(--crm-danger);
}

.required {
    margin-left: 3px;
}

.field-error,
.errorlist {
    margin-top: 5px;
    font-size: 13px;
}

.errorlist {
    padding-left: 18px;
    color: var(--crm-danger);
}

.form-actions,
.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.form-actions {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--crm-border);
}

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

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

.details dt {
    margin-bottom: 4px;
    color: var(--crm-text-muted);
    font-size: 12px;
}

.details dd {
    margin: 0;
    font-size: 15px;
    font-weight: 650;
}

.comment {
    color: #475467;
    font-size: 14px;
}

.section-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.section-header h2,
.section-header .subtitle {
    margin-bottom: 0;
}

.schedule-panel {
    margin-top: 16px;
}

.schedule-group + .schedule-group {
    margin-top: 22px;
}

.schedule-group h3 {
    margin: 0 0 10px;
    font-size: 16px;
}

.compact-empty-state {
    padding: 22px 12px;
}

.entity-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.entity-tag {
    padding: 6px 10px;
    border: 1px solid var(--crm-border);
    border-radius: 6px;
    background: #f7f9fc;
    color: var(--crm-primary-hover);
    font-size: 14px;
    font-weight: 650;
    text-decoration: none;
}

.checkbox-select {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 14px;
    padding: 10px 12px;
    border: 1px solid var(--crm-border-strong);
    border-radius: 6px;
}

.checkbox-select label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-weight: 500;
}

.checkbox-select input[type="checkbox"],
.schedule-delete input[type="checkbox"] {
    width: 16px;
    min-height: 16px;
    padding: 0;
}

.schedule-form-table select,
.schedule-form-table input[type="time"] {
    min-width: 130px;
}

.schedule-delete {
    width: 82px;
    text-align: center;
}

.messages {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
}

.message,
.form-errors {
    padding: 10px 13px;
    border: 1px solid #b9e3cc;
    border-radius: 6px;
    background: var(--crm-success-soft);
    color: #176b45;
    font-size: 14px;
    font-weight: 600;
}

.message-error,
.form-errors {
    border-color: #efc7cc;
    background: var(--crm-danger-soft);
    color: var(--crm-danger);
}

.message-warning {
    border-color: #ead99e;
    background: var(--crm-warning-soft);
    color: var(--crm-warning);
}

.empty-state {
    padding: 52px 20px;
    color: var(--crm-text-muted);
    text-align: center;
}

.empty-state h2 {
    margin-bottom: 5px;
    color: var(--crm-text);
}

.empty-state p {
    margin-bottom: 0;
    font-size: 14px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 820px) {
    .topbar {
        height: 52px;
        padding: 0 14px;
    }

    .topbar-context,
    .brand-copy small {
        display: none;
    }

    .app-shell {
        display: block;
        min-height: calc(100vh - 52px);
    }

    .sidebar {
        display: flex;
        width: 100%;
        gap: 6px;
        padding: 9px 12px;
        overflow-x: auto;
        border-bottom: 1px solid #26364e;
        transition: none;
    }

    .nav-link {
        min-height: 36px;
        flex: 0 0 auto;
        justify-content: flex-start;
        gap: 8px;
        padding: 6px 9px;
        transition: background-color 0.14s ease, color 0.14s ease;
    }

    .sidebar:hover .nav-link,
    .sidebar:focus-within .nav-link {
        gap: 8px;
    }

    .nav-label,
    .sidebar:hover .nav-label,
    .sidebar:focus-within .nav-label {
        max-width: none;
        overflow: visible;
        opacity: 1;
        transform: none;
        transition: none;
    }

    .nav-link-disabled {
        display: none;
    }

    .content {
        padding: 20px 14px 38px;
    }

    .page-header {
        align-items: stretch;
        flex-direction: column;
    }

    .page-header {
        gap: 12px;
    }

    .header-actions,
    .page-header > .button {
        width: 100%;
    }

    .header-actions .button,
    .page-header > .button {
        flex: 1;
    }

    .table-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .client-list-controls {
        align-items: stretch;
        flex-direction: column;
    }

    .status-filter {
        align-self: flex-start;
    }

    .search-form {
        flex-wrap: wrap;
    }

    .search-form input {
        min-width: 100%;
        flex-basis: 100%;
    }

    .table-summary {
        align-self: flex-end;
    }

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

    .section-header {
        align-items: stretch;
        flex-direction: column;
    }

    .checkbox-select {
        grid-template-columns: 1fr;
    }

    .panel {
        padding: 16px;
    }

    .table-panel {
        padding: 0;
    }

    th,
    td {
        padding: 10px 12px;
    }
}
