/* ==========================================================================
   idbg — DESIGN BASE
   Reset, typography, buttons, inputs, utilities. No component-specific rules.
   ========================================================================== */

/* -------- Reset -------- */
*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-family: var(--font-ui);
    color: var(--color-text-primary);
    background: var(--color-canvas);
}

body {
    margin: 0;
    font-size: var(--text-body);
    /* cgbg sets body line-height to 1.6 */
    line-height: var(--leading-relaxed);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Слага се от app-ux.js, докато .modal-overlay е видим — страницата отдолу не
   бива да скролва, когато свърши скролът в модала. */
body.has-modal-open { overflow: hidden; }

/* Всяко `display: flex/grid/block` в компонент бие UA правилото `[hidden] {
   display: none }`, защото е по-специфично от селектор за елемент. Досега това
   се кърпеше поотделно на всеки компонент (.alert[hidden], .modal-overlay[hidden],
   .cmd-palette[hidden], .bulk-toolbar[hidden] …) и всеки нов скрит елемент
   тръгваше видим. Правилото е тук веднъж — атрибутът `hidden` вече значи скрит. */
[hidden] { display: none !important; }

img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--brand-blue); text-decoration: none; transition: color var(--duration-fast) var(--ease-out); }
a:hover { color: var(--brand-blue-dark); }

hr {
    border: 0;
    border-top: 1px solid var(--color-border);
    margin: var(--space-6) 0;
}

::selection { background: var(--brand-blue-light); color: var(--brand-blue-dark); }

/* -------- Typography -------- */
h1, h2, h3, h4, h5, h6 {
    margin: 0 0 var(--space-3);
    font-weight: 700;
    line-height: var(--leading-snug);
    color: var(--color-text-primary);
    letter-spacing: -0.01em;
}
h1 { font-size: var(--text-h2); font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: var(--text-h3); }
h3 { font-size: var(--text-h4); }
h4 { font-size: var(--text-body-lg); }
h5, h6 { font-size: var(--text-body); }

p { margin: 0 0 var(--space-3); }
p:last-child { margin-bottom: 0; }

small, .text-small { font-size: var(--text-small); }
.text-caption { font-size: var(--text-caption); }
.text-body    { font-size: var(--text-body); }
.text-body-lg { font-size: var(--text-body-lg); }
.text-h4 { font-size: var(--text-h4); }
.text-h3 { font-size: var(--text-h3); }
.text-h2 { font-size: var(--text-h2); }

.mono, code, pre, kbd { font-family: var(--font-mono); }
code {
    background: var(--color-bg-subtle);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 0.9em;
}

.muted { color: var(--color-text-secondary); }
.muted-label {
    color: var(--color-text-muted);
    font-size: var(--text-caption);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.text-center { text-align: center; }
.text-right { text-align: right; }

/* -------- Container -------- */
.container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 var(--container-padding);
    width: 100%;
}
.container-hero { max-width: var(--container-hero-max); margin: 0 auto; padding: 0 var(--container-padding); }

.main-content {
    flex: 1;
    padding: var(--space-6) 0 var(--space-12);
}

.app-page { padding: var(--space-6) 0 var(--space-12); }

/* -------- Skip link (a11y) -------- */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 8px;
    z-index: 99999;
    padding: var(--space-2) var(--space-3);
    background: var(--color-bg-card);
    color: var(--brand-blue);
    border: 2px solid var(--brand-blue);
    border-radius: var(--radius);
    font-weight: 600;
}
.skip-link:focus {
    left: var(--space-3);
    outline: 2px solid var(--brand-blue);
    outline-offset: 2px;
}

/* -------- Focus (a11y) -------- */
:focus-visible {
    outline: 2px solid var(--brand-blue);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--brand-blue);
    outline-offset: 2px;
}
input:focus,
select:focus,
textarea:focus {
    border-color: var(--brand-blue);
    box-shadow: var(--shadow-focus);
    outline: none;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 10px 16px;
    font-size: var(--text-small);
    font-weight: 600;
    line-height: 1;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: transparent;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    white-space: nowrap;
    user-select: none;
}
.btn:disabled,
.btn[disabled] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* Primary — cgbg is flat: solid fill, darker on hover, no shadow or lift. */
.btn-primary {
    background: var(--brand-blue);
    color: #fff;
    border-color: var(--brand-blue);
    box-shadow: none;
}
.btn-primary:hover {
    background: var(--brand-blue-dark);
    border-color: var(--brand-blue-dark);
    color: #fff;
    box-shadow: none;
}

/* Ghost (secondary) — cgbg outlines it in brand blue and fills on hover. */
.btn-ghost {
    background: transparent;
    color: var(--brand-blue);
    border-color: var(--brand-blue);
}
.btn-ghost:hover {
    background: var(--brand-blue);
    border-color: var(--brand-blue);
    color: #fff;
}

/* Danger variants */
.btn-danger {
    background: var(--color-danger);
    color: #fff;
    border-color: var(--color-danger);
}
.btn-danger:hover { background: #DC2626; border-color: #DC2626; color: #fff; }

.btn-danger-ghost { color: var(--color-danger); background: var(--color-bg-card); border-color: var(--color-border); }
.btn-danger-ghost:hover { background: var(--color-danger-bg); color: var(--color-danger); border-color: var(--color-danger); }

/* Sizes */
.btn-sm { padding: 6px 12px; font-size: var(--text-caption); border-radius: var(--radius-sm); }
.btn-lg { padding: 14px 24px; font-size: var(--text-body); border-radius: var(--radius-md); }
.btn-block { display: flex; width: 100%; }

/* ==========================================================================
   Forms — inputs, labels, selects, textareas
   ========================================================================== */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    font: inherit;
    font-size: var(--text-small);
    line-height: 1.4;
    color: var(--color-text-primary);
    background-color: var(--color-bg-input);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    transition: border-color var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
    appearance: none;
    -webkit-appearance: none;
}

/* Стрелките нагоре/надолу на number полетата отпадат навсякъде (Trello #124).
   `appearance: none` отгоре стига за Chrome/Safari, но не и за Firefox, а
   и не покрива псевдоелемента — затова и двете изрично. Стойността се пише
   и се сменя със стрелките на клавиатурата. */
input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

select {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 36px;
}

textarea { resize: vertical; min-height: 70px; line-height: 1.5; }

input[readonly],
input[disabled],
select[disabled],
textarea[disabled] {
    background-color: var(--color-bg-subtle);
    color: var(--color-text-secondary);
    cursor: not-allowed;
}

input::placeholder,
textarea::placeholder {
    color: var(--color-text-muted);
}

label {
    display: block;
    font-size: var(--text-small);
}
label > span:first-child {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--color-text-primary);
}
label > span.muted-label {
    font-weight: 400;
    font-size: var(--text-caption);
    color: var(--color-text-muted);
    text-transform: none;
    letter-spacing: 0;
}

/* Checkboxes inside a label ("legal-check" style for inline use) */
.legal-check {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-2) 0;
    cursor: pointer;
    user-select: none;
}
.legal-check input[type="checkbox"],
.legal-check input[type="radio"] {
    width: 18px;
    height: 18px;
    margin: 2px 0 0;
    accent-color: var(--brand-blue);
    cursor: pointer;
    flex-shrink: 0;
}
.legal-check span { font-size: var(--text-small); line-height: 1.45; }
.legal-check:hover { color: var(--color-text-primary); }

/* ==========================================================================
   Utilities
   ========================================================================== */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.mt-0 { margin-top: 0 !important; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }

.hidden { display: none !important; }

/* Animation — загатнати от data-loading, toast fade-in */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeOut {
    from { opacity: 1; }
    to   { opacity: 0; transform: translateY(-8px); }
}
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}
