/* Zenith.UX design system — shared primitives. Tokens use CSS variables so the host theme
   (Tailwind input.css) can override them. The palette mirrors the dark "studio" look & feel
   so Zenith components render correctly even before the host Tailwind sheet loads. */

:root {
    /* Canonical theme tokens (dark default) — kept in sync with the host input.css base layer. */
    --primary-color: #24cade;
    --primary-hover: #1db6c9;
    --primary-active: #1899a9;
    --primary-text: #0f172a;
    --bg-dark: #0f131a;
    --bg-medium: #1f2630;
    --bg-light: #181f25;
    --bg-content: #0f131a;
    --border-color: #2a313c;
    --text-primary: #e6ebf0;
    --text-secondary: #7e8ca0;
    --text-light: #d8e0e8;
    --text-muted: #7f8a9c;
    --status-success: #22c55e;
    --status-warning: #f59e0b;
    --status-info: #24cade;
    --status-danger: #f87171;

    /* Zenith primitives derive from the theme tokens above. */
    --zx-primary: var(--primary-color);
    --zx-primary-contrast: var(--primary-text);
    --zx-secondary: var(--bg-medium);
    --zx-secondary-contrast: var(--text-light);
    --zx-danger: var(--status-danger);
    --zx-danger-contrast: #0f172a;
    --zx-border: var(--border-color);
    --zx-muted: var(--text-secondary);
    --zx-surface: var(--bg-light);
    --zx-radius: 6px;
}

/* Buttons ---------------------------------------------------------------- */
.btn-studio {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--zx-radius);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    caret-color: transparent;
}
.btn-studio:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-studio--primary { background: var(--zx-primary); color: var(--zx-primary-contrast); }
.btn-studio--secondary { background: var(--zx-secondary); color: var(--zx-secondary-contrast); border-color: var(--zx-border); }
.btn-studio--danger { background: var(--zx-danger); color: var(--zx-danger-contrast); }
.btn-studio--ghost { background: transparent; color: var(--zx-primary); }

/* Forms ------------------------------------------------------------------ */
.ux-field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.form-label { font-weight: 600; font-size: 0.875rem; color: var(--zx-secondary-contrast); }
.form-input {
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--zx-border);
    border-radius: var(--zx-radius);
    font: inherit;
    background: var(--zx-surface);
}
.form-input:focus-visible { outline: 2px solid var(--zx-primary); outline-offset: 1px; }
.form-input--invalid { border-color: var(--zx-danger); }
.ux-field__hint { font-size: 0.8rem; color: var(--zx-muted); margin: 0; }

/* Button bar (global footer) — matches Polaris .app-footer height/paint ---- */
.ux-button-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    min-height: 52px;
    padding: 6px 1.5rem;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--zx-border);
    background: var(--sidebar-track-bg, var(--bg-dark, #0f131a));
    box-sizing: border-box;
    -webkit-user-select: none;
    user-select: none;
}

.ux-button-bar__row {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    width: 100%;
    gap: 0.5rem;
    overflow: visible;
}

.ux-button-bar__primary {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    min-width: 0;
    flex: 1 1 auto;
    gap: 0.5rem;
}

.ux-button-bar__right {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.ux-button-bar__separator {
    width: 1px;
    height: 28px;
    background-color: var(--zx-border);
    align-self: center;
    opacity: 0.85;
    flex-shrink: 0;
}

/* Compact control size — matches Polaris .button-bar-row button. */
.ux-button-bar .btn-studio {
    min-height: 34px;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    line-height: 1;
    border-radius: 8px;
    font-weight: 600;
}

.ux-button-bar .btn-studio--primary {
    padding-left: 14px;
    padding-right: 14px;
}

/* Theme toggle ----------------------------------------------------------- */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--zx-radius);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}
.theme-toggle:hover {
    color: var(--primary-color);
    background: var(--hover-color, var(--bg-medium));
    border-color: var(--primary-color);
}
.theme-toggle__icon { width: 1.15rem; height: 1.15rem; display: none; }
/* Show the sun in dark mode (click -> light), the moon in light mode (click -> dark). */
html[data-theme="dark"] .theme-toggle__sun,
html:not([data-theme]) .theme-toggle__sun { display: block; }
html[data-theme="light"] .theme-toggle__moon { display: block; }

/* Banner ----------------------------------------------------------------- */
.ux-banner {
    padding: 0.5rem 1.25rem;
    background: var(--zx-secondary);
    color: var(--zx-secondary-contrast);
    font-weight: 600;
}

/* Spinner ---------------------------------------------------------------- */
.ux-spinner { display: flex; align-items: center; gap: 0.6rem; color: var(--zx-muted); }
.ux-spinner__circle {
    width: 1.1rem; height: 1.1rem;
    border: 2px solid var(--zx-border);
    border-top-color: var(--zx-primary);
    border-radius: 50%;
    animation: ux-spin 0.8s linear infinite;
}
@keyframes ux-spin { to { transform: rotate(360deg); } }

/* Modal ------------------------------------------------------------------ */
.ux-modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
}
.ux-modal {
    background: var(--zx-surface);
    border-radius: 8px;
    min-width: 22rem; max-width: 90vw; max-height: 85vh;
    display: flex; flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.ux-modal__header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--zx-border); }
.ux-modal__title { margin: 0; font-size: 1.1rem; }
.ux-modal__close { background: none; border: none; cursor: pointer; font-size: 1rem; }
.ux-modal__body { padding: 1.25rem; overflow-y: auto; }
.ux-modal__footer { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0.75rem 1.25rem; border-top: 1px solid var(--zx-border); }

/* Toasts ----------------------------------------------------------------- */
.ux-toast-host { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 1100; }
.ux-toast {
    display: flex; align-items: flex-start; gap: 0.75rem;
    min-width: 16rem; max-width: 24rem;
    padding: 0.75rem 0.9rem;
    border-radius: var(--zx-radius);
    border-left: 4px solid var(--zx-primary);
    background: var(--zx-surface);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}
.ux-toast--success { border-left-color: var(--status-success); }
.ux-toast--warning { border-left-color: var(--status-warning); }
.ux-toast--error { border-left-color: var(--zx-danger); }
.ux-toast__title { font-weight: 600; }
.ux-toast__message { font-size: 0.85rem; color: var(--zx-muted); }
.ux-toast__close { margin-left: auto; background: none; border: none; cursor: pointer; }
