/* Design tokens — MEDPEDICURE clinical brand */

:root {
    /* Backgrounds */
    --paper:    #FFFFFF;
    --bg:       #F5F7FF;
    --bg-2:     #EDF1FB;

    /* Brand blues */
    --primary:    #3F4FE3;   /* royal blue - main CTA */
    --primary-2:  #3340C0;   /* darker hover */
    --primary-soft: #ECEFFD;
    --navy:       #2D40A8;   /* logo navy */
    --cyan:       #1FC1D4;   /* accent (top-right "Appointment" button on site) */
    --cyan-2:     #18A3B4;

    /* Text */
    --ink:    #0F1738;
    --ink-2:  #3D4567;
    --muted:  #7A82A0;
    --line:   #DFE4F2;
    --line-2: #C7CFE4;

    /* Status */
    --amber:        #D97706;
    --amber-bg:     #FEF7E6;
    --amber-border: #F0DCA9;
    --rose:         #C2424F;
    --rose-bg:      #FDEEF0;
    --emerald:      #0F9669;
    --emerald-bg:   #E6F5EF;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    font-feature-settings: 'cv11', 'ss01';
}

.font-display { font-family: 'Inter', sans-serif; font-weight: 600; letter-spacing: -0.02em; }

/* Tailwind colour helpers */
.bg-paper      { background: var(--paper); }
.bg-app        { background: var(--bg); }
.bg-bg-2       { background: var(--bg-2); }
.bg-primary    { background: var(--primary); }
.bg-primary-soft { background: var(--primary-soft); }
.bg-navy       { background: var(--navy); }
.bg-cyan       { background: var(--cyan); }
.bg-amber-soft { background: var(--amber-bg); }
.bg-emerald-soft { background: var(--emerald-bg); }
.text-primary  { color: var(--primary); }
.text-navy     { color: var(--navy); }
.text-cyan     { color: var(--cyan); }
.text-amber    { color: var(--amber); }
.text-emerald  { color: var(--emerald); }
.text-ink      { color: var(--ink); }
.text-ink-2    { color: var(--ink-2); }
.text-muted    { color: var(--muted); }
.border-line   { border-color: var(--line); }
.border-primary { border-color: var(--primary); }

.shadow-soft { box-shadow: 0 1px 2px rgba(15,23,56,0.04), 0 4px 16px rgba(15,23,56,0.04); }
.shadow-lift { box-shadow: 0 4px 24px rgba(15,23,56,0.08); }

/* Inputs */
.input, .select, textarea.input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 0.625rem;
    color: var(--ink);
    font-size: 16px; /* 16px чтобы iOS Safari не зумил при фокусе */
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
}
@media (min-width: 640px) {
    .input, .select, textarea.input { font-size: 0.95rem; }
}
/* Селект — с шевроном, потому что -webkit-appearance:none убирает нативную стрелку */
select.input, .select {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'><path d='M1 1.5L6 6.5L11 1.5' stroke='%237A82A0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}
.input:focus, textarea.input:focus, .select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(63,79,227,0.15);
}
textarea.input { resize: vertical; min-height: 80px; }

label.field-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--ink-2);
    margin-bottom: 0.375rem;
    letter-spacing: 0.005em;
}

/* Buttons — touch target min 44px на мобиле */
.btn-primary {
    background: var(--primary);
    color: white;
    padding: 0.625rem 1.25rem;
    border-radius: 0.625rem;
    font-weight: 500;
    transition: background .15s, transform .05s, box-shadow .15s;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.925rem;
    box-shadow: 0 1px 2px rgba(63,79,227,0.2);
    min-height: 44px;
    line-height: 1.2;
    -webkit-tap-highlight-color: transparent;
}
.btn-primary:hover { background: var(--primary-2); box-shadow: 0 4px 12px rgba(63,79,227,0.25); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

.btn-cyan {
    background: var(--cyan);
    color: white;
    padding: 0.625rem 1.25rem;
    border-radius: 0.625rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.925rem;
    transition: background .15s;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}
.btn-cyan:hover { background: var(--cyan-2); }

.btn-ghost {
    background: transparent;
    color: var(--ink-2);
    padding: 0.5rem 1rem;
    border-radius: 0.625rem;
    font-weight: 500;
    border: 1px solid var(--line);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.875rem;
    transition: background .15s, border-color .15s;
    min-height: 40px;
    -webkit-tap-highlight-color: transparent;
}
.btn-ghost:hover { background: var(--bg); border-color: var(--line-2); }

.btn-danger {
    background: transparent;
    color: var(--rose);
    padding: 0.5rem 1rem;
    border-radius: 0.625rem;
    font-weight: 500;
    border: 1px solid #ECC0C5;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.875rem;
    min-height: 40px;
    -webkit-tap-highlight-color: transparent;
}
.btn-danger:hover { background: var(--rose-bg); }

/* Patient list rows */
.patient-row {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 0.75rem;
    padding: 0.875rem 1rem;
    cursor: pointer;
    transition: border-color .15s, transform .05s, box-shadow .15s;
    display: flex;
    gap: 0.875rem;
    align-items: center;
    text-decoration: none;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}
@media (min-width: 640px) {
    .patient-row { padding: 1rem 1.25rem; gap: 1rem; }
}
.patient-row:active { background: var(--bg); }
.patient-row:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 12px rgba(63,79,227,0.08);
}

/* Safety strip - signature element */
.safety-strip {
    background: var(--amber-bg);
    border: 1px solid var(--amber-border);
    border-left: 4px solid var(--amber);
    border-radius: 0.625rem;
    padding: 0.875rem 1rem;
    display: flex;
    gap: 0.875rem;
    align-items: flex-start;
}
.safety-strip-empty {
    background: var(--emerald-bg);
    border: 1px solid #B7E0CC;
    border-left: 4px solid var(--emerald);
    border-radius: 0.625rem;
    padding: 0.75rem 1rem;
    color: var(--emerald);
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

/* Tabs */
.tab-button {
    padding: 0.625rem 0.875rem;
    border-radius: 0.5rem;
    color: var(--muted);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background .15s, color .15s;
    background: transparent;
    border: none;
    font-family: inherit;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
    display: inline-block;
}
/* Горизонтальный скролл для табов-контейнеров */
.tabs-scroll {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0.125rem;
}
.tabs-scroll::-webkit-scrollbar { display: none; }
.tab-button:hover { color: var(--ink); }
.tab-button.active {
    background: var(--primary-soft);
    color: var(--primary);
}

/* Modal */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,23,56,0.45);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 50;
    animation: fadeIn .15s ease-out;
}
.modal-panel {
    background: var(--paper);
    border-radius: 1rem;
    max-width: 640px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 20px 60px rgba(15,23,56,0.2);
    animation: slideUp .2s ease-out;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: translateY(0) } }

/* Photo thumb */
.photo-thumb {
    aspect-ratio: 1;
    border-radius: 0.625rem;
    overflow: hidden;
    background: var(--bg-2);
    position: relative;
    cursor: pointer;
    border: 1px solid var(--line);
    transition: transform .15s, box-shadow .15s;
}
.photo-thumb:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(15,23,56,.1); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }

.lightbox {
    position: fixed; inset: 0;
    background: rgba(15,23,56,0.94);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    padding: 2rem;
}
.lightbox img { max-width: 100%; max-height: 90vh; border-radius: 0.5rem; }
.lightbox-close {
    position: absolute; top: 1.25rem; right: 1.25rem;
    background: rgba(255,255,255,0.12); border: none; color: white;
    width: 40px; height: 40px; border-radius: 50%;
    font-size: 1.25rem; cursor: pointer;
}

/* Empty states */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--muted);
}
.empty-state h3 { font-weight: 600; font-size: 1.125rem; color: var(--ink-2); margin-bottom: 0.5rem; letter-spacing: -0.01em; }

/* Chips */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.625rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--bg-2);
    color: var(--ink-2);
    border: 1px solid var(--line);
    white-space: nowrap;
}
.chip-amber   { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-border); }
.chip-primary { background: var(--primary-soft); color: var(--primary); border-color: #CFD6FA; }
.chip-cyan    { background: #DAF6FA; color: var(--cyan-2); border-color: #B5EAF1; }
.chip-rose    { background: var(--rose-bg); color: var(--rose); border-color: #ECC0C5; }
.chip-emerald { background: var(--emerald-bg); color: var(--emerald); border-color: #B7E0CC; }
.chip-navy    { background: #E0E5F8; color: var(--navy); border-color: #C4CCEC; }

/* Tag input widget */
.tag-input-wrap {
    display: flex; flex-wrap: wrap;
    gap: 0.375rem;
    padding: 0.5rem;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 0.625rem;
    min-height: 2.625rem;
    transition: border-color .15s, box-shadow .15s;
}
.tag-input-wrap:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(63,79,227,0.15); }
.tag-input-wrap input {
    border: none; outline: none; flex: 1; min-width: 100px;
    font-family: inherit; font-size: 0.875rem; background: transparent;
}
.tag-pill {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.2rem 0.5rem 0.2rem 0.625rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 500;
}
.tag-pill button {
    background: none; border: none; cursor: pointer; padding: 0 0.125rem;
    color: inherit; opacity: 0.6; font-size: 0.95rem; line-height: 1;
}
.tag-pill button:hover { opacity: 1; }

.tag-suggestions {
    display: flex; flex-wrap: wrap; gap: 0.375rem; margin-top: 0.5rem;
}
.tag-suggest-btn {
    background: var(--bg);
    border: 1px dashed var(--line-2);
    color: var(--ink-2);
    padding: 0.2rem 0.625rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
}
.tag-suggest-btn:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

/* Toast */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: 0.625rem;
    font-size: 0.875rem;
    box-shadow: 0 8px 24px rgba(15,23,56,0.25);
    z-index: 200;
    animation: toastIn .2s ease-out;
}
.toast.error { background: var(--rose); }
.toast.success { background: var(--emerald); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px) } to { opacity: 1; transform: translate(-50%, 0) } }

/* Divider */
.divider {
    display: flex;
    align-items: center;
    color: var(--muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin: 1.5rem 0;
    font-weight: 600;
}
.divider::before, .divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--line);
}
.divider span { padding: 0 1rem; }

/* Visit timeline */
.visit-item {
    border-left: 2px solid var(--line);
    padding: 0 0 1.25rem 1.25rem;
    position: relative;
}
.visit-item::before {
    content: '';
    position: absolute;
    left: -5px; top: 4px;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--primary);
}
.visit-item:last-child { border-left-color: transparent; padding-bottom: 0; }

/* Upload zone */
.dropzone {
    border: 2px dashed var(--line-2);
    border-radius: 0.75rem;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all .15s;
    background: var(--bg);
}
.dropzone:hover, .dropzone.active { border-color: var(--primary); background: var(--primary-soft); }

/* ===== Calendar ===== */
.cal-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.cal-nav-btn {
    width: 38px; height: 38px;
    border-radius: 0.5rem;
    border: 1px solid var(--line);
    background: var(--paper);
    cursor: pointer;
    color: var(--ink-2);
    font-size: 1rem;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .15s, border-color .15s;
    -webkit-tap-highlight-color: transparent;
}
.cal-nav-btn:hover { background: var(--bg); border-color: var(--line-2); }
.cal-month-title {
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 1.125rem;
    color: var(--ink);
    margin: 0 0.5rem;
    min-width: 140px;
    text-align: center;
}

.cal-master-filter {
    display: flex; gap: 0.375rem; flex-wrap: wrap;
}
.cal-mchip {
    padding: 0.3rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--paper);
    font-size: 0.8rem;
    color: var(--ink-2);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    transition: all .15s;
    -webkit-tap-highlight-color: transparent;
}
.cal-mchip:hover { border-color: var(--line-2); }
.cal-mchip.active { background: var(--primary); color: white; border-color: var(--primary); }
.cal-mchip .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--m-color, var(--primary));
}

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: 0.75rem;
    overflow: hidden;
}
.cal-dow {
    background: var(--bg-2);
    padding: 0.5rem 0.5rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    text-align: center;
    font-weight: 600;
}
.cal-day {
    background: var(--paper);
    min-height: 88px;
    padding: 0.4rem 0.5rem;
    cursor: pointer;
    transition: background .12s;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}
.cal-day:hover { background: var(--bg); }
.cal-day.other { background: #FAFBFE; color: var(--muted); }
.cal-day.today .cal-day-num {
    background: var(--primary);
    color: white;
    width: 26px; height: 26px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 600;
}
.cal-day.selected {
    box-shadow: inset 0 0 0 2px var(--primary);
    background: var(--primary-soft);
}
.cal-day-num {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--ink);
    width: 26px; height: 26px;
    display: inline-flex; align-items: center; justify-content: center;
}
.cal-day.other .cal-day-num { color: var(--muted); }
.cal-day-events {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
    flex: 1;
}
.cal-event {
    font-size: 0.7rem;
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--primary-soft);
    color: var(--primary);
    border-left: 2px solid var(--m-color, var(--primary));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}
.cal-more {
    font-size: 0.65rem;
    color: var(--muted);
    padding: 0 2px;
}

/* Mobile calendar — compact */
@media (max-width: 640px) {
    .cal-day {
        min-height: 56px;
        padding: 0.25rem 0.3rem;
    }
    .cal-day-num { width: 22px; height: 22px; font-size: 0.75rem; }
    .cal-day-events { display: none; }
    .cal-day .cal-dot-row {
        display: flex; flex-wrap: wrap; gap: 2px;
        margin-top: 2px;
    }
    .cal-day .cal-dot-row .dot {
        width: 5px; height: 5px; border-radius: 50%;
        background: var(--m-color, var(--primary));
    }
    .cal-dow { padding: 0.35rem 0.2rem; font-size: 0.6rem; }
    .cal-month-title { font-size: 1rem; min-width: 110px; }
}
@media (min-width: 641px) {
    .cal-day .cal-dot-row { display: none; }
}

.cal-day-panel {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    margin-top: 1rem;
}
.cal-visit-item {
    display: flex;
    gap: 0.875rem;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--line);
    align-items: flex-start;
    cursor: pointer;
    transition: background .12s;
    border-radius: 0.5rem;
    margin: 0 -0.5rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    -webkit-tap-highlight-color: transparent;
}
.cal-visit-item:hover { background: var(--bg); }
.cal-visit-item:last-child { border-bottom: none; }
.cal-visit-time {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--ink);
    min-width: 50px;
    font-size: 0.875rem;
}
.cal-visit-bar {
    width: 3px; align-self: stretch;
    border-radius: 2px;
    background: var(--m-color, var(--primary));
    flex-shrink: 0;
}

/* ===== Reports ===== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.625rem;
    margin-bottom: 1rem;
}
@media (max-width: 640px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
}
.kpi-card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 0.875rem;
    padding: 0.875rem 1rem;
    border-top: 3px solid var(--kpi-color, var(--primary));
}
.kpi-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 0.3rem;
    font-weight: 600;
}
.kpi-value {
    font-size: 1.375rem;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kpi-sub { font-size: 0.7rem; color: var(--muted); margin-top: 0.2rem; line-height: 1.3; }
@media (min-width: 641px) {
    .kpi-card { padding: 1rem 1.25rem; }
    .kpi-value { font-size: 1.5rem; }
    .kpi-label { font-size: 0.7rem; }
    .kpi-sub { font-size: 0.75rem; }
}

/* Bar chart по мастерам */
.bar-row {
    display: grid;
    grid-template-columns: 160px 1fr 100px;
    gap: 0.75rem;
    align-items: center;
    padding: 0.5rem 0;
    font-size: 0.875rem;
}
.bar-label { color: var(--ink-2); font-weight: 500; min-width: 0; }
.bar-label .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track {
    height: 26px;
    background: var(--bg-2);
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}
.bar-fill {
    position: absolute; left: 0; top: 0; bottom: 0;
    background: var(--bar-color, var(--primary));
    border-radius: 6px;
    transition: width .4s ease;
    display: flex; align-items: center; padding-left: 0.5rem;
    color: white; font-weight: 600; font-size: 0.75rem;
    white-space: nowrap;
}
.bar-value {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--ink);
}
@media (max-width: 640px) {
    .bar-row {
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "label value"
            "bar bar";
        row-gap: 0.35rem;
        padding: 0.625rem 0;
    }
    .bar-row .bar-label { grid-area: label; font-size: 0.85rem; }
    .bar-row .bar-value { grid-area: value; font-size: 0.85rem; }
    .bar-row .bar-track { grid-area: bar; height: 22px; }
    .bar-fill { font-size: 0.7rem; }
}

/* Pie chart (donut) — простой SVG */
.donut-wrap { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.donut-wrap svg { width: 180px; height: 180px; flex-shrink: 0; }
.donut-legend { font-size: 0.8rem; min-width: 0; flex: 1; width: 100%; }
.donut-legend-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0; min-width: 0; }
.donut-legend-row .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend-row .val { color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; font-size: 0.75rem; }
.donut-legend-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
@media (max-width: 640px) {
    .donut-wrap { flex-direction: column; gap: 0.75rem; align-items: stretch; }
    .donut-wrap svg { width: 160px; height: 160px; margin: 0 auto; }
}

/* Tab subnav для Reports */
.subnav {
    display: flex; gap: 0.25rem;
    background: var(--bg-2);
    padding: 0.25rem;
    border-radius: 0.625rem;
    margin-bottom: 1.25rem;
    width: fit-content;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.subnav button {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--ink-2);
    font-weight: 500;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.subnav button.active {
    background: var(--paper);
    color: var(--ink);
    box-shadow: 0 1px 2px rgba(15,23,56,0.06);
}

/* Date range presets */
.date-presets {
    display: flex; gap: 0.375rem; flex-wrap: wrap;
}
.date-presets button {
    padding: 0.45rem 0.85rem;
    border-radius: 0.5rem;
    border: 1px solid var(--line);
    background: var(--paper);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    color: var(--ink-2);
    font-weight: 500;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.date-presets button.active { background: var(--primary); color: white; border-color: var(--primary); }
@media (max-width: 640px) {
    .date-presets {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin: 0 -1rem;
        padding: 0 1rem;
    }
    .date-presets::-webkit-scrollbar { display: none; }
}

/* Reports — стек фильтров на мобиле */
.reports-filter {
    display: grid;
    grid-template-columns: auto 1fr auto 1fr auto auto;
    gap: 0.5rem;
    align-items: center;
}
.reports-filter input[type="date"],
.reports-filter select { min-width: 0; }
@media (max-width: 640px) {
    .reports-filter {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "from-l to-l"
            "from to"
            "master master"
            "apply apply";
        gap: 0.5rem;
    }
    .reports-filter .lbl-from { grid-area: from-l; }
    .reports-filter .lbl-to   { grid-area: to-l; }
    .reports-filter .inp-from { grid-area: from; }
    .reports-filter .inp-to   { grid-area: to; }
    .reports-filter .sel-mst  { grid-area: master; }
    .reports-filter .btn-apply { grid-area: apply; width: 100%; }
}

/* Master filter chips — горизонтальный скролл на мобиле */
.cal-master-filter {
    display: flex; gap: 0.375rem; flex-wrap: wrap;
}
@media (max-width: 640px) {
    .cal-master-filter {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin: 0 -1rem;
        padding: 0 1rem;
    }
    .cal-master-filter::-webkit-scrollbar { display: none; }
}

/* Услуги/цены — таблица */
.price-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.price-table th, .price-table td {
    padding: 0.5rem 0.625rem;
    text-align: left;
    border-bottom: 1px solid var(--line);
}
.price-table th {
    background: var(--bg-2);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink-2);
    font-weight: 600;
}
.price-table td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}
.price-table .price-input {
    width: 80px; padding: 0.3rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: 0.375rem;
    font-size: 16px;
    font-variant-numeric: tabular-nums;
    text-align: right;
    background: var(--paper);
    color: var(--ink);
    font-family: inherit;
}
@media (min-width: 641px) {
    .price-table .price-input { font-size: 0.85rem; }
}
.price-table .price-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(63,79,227,0.15); }
.price-table .price-input.dirty { border-color: var(--amber); background: var(--amber-bg); }
.price-table .price-input.saved { border-color: var(--emerald); background: var(--emerald-bg); }

.scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-radius: 0.625rem;
}

/* Сервис-таблица → карточки на мобиле */
@media (max-width: 640px) {
    .svc-cards { display: flex; flex-direction: column; gap: 0.625rem; }
    .svc-card {
        background: var(--paper);
        border: 1px solid var(--line);
        border-radius: 0.75rem;
        padding: 0.875rem 1rem;
        display: flex;
        gap: 0.625rem;
        align-items: flex-start;
    }
    .svc-card.inactive { opacity: 0.55; }
    .svc-card .info { flex: 1; min-width: 0; }
    .svc-card .name { font-weight: 500; color: var(--ink); }
    .svc-card .meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.2rem; display: flex; flex-wrap: wrap; gap: 0.5rem; }
    .svc-card .price-tag {
        font-variant-numeric: tabular-nums;
        font-weight: 600;
        color: var(--ink);
        font-size: 1rem;
        white-space: nowrap;
        margin-left: auto;
    }
    .svc-card .actions { display: flex; flex-direction: column; gap: 0.35rem; flex-shrink: 0; margin-left: 0.5rem; }
    .svc-card .actions button { min-height: 32px; padding: 0.3rem 0.6rem; font-size: 0.75rem; }
}

/* Prices matrix — компактнее на мобиле */
@media (max-width: 640px) {
    .price-matrix th, .price-matrix td { padding: 0.4rem 0.4rem; font-size: 0.8rem; }
    .price-matrix .price-input { width: 64px; padding: 0.25rem 0.35rem; }
    .price-matrix th:first-child, .price-matrix td:first-child {
        position: sticky; left: 0; background: var(--paper); z-index: 1;
        box-shadow: 1px 0 0 var(--line);
        max-width: 140px;
    }
    .price-matrix thead th:first-child { background: var(--bg-2); }
}

/* Группа кнопок-действий в модалках (desktop) */
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    align-items: center;
}
.modal-actions-split {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

/* ===== AI Rewrite button ===== */
.ai-field {
    position: relative;
}
.ai-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.625rem;
    background: linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%);
    color: white;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 1px 3px rgba(99,102,241,0.3);
    transition: transform .08s, box-shadow .15s, opacity .15s;
    line-height: 1.2;
    min-height: 28px;
}
.ai-btn:hover { box-shadow: 0 3px 10px rgba(99,102,241,0.35); }
.ai-btn:active { transform: translateY(1px); }
.ai-btn:disabled { opacity: 0.55; cursor: wait; }
.ai-btn .spark { font-size: 0.85em; }
.ai-btn.loading .spark { animation: aiSpin 1s linear infinite; }
@keyframes aiSpin {
    from { transform: rotate(0); } to { transform: rotate(360deg); }
}

.field-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.375rem;
    flex-wrap: wrap;
}
.field-label-row .field-label { margin-bottom: 0; }

/* ===== Burger menu + Drawer ===== */
.burger {
    display: none;
    width: 40px; height: 40px;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    border-radius: 0.5rem;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}
.burger:active { background: var(--bg); }
.burger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--ink);
    border-radius: 2px;
    transition: transform .2s, opacity .15s;
}
.sm-only { display: none; }
@media (max-width: 640px) {
    .sm-only { display: flex; }
    .burger { display: flex; }
    .desktop-nav { display: none !important; }
}

.drawer-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,23,56,0.45);
    z-index: 60;
    animation: fadeIn .15s ease-out;
}
.drawer {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 80%;
    max-width: 320px;
    background: var(--paper);
    z-index: 70;
    display: flex;
    flex-direction: column;
    box-shadow: 8px 0 32px rgba(15,23,56,0.18);
    animation: drawerIn .25s cubic-bezier(.2,.7,.3,1);
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-left: env(safe-area-inset-left, 0);
}
@keyframes drawerIn {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

.drawer-header {
    padding: 1.25rem 1rem 1rem;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.drawer-header .avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}
.drawer-header .who { flex: 1; min-width: 0; }
.drawer-header .name { font-weight: 600; color: var(--ink); font-size: 0.95rem; truncate-text: true; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-header .role { font-size: 0.75rem; color: var(--muted); margin-top: 1px; }
.drawer-header .close {
    width: 32px; height: 32px;
    border-radius: 0.5rem;
    border: none; background: transparent;
    font-size: 1.1rem;
    color: var(--muted);
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.drawer-nav {
    flex: 1;
    padding: 0.625rem 0.5rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.drawer-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.875rem;
    border-radius: 0.625rem;
    color: var(--ink-2);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background .12s;
    -webkit-tap-highlight-color: transparent;
}
.drawer-nav a:active { background: var(--bg); }
.drawer-nav a.active {
    background: var(--primary-soft);
    color: var(--primary);
}
.drawer-nav a .icon {
    width: 22px; height: 22px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    color: currentColor;
}

.drawer-footer {
    padding: 0.75rem 1rem 1rem;
    border-top: 1px solid var(--line);
}
.drawer-footer .btn-logout {
    width: 100%;
    padding: 0.75rem;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 0.625rem;
    color: var(--rose);
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    -webkit-tap-highlight-color: transparent;
}
.drawer-footer .btn-logout:active { background: var(--rose-bg); }

/* ===== Mobile ===== */
@media (max-width: 640px) {
    /* Модалка — на всю высоту, без люфтов */
    .modal-backdrop {
        padding: 0;
        align-items: flex-end;
    }
    .modal-panel {
        border-radius: 1rem 1rem 0 0;
        max-height: 95vh;
        max-width: 100%;
        animation: slideUpMobile .25s ease-out;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    @keyframes slideUpMobile {
        from { opacity: 0; transform: translateY(20px) }
        to { opacity: 1; transform: translateY(0) }
    }

    /* Внутренние формы модалок — компактнее */
    .modal-panel form.p-6,
    .modal-panel > .p-6 { padding: 1.25rem 1rem; }

    /* Кнопки в группе — растягиваем равномерно */
    .modal-actions {
        flex-direction: column-reverse;
        gap: 0.5rem;
        width: 100%;
    }
    .modal-actions-split {
        flex-direction: column-reverse;
        gap: 0.5rem;
        align-items: stretch;
    }
    .modal-actions-split > div:empty { display: none; }
    .modal-actions .btn-primary,
    .modal-actions .btn-ghost,
    .modal-actions .btn-danger,
    .modal-actions-split > .btn-danger {
        width: 100%;
        text-align: center;
    }

    /* Подсветка эмпти-стейтов поменьше */
    .empty-state { padding: 2rem 1rem; }

    /* Сейфти-стрип — компактнее */
    .safety-strip { padding: 0.75rem 0.875rem; gap: 0.625rem; }

    /* Photo grid — больше колонок не нужно */
    .photo-thumb { border-radius: 0.5rem; }

    /* Лайтбокс — без рамок */
    .lightbox { padding: 0.5rem; }
    .lightbox img { max-height: 95vh; }
    .lightbox-close { top: 0.75rem; right: 0.75rem; }

    /* Toast не должен залезать под нав */
    .toast {
        bottom: calc(1rem + env(safe-area-inset-bottom, 0));
        left: 1rem; right: 1rem;
        transform: none;
        max-width: none;
    }
    @keyframes toastIn { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: translateY(0) } }

    /* Визит — поменьше отступы */
    .visit-item { padding: 0 0 1rem 1rem; }

    /* Dropzone — компактнее */
    .dropzone { padding: 1.25rem 1rem; }

    /* Уменьшить дефолтный размер h1 заголовков на мобиле */
    .font-display.text-2xl { font-size: 1.375rem; }
}

/* Safe-area для нотчей */
body {
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
}

/* Плавающая кнопка действия (FAB) — для мобилы */
.fab {
    position: fixed;
    right: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0));
    width: 56px; height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(63,79,227,0.35);
    font-size: 1.75rem;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 20;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}
.fab:active { transform: scale(0.95); }
@media (max-width: 640px) {
    .fab { display: flex; }
    .fab-hide-on-mobile { display: none !important; }
}
