/* ===========================
   Reset & Base
   =========================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:        #f5f5f0;
    --surface:   #fff;
    --surface-2: #ececea;
    --border:    rgba(0,0,0,.12);
    --border-md: rgba(0,0,0,.2);
    --text:      #1a1a1a;
    --muted:     #666;
    --subtle:    #999;
    --primary:   #1a1a1a;
    --green:     #1D9E75;
    --amber:     #BA7517;
    --red:       #E24B4A;
    --blue:      #378ADD;
    --r-sm:      8px;
    --r-md:      12px;
    --r-lg:      16px;
    --shadow:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,.1);
    --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;

    /* Typography scale */
    --fs-body:      10.5pt;
    --fs-comment:   10pt;
    --fs-table:     8.5pt;
    --fs-table-th:  7.5pt;
    --fs-label:     8.5pt;
    --fs-small:     8pt;
    --fs-h1:        24pt;
    --fs-h2:        16pt;
    --fs-h3:        12pt;

    /* Semantic colors */
    --color-card-bg:    #f5f5f0;
    --color-card-bg-alt:#f9f9f7;
    --color-heading:    #1a1a1a;
    --color-secondary:  #888;
    --color-placeholder:#bbb;
    --color-danger:     #dc2626;
    --blue-accent:      #2563EB;
    --blue-accent-hover: #1d4ed8;
    --color-danger-border: #fca5a5;
    --color-danger-bg:  #fef2f2;
    --color-amber-bg:   #fdf8f0;
    --color-blue-bg:    #f0f5fd;

    /* Block tokens */
    --radius-card:      10px;
    --border-subtle:    0.5px solid rgba(0,0,0,.09);
    --border-separator: 0.5px solid rgba(0,0,0,.07);
    --table-header-bg:  #1a1a1a;
    --table-header-color: white;
    --table-hover-bg:   #f5f5f0;
    --table-totals-bg:  #f0f0ee;
}

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
a:hover { opacity: .7; }
img { max-width: 100%; height: auto; display: block; }

/* ===========================
   Navbar
   =========================== */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
    padding: 0 20px;
    background: var(--surface);
    border-bottom: 0.5px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar__brand a {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    letter-spacing: -.01em;
}
.navbar__right { display: flex; align-items: center; gap: 10px; }
.navbar__user { font-size: 12px; color: var(--muted); }

/* ===========================
   Buttons
   =========================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    border-radius: var(--r-sm);
    border: 0.5px solid var(--border-md);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 400;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    transition: background .12s, opacity .12s;
    white-space: nowrap;
    text-decoration: none;
    line-height: 1.4;
}
.btn:hover { background: rgba(0,0,0,.05); opacity: 1; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn--primary {
    background: var(--text);
    color: #fff;
    border-color: var(--text);
}
.btn--primary:hover { background: #333; }

.btn--ghost {
    background: transparent;
    border-color: var(--border-md);
}

.btn--danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn--danger:hover { opacity: .88; background: var(--red); }

.btn--sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.btn--icon { padding: 5px 7px; }

/* Toggle-кнопка (S/M/L, выравнивание, H1/H2/H3) — компактная, с active-состоянием */
.btn--toggle {
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 5px;
}
.btn--toggle.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--surface);
}
.btn--toggle svg { display: block; width: 18px; height: 14px; flex-shrink: 0; }

/* Пунктирная кнопка «добавить» */
.btn--dashed {
    border-style: dashed;
    color: var(--subtle);
    background: transparent;
}
.btn--dashed:hover { color: var(--text); border-color: var(--border-md); }

/* Компактная danger-обводка (удаление в BSP) */
.btn--danger-ghost {
    background: transparent;
    color: var(--color-danger);
    border-color: var(--color-danger-border);
}
.btn--danger-ghost:hover { background: var(--color-danger-bg); }

/* ===========================
   Main layout
   =========================== */
.main-content { padding: 28px 24px; max-width: 1100px; margin: 0 auto; }

/* ===========================
   Cards grid
   =========================== */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 10px;
    margin-top: 20px;
}

/* ===========================
   Page header
   =========================== */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 6px;
}
.page-header h1 { font-size: 18px; font-weight: 500; letter-spacing: -.01em; }
.page-header p { color: var(--muted); margin-top: 3px; font-size: 13px; }

/* ===========================
   Modal
   =========================== */
.modal-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 200;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }

.modal {
    background: var(--surface);
    border-radius: var(--r-lg);
    padding: 24px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-md);
    border: 0.5px solid var(--border);
}
.modal__title { font-size: 16px; font-weight: 500; margin-bottom: 18px; }
.modal__footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* Confirm dialog */
.confirm-dialog-backdrop { z-index: 500; }
.confirm-dialog {
    background: var(--surface);
    border-radius: var(--r-lg);
    padding: 24px;
    max-width: 360px;
    width: 90%;
    box-shadow: var(--shadow-md);
    border: 0.5px solid var(--border);
}
.confirm-dialog__msg {
    font-size: 14px;
    color: var(--text);
    line-height: 1.5;
    margin-bottom: 20px;
}
.confirm-dialog__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ===========================
   Form elements
   =========================== */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .04em; }
.form-control {
    width: 100%;
    padding: 7px 10px;
    border: 0.5px solid var(--border-md);
    border-radius: var(--r-sm);
    font-family: var(--font);
    font-size: 13px;
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: border-color .12s;
}
.form-control:focus { border-color: #555; }
.form-control::placeholder { color: #aaa; }
.form-select {
    width: 100%;
    padding: 7px 10px;
    border: 0.5px solid var(--border-md);
    border-radius: var(--r-sm);
    font-family: var(--font);
    font-size: 13px;
    color: var(--text);
    background: var(--surface);
    cursor: pointer;
    outline: none;
    transition: border-color .12s;
}
.form-select:focus { outline: none; border-color: #555; }
/* xs-модификаторы из двух классов (specificity 0,2,0); в редакторе их перебивает
   отдельное правило body.editor-body .form-*--xs (0,3,1) в editor.css */
.form-control.form-control--xs,
.form-select.form-select--xs { font-size: 11px; padding: 2px 4px; width: auto; height: auto; }
input[type="color"].form-control {
    width: 100%;
    height: 32px;
    padding: 2px 4px;
    border: 0.5px solid var(--border-md);
    border-radius: var(--r-sm);
    cursor: pointer;
    box-sizing: border-box;
}
input[type="number"].form-control {
    width: 80px;
    padding: 4px 6px;
    border: 0.5px solid var(--border-md);
    border-radius: var(--r-sm);
    font-size: 11px;
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    box-sizing: border-box;
}
input[type="number"].form-control:focus { outline: none; border-color: #555; }

/* ===========================
   Toast
   =========================== */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 999; display: flex; flex-direction: column; gap: 6px; }
.toast {
    padding: 10px 16px;
    border-radius: var(--r-sm);
    font-size: 13px;
    box-shadow: var(--shadow-md);
    animation: slideIn .18s ease;
    border: 0.5px solid rgba(0,0,0,.1);
}
.toast--success { background: var(--surface); color: var(--green); }
.toast--error   { background: #FCEBEB; color: #A32D2D; }
.toast--info    { background: var(--surface); color: var(--text); }

@keyframes slideIn {
    from { transform: translateX(24px); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

/* ===========================
   Breadcrumb
   =========================== */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--text); opacity: 1; }
.breadcrumb__sep { color: var(--border-md); }

/* ===========================
   Radio group
   =========================== */
.radio-group { display: flex; flex-direction: column; gap: 6px; }
.radio-group label { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text); text-transform: none; letter-spacing: 0; font-weight: 400; cursor: pointer; }

/* ===========================
   Divider
   =========================== */
.divider { height: 0.5px; background: var(--border); margin: 20px 0; }

/* ===========================
   Dark mode
   =========================== */
@media (prefers-color-scheme: dark) {
    :root {
        --bg:        #1a1a1a;
        --surface:   #222;
        --surface-2: #2a2a28;
        --border:    rgba(255,255,255,.1);
        --border-md: rgba(255,255,255,.2);
        --text:      #e8e8e0;
        --muted:     #999;
        --subtle:    #666;
        --primary:   #e8e8e0;
    }
    .btn--primary { background: #e8e8e0; color: #1a1a1a; border-color: #e8e8e0; }
    .btn--primary:hover { background: #ccc; }
    .toast--success, .toast--info { background: #2a2a28; }
}
