/**
 * Bonsai Dashboard — ArtCraft Studio Design System (v4.0)
 * Precision Grid • Hairline Aesthetics • Archivo & Geist Mono • Dual Theme
 */

/* ==============================================================================
   1. VARIABLES & DESIGN TOKENS
   ============================================================================== */

:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Archivo', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-serif: 'Instrument Serif', Georgia, serif;
    --font-mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

    /* ArtCraft Light Theme Tokens (#f2f1ee) */
    --bg: #f2f1ee;
    --bg-raised: #faf9f7;
    --bg-sunken: #e9e8e4;
    --ink: #101014;
    --ink-strong: #000000;
    --muted: rgba(16, 16, 20, 0.62);
    --faint: rgba(16, 16, 20, 0.42);
    --line: rgba(16, 16, 20, 0.16);
    --line-strong: rgba(16, 16, 20, 0.40);
    --accent: #2d81ff;
    --accent-ink: #1659c4;
    --invert-bg: #101014;
    --invert-fg: #f2f1ee;
    --danger: #b3261e;
    --c-healthy: #10b981;
    --c-warning: #f59e0b;
    --c-danger: #ef4444;
    --c-stress: #f59e0b;
    color-scheme: light;
}

[data-theme="dark"] {
    /* ArtCraft Dark Studio Theme Tokens (#121316) */
    --bg: #121316;
    --bg-raised: #18191d;
    --bg-sunken: #0a0a0c;
    --ink: #ededee;
    --ink-strong: #ffffff;
    --muted: rgba(237, 237, 238, 0.60);
    --faint: rgba(237, 237, 238, 0.38);
    --line: rgba(237, 237, 238, 0.14);
    --line-strong: rgba(237, 237, 238, 0.38);
    --accent: #2d81ff;
    --accent-ink: #74aaff;
    --invert-bg: #ffffff;
    --invert-fg: #0b0b0c;
    --danger: #ff6259;
    --c-healthy: #10b981;
    --c-warning: #f59e0b;
    --c-danger: #ef4444;
    --c-stress: #f59e0b;
    color-scheme: dark;
}

/* ==============================================================================
   2. BASE RESET & TYPOGRAPHY
   ============================================================================== */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html, body {
    width: 100%;
    height: 100%;
    background-color: var(--bg);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.5;
    overflow-x: hidden;
    transition: background-color 0.2s ease, color 0.2s ease;
}

#app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
}

.font-display { font-family: var(--font-display); }
.font-serif { font-family: var(--font-serif); }
.font-mono { font-family: var(--font-mono); }
.text-ink { color: var(--ink); }
.text-ink-strong { color: var(--ink-strong); }
.text-muted { color: var(--muted); }
.text-faint { color: var(--faint); }
.text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }
.bg-bg { background-color: var(--bg); }
.bg-bg-raised { background-color: var(--bg-raised); }
.bg-bg-sunken { background-color: var(--bg-sunken); }
.bg-line { background-color: var(--line); }

/* Utility HUD Label (ArtCraft) */
.hud-label {
    font-family: var(--font-mono);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-size: 0.6875rem;
    font-weight: 500;
}

/* Hairline Grid Corner Ticks (ArtCraft) */
.tick {
    pointer-events: none;
    width: 11px;
    height: 11px;
    position: absolute;
}
.tick:before, .tick:after {
    content: "";
    background: var(--line-strong);
    position: absolute;
}
.tick:before {
    width: 1px;
    top: 0;
    bottom: 0;
    left: 5px;
}
.tick-half:before {
    top: 5px;
}
.tick:after {
    height: 1px;
    top: 5px;
    left: 0;
    right: 0;
}

/* Border utilities */
.border-line { border-color: var(--line); }
.border-b { border-bottom-width: 1px; border-bottom-style: solid; }
.border-t { border-top-width: 1px; border-top-style: solid; }
.border-r { border-right-width: 1px; border-right-style: solid; }
.border-l { border-left-width: 1px; border-left-style: solid; }
.border-x { border-left-width: 1px; border-right-width: 1px; border-style: solid; }
.border-y { border-top-width: 1px; border-bottom-width: 1px; border-style: solid; }
.border { border-width: 1px; border-style: solid; }

.hidden { display: none !important; }

/* SVG guards */
svg {
    flex-shrink: 0;
}
nav svg, button svg, a svg, .btn svg, .icon-svg {
    max-width: 22px;
    max-height: 22px;
    flex-shrink: 0;
}

/* Core Layout Utilities */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-stretch { align-items: stretch; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.flex-1 { flex: 1 1 0%; }
.flex-shrink-0 { flex-shrink: 0; }
.min-w-0 { min-width: 0; }
.w-full { width: 100%; }
.h-full { height: 100%; }
.h-12 { height: 3rem; }
.h-5 { height: 1.25rem; }
.w-5 { width: 1.25rem; }
.h-4 { height: 1rem; }
.w-4 { width: 1rem; }
.gap-1 { gap: 0.25rem; }
.gap-1\.5 { gap: 0.375rem; }
.gap-2 { gap: 0.5rem; }
.gap-2\.5 { gap: 0.625rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-2\.5 { padding-left: 0.625rem; padding-right: 0.625rem; }
.px-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
.py-1\.5 { padding-top: 0.375rem; padding-bottom: 0.375rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.sticky { position: sticky; }
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.top-0 { top: 0; }
.left-0 { left: 0; }
.right-0 { right: 0; }
.bottom-0 { bottom: 0; }
.inset-0 { inset: 0; }
.z-50 { z-index: 50; }
.z-40 { z-index: 40; }
.z-30 { z-index: 30; }
.z-20 { z-index: 20; }
.z-10 { z-index: 10; }
@media (min-width: 1024px) {
    .lg\:flex { display: flex; }
    .lg\:hidden { display: none; }
}

/* ==============================================================================
   3. STICKY HUD NAVIGATION (#site-nav)
   ============================================================================== */

#site-nav {
    border-bottom: 1px solid var(--line);
    background-color: var(--bg);
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.nav-select {
    appearance: none;
    background: transparent;
    border: none;
    color: var(--ink);
    padding: 0 4px;
    outline: none;
}
.nav-select option {
    background-color: var(--bg-raised);
    color: var(--ink);
}

.dot-live {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--c-healthy);
    box-shadow: 0 0 6px var(--c-healthy);
    display: inline-block;
    transition: all 0.3s ease;
}
.stream-pulse {
    transform: scale(1.4);
}

.nav-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: var(--font-mono);
}

/* ==============================================================================
   4. MARQUEE TELEMETRY TICKER (ArtCraft Continuous Ribbon)
   ============================================================================== */

.marquee {
    overflow: hidden;
    width: 100%;
    display: flex;
    border-bottom: 1px solid var(--line);
    background-color: var(--bg);
}

.marquee-track {
    display: flex;
    flex-shrink: 0;
    list-style: none;
    animation: marquee-scroll 50s linear infinite;
}

.marquee-track li {
    font-size: 0.6875rem;
}

@keyframes marquee-scroll {
    0% { transform: translateX(0); }
    100% { transform: translateX(-100%); }
}

/* ==============================================================================
   5. STUDIO VIEWPORT & CANVAS (#studio-viewport)
   ============================================================================== */

#studio-viewport {
    background-color: var(--bg);
}

#canvas-wrapper {
    position: relative;
    width: 100%;
    height: calc(100vh - 138px);
    min-height: 520px;
    background-color: var(--bg);
    overflow: hidden;
}

#bonsai-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
    touch-action: none;
}

#bonsai-canvas:active {
    cursor: grabbing;
}

/* Floating Studio Controls Bar (Top Right) */
.studio-controls-bar {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    z-index: 25;
}

.studio-pill-group {
    display: flex;
    align-items: stretch;
    background: var(--bg-raised);
    border: 1px solid var(--line);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.studio-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    background: transparent;
    border: none;
    border-left: 1px solid var(--line);
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.studio-btn:first-child {
    border-left: none;
}

.studio-btn:hover {
    color: var(--ink);
    background-color: var(--bg-sunken);
}

.studio-select {
    background: transparent;
    border: none;
    padding: 6px 8px;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 10px;
    outline: none;
    cursor: pointer;
    border-right: 1px solid var(--line);
}

.studio-select:hover {
    color: var(--ink);
}

.studio-select option {
    background-color: var(--bg-raised);
    color: var(--ink);
}

/* Tooltip Flotante de Inspección */
.tree-tooltip {
    position: absolute;
    z-index: 30;
    pointer-events: none;
    background: var(--bg-raised);
    border: 1px solid var(--line);
    padding: 10px 14px;
    width: 220px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    backdrop-filter: blur(8px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.tooltip-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 6px;
}

.tt-dot {
    width: 7px;
    height: 7px;
    background-color: var(--c-healthy);
    display: inline-block;
}

.tt-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--ink-strong);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.tt-badge {
    color: var(--accent);
    font-size: 10px;
    font-weight: 700;
}

.tooltip-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.tt-row {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 11px;
}

.tt-lbl {
    color: var(--faint);
}

.tt-val {
    color: var(--ink);
    font-weight: 500;
}

.tooltip-hint {
    margin-top: 6px;
    border-top: 1px solid var(--line);
    padding-top: 4px;
    color: var(--faint);
    font-size: 9px;
    text-align: center;
}

/* ==============================================================================
   6. LEAF DRAWER (ArtCraft Studio Sidebar)
   ============================================================================== */

.leaf-drawer {
    position: fixed;
    top: 48px;
    right: 0;
    width: 440px;
    max-width: 95vw;
    height: calc(100vh - 48px);
    background-color: var(--bg-raised);
    border-left: 1px solid var(--line);
    z-index: 45;
    display: flex;
    flex-direction: column;
    box-shadow: -6px 0 24px rgba(0, 0, 0, 0.15);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.leaf-drawer.hidden {
    transform: translateX(100%);
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background-color: var(--bg);
}

.drawer-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.btn-drawer-close {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}
.btn-drawer-close:hover {
    color: var(--danger);
}

.drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 18px;
}

.action-card-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    background: var(--bg);
    cursor: pointer;
    transition: all 0.15s ease;
}
.action-card-btn:hover {
    border-color: var(--line-strong);
    background: var(--bg-sunken);
}

.terminal-box {
    background-color: var(--bg-sunken);
    border: 1px solid var(--line);
    padding: 10px 12px;
    max-height: 180px;
    overflow-y: auto;
}

.terminal-box pre {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--ink);
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.4;
}

.btn-exec-preset {
    padding: 2px 7px;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn-exec-preset:hover {
    color: var(--ink);
    border-color: var(--line-strong);
    background: var(--bg-sunken);
}

/* ==============================================================================
   7. MODALS & DIALOGS (ArtCraft Studio Cards)
   ============================================================================== */

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(10, 10, 12, 0.72);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal-card {
    position: relative;
    width: 100%;
    background-color: var(--bg-raised);
    border: 1px solid var(--line);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.btn-modal-close {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0 4px;
}
.btn-modal-close:hover {
    color: var(--danger);
}

.incidents-list-container {
    background: var(--bg-sunken);
    border: 1px solid var(--line);
    padding: 12px;
    max-height: 48vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.incident-card {
    border: 1px solid var(--line);
    background: var(--bg);
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.incident-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.incident-badge-crit {
    background: var(--danger);
    color: #fff;
    padding: 1px 6px;
    font-size: 9px;
    font-weight: 700;
}

.incident-badge-warn {
    background: var(--c-warning);
    color: #000;
    padding: 1px 6px;
    font-size: 9px;
    font-weight: 700;
}

.incident-msg {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--ink);
}

/* Storage breakdown cards */
.storage-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1px;
    background-color: var(--line);
    border: 1px solid var(--line);
    margin-top: 12px;
}

.storage-box {
    background-color: var(--bg);
    padding: 12px 14px;
}

/* ==============================================================================
   8. BUTTONS & INPUTS (Invert CTA & Ghost Formats)
   ============================================================================== */

.btn-invert-cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    font-family: var(--font-mono);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 11px;
    background-color: var(--invert-bg);
    color: var(--invert-fg);
    border: 1px solid var(--invert-bg);
    cursor: pointer;
    transition: opacity 0.15s ease;
    padding: 8px 16px;
}
.btn-invert-cta:hover {
    opacity: 0.85;
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    font-family: var(--font-mono);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 11px;
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
    cursor: pointer;
    padding: 8px 16px;
    transition: all 0.15s ease;
}
.btn-ghost:hover {
    background-color: var(--invert-bg);
    color: var(--invert-fg);
    border-color: var(--invert-bg);
}

.btn-danger-cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    font-family: var(--font-mono);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 11px;
    background-color: var(--danger);
    color: #ffffff;
    border: 1px solid var(--danger);
    cursor: pointer;
    padding: 8px 16px;
    transition: opacity 0.15s ease;
}
.btn-danger-cta:hover {
    opacity: 0.85;
}

.studio-input {
    border-radius: 0;
    border: 1px solid var(--line);
    background-color: var(--bg-sunken);
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 12px;
    padding: 8px 10px;
    outline: none;
    transition: border-color 0.15s ease;
}
.studio-input:focus {
    border-color: var(--line-strong);
}

/* ==============================================================================
   9. SCREENSAVER & TOASTS
   ============================================================================== */

.screensaver-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 40px;
    background: transparent;
    transition: opacity 1.2s ease;
}

.screensaver-overlay.hidden {
    display: none !important;
    opacity: 0 !important;
}

.screensaver-clock {
    font-size: 4rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: 2px;
    text-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.screensaver-sub {
    margin-top: 8px;
    letter-spacing: 0.15em;
}

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background-color: var(--invert-bg);
    color: var(--invert-fg);
    border: 1px solid var(--line);
    padding: 10px 16px;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.05em;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    animation: toast-in 0.2s ease;
}

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

/* ==============================================================================
   10. SCROLLBARS
   ============================================================================== */

::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--line);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--line-strong);
}
