/*
 * LDTools — base.css
 * Shared design foundations. Include on every LDTools surface.
 * Per-surface theme variables (--bg, --text, --accent …) are defined in each page's own <style> block.
 */

/* ─── Reset ─────────────────────────────────────────────────── */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ─── Structural tokens ─────────────────────────────────────── */

:root {
    /* Border radius */
    --r-xs:   4px;
    --r-sm:   6px;
    --r-md:   10px;
    --r-lg:   14px;
    --r-xl:   18px;
    --r-full: 9999px;

    /* Elevation */
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,.12);
    --shadow-lg: 0 20px 50px rgba(0,0,0,.22);

    /* Transitions */
    --t-fast: 0.15s ease;
    --t-base: 0.2s ease;
    --t-slow: 0.28s ease;

    /* Layering */
    --z-modal: 1000;
    --z-toast: 2000;
}

/* ─── Base body ─────────────────────────────────────────────── */

body {
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ─── Shared button system ──────────────────────────────────── */
/*
 * Use .btn as a base with a modifier:
 *   .btn.btn-primary   — filled accent
 *   .btn.btn-ghost     — outlined surface
 *   .btn.btn-danger    — filled red
 */

.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1.1rem;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    font-size: .875rem;
    font-weight: 600;
    font-family: inherit;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition:
        background var(--t-fast),
        border-color var(--t-fast),
        color var(--t-fast),
        opacity var(--t-fast);
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: .6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) {
    background: var(--accent-hov, color-mix(in srgb, var(--accent) 84%, #000));
    border-color: var(--accent-hov, color-mix(in srgb, var(--accent) 84%, #000));
}

.btn-ghost {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--bg);
}

.btn-danger {
    background: var(--danger, #dc2626);
    color: #fff;
    border-color: transparent;
}
.btn-danger:hover:not(:disabled) {
    background: #b91c1c;
}

/* ─── Modal ─────────────────────────────────────────────────── */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: 1.25rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-fast);
}
.modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-box {
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    padding: 1.6rem 1.5rem 1.4rem;
    max-width: 360px;
    width: 100%;
    transform: scale(.94) translateY(10px);
    transition: transform var(--t-base);
}
.modal-backdrop.open .modal-box {
    transform: scale(1) translateY(0);
}

.modal-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: .5rem;
}
.modal-desc {
    font-size: .9rem;
    color: var(--muted);
    line-height: 1.55;
    margin-bottom: 1.35rem;
}
.modal-desc strong {
    color: var(--text);
    font-weight: 600;
    word-break: break-all;
}
.modal-actions {
    display: flex;
    gap: .65rem;
    justify-content: flex-end;
}

/* ─── Toast ─────────────────────────────────────────────────── */

.toast-container {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: .65rem;
    z-index: var(--z-toast);
    pointer-events: none;
}
.toast {
    min-width: min(320px, calc(100vw - 2rem));
    max-width: min(360px, calc(100vw - 2rem));
    padding: .82rem .95rem;
    border-radius: var(--r-lg);
    box-shadow: 0 18px 35px rgba(15,23,42,.18);
    color: #fff;
    font-size: .88rem;
    line-height: 1.45;
    opacity: 0;
    transform: translateY(12px);
    animation: toast-in var(--t-base) forwards;
}
.toast-success { background: #166534; }
.toast-error   { background: #991b1b; }
.toast-info    { background: #1d4ed8; }
.toast.is-leaving { animation: toast-out .18s ease forwards; }

@keyframes toast-in  { to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

@media (max-width: 640px) {
    .toast-container { left: .85rem; right: .85rem; bottom: .85rem; }
    .toast { min-width: 0; max-width: none; }
}

/* ─── Form foundations ──────────────────────────────────────── */

.form-field { margin-bottom: .9rem; }
.form-field:last-of-type { margin-bottom: 0; }

.form-label {
    display: block;
    font-size: .82rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: .32rem;
}
.form-hint {
    font-weight: 400;
    color: var(--muted);
    margin-left: .3rem;
}

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: .48rem .7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .875rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,111,240,.12);
}
.form-textarea {
    resize: vertical;
    min-height: 68px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .75rem;
}
.form-check-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .3rem 0;
}
.form-check-row input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: var(--accent);
    flex-shrink: 0;
}
.form-check-row label {
    font-size: .875rem;
    cursor: pointer;
    user-select: none;
}

@media (max-width: 480px) {
    .form-row { grid-template-columns: 1fr; gap: 0; }
}
