/* =========================================
   1. CONFIGURATION & VARIABLES
   ========================================= */
:root {
    /* --- CORE COLORS --- */
    --bg-app: #000000;
    --card-bg: #030303;
    --card-border: #1f1f1f;
    --glass-border: #1f1f1f;
    
    /* --- ACCENTS --- */
    --accent: #dfff00;       /* Neon Yellow */
    --accent-hover: #eaff33;
    --accent-dim: rgba(223, 255, 0, 0.05);

    /* --- SEMANTIC STATES --- */
    --text-main: #ffffff;
    --text-muted: #6E6E6E;
    --danger: #FF0017;       /* Red */
    --success: #00FF3C;      /* Green */
    --terminated: #FF5100;   /* Orange */

    /* --- DIMENSIONS --- */
    --card-width: 346px;     /* Fixed width for desktop */
    --card-radius: 30px;
    --sidebar-width: 300px;
    --sidebar-margin: 24px;
    --header-height: 60px;
    
    /* --- RADIUS --- */
    --radius-sm: 10px;
    --radius-md: 20px;
    --radius-lg: 30px;
    
    /* --- ANIMATION --- */
    --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
    
    /* --- FONTS --- */
    --font-ui: 'Space Grotesk', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

/* Z-INDEX REGISTRY
   ----------------
   0      : Background Grid
   2      : Main UI Layer
   90     : Credit Badge
   100    : Sidebar
   500    : Workspace Header
   600    : Export Menu
   9999   : Auth Overlay
   10000  : Core Loader
*/

/* =========================================
   2. GLOBAL RESET & BASE
   ========================================= */
* { box-sizing: border-box; outline: none; -webkit-tap-highlight-color: transparent; }

body {
    margin: 0;
    background: var(--bg-app);
    color: var(--text-main);
    font-family: var(--font-ui);
    height: 100vh; 
    overflow: hidden;
    user-select: none;
}

button { font-family: var(--font-ui); }
.mono { font-family: var(--font-mono); }

/* --- BACKGROUND GRID --- */
#grid-canvas {
    position: fixed; top: 0; left: 0;
    width: 100vw; height: 100vh;
    z-index: 0;
    pointer-events: none;
    opacity: 0.5;
}

/* =========================================
   3. COMPONENT: AUTH CARD SYSTEM
   ========================================= */
.overlay { 
    position: fixed; inset: 0; 
    z-index: 9999; 
    background: transparent; 
    display: flex; align-items: center; justify-content: center; 
    padding: 20px; 
    perspective: 1500px; /* Essential for 3D Tilt */
}

/* The Morphing Card */
.auth-container { 
    width: 90%; 
    max-width: var(--card-width); 
    background: var(--card-bg); 
    border: 1px solid var(--card-border); 
    border-radius: var(--card-radius); 
    display: flex; flex-direction: column;
    position: relative; 
    overflow: hidden;
    transform-style: preserve-3d;
    will-change: transform, height;
}

/* Header */
.card-header {
    display: flex; align-items: center; justify-content: space-between; 
    padding: 24px; height: 70px; flex-shrink: 0;
}

.header-left { display: flex; align-items: center; }

.card-title {
    font-size: 16px; font-weight: 600; color: #fff;
    margin: 0;
}

.nav-back-btn {
    background: none; border: none; padding: 0; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    width: 24px; height: 24px; margin-right: 12px;
    opacity: 0.6; transition: opacity 0.2s;
    overflow: hidden;
}
.nav-back-btn:hover { opacity: 1; }
.nav-back-btn.hidden { display: none; } 

/* Brand Logo */
.brand-logo svg path { transition: fill 0.3s ease; }
.brand-logo:hover svg path { fill: var(--accent); }
.brand-logo { cursor: pointer; display: block; }

/* Separator */
.card-sep {
    height: 1px; width: 100%;
    background: var(--card-border);
    flex-shrink: 0;
}

/* Body & Layout */
.card-body {
    padding: 24px;
    display: flex; flex-direction: column; 
    min-height: 100px;
}

.view-content {
    display: flex; flex-direction: column;
    gap: 20px; width: 100%;
}

.card-desc {
    font-size: 13px; color: var(--text-muted); line-height: 1.5; margin: 0;
}
.card-desc.mt-sm { margin-top: -8px; padding-left: 2px; }

/* =========================================
   4. COMPONENT: INPUTS & PILLS
   ========================================= */

/* --- INPUT FIELDS --- */
.input-group {
    display: flex; flex-direction: column; width: 100%; position: relative;
}

.field-wrapper {
    position: relative; width: 100%; height: 50px;
    background: #0A0A0A; border: 1px solid #222;
    border-radius: 12px;
    display: flex; align-items: center; padding: 0 16px;
    transition: border-color 0.2s;
}
.field-wrapper:focus-within { border-color: #444; }
.field-wrapper.locked { opacity: 0.7; pointer-events: none; background: #080808; }

.input-icon-left {
    display: flex; align-items: center; justify-content: center;
    margin-right: 12px; color: var(--text-muted);
}

.card-input {
    background: transparent; border: none; width: 100%; height: 100%;
    color: #fff; font-size: 14px; font-family: inherit;
}
.card-input::placeholder { color: #333; }
.input-value-display { color: #fff; font-size: 14px; }

/* --- PILLS (User/Status) --- */
.info-group {
    display: flex; flex-direction: column; gap: 14px; 
    margin: 0; align-items: flex-start; width: 100%;
}

.pill {
    display: inline-flex; align-items: center; gap: 10px;
    height: 34px; padding: 0 12px 0 6px;
    border-radius: 100px;
    font-size: 13px; font-weight: 300; white-space: nowrap;
}

.pill-user { background: #111; border: 1px solid #222; color: #888; }

.pill-status { background: transparent; border: 1px solid transparent; }
.pill-status.success { border-color: rgba(0, 255, 60, 0.2); background: rgba(0, 255, 60, 0.05); color: var(--success); }
.pill-status.failed { border-color: rgba(255, 0, 23, 0.2); background: rgba(255, 0, 23, 0.05); color: var(--danger); }
.pill-status.terminated { border-color: rgba(255, 81, 0, 0.3); background: rgba(255, 81, 0, 0.08); color: var(--terminated); }

/* --- ALERT PILL (Animated) --- */
.pill-alert {
    display: flex; align-items: center; gap: 10px;
    width: auto; align-self: flex-start;
    height: 0; opacity: 0; margin-top: 0; padding: 0 12px 0 8px; /* Zero State */
    overflow: hidden; 
    transform-origin: top left;
    will-change: height, margin-top, opacity;
    
    background: rgba(255, 0, 23, 0.1);
    border-radius: 100px;
    color: var(--danger); font-size: 13px; font-weight: 300;
}
.icon-alert-mini svg { display: block; width: 18px !important; height: 18px !important; }

/* --- OTP GRID --- */
.otp-grid { display: flex; gap: 8px; justify-content: center; width: 100%; }
.otp-box {
    width: 100%; max-width: 44px; aspect-ratio: 44 / 50; height: auto;
    background: #0A0A0A; border: 1px solid #222; border-radius: 10px;
    color: #fff; font-size: 20px; text-align: center;
    font-family: var(--font-mono); transition: all 0.2s; caret-color: var(--accent);
}
.otp-box:focus { border-color: #555; background: #000; }
.otp-grid.locked { opacity: 0.5; pointer-events: none; }

/* --- RATE LIMIT / LOCKOUT STATE --- */

/* Dimmed Pills (Darker than normal) */
.pill.dimmed {
    background: #111;
    border: 1px solid #1a1a1a;
    color: #444;
}

/* The Gold Lockout Button */
.btn-lockout {
    background: rgba(255, 184, 0, 0.05) !important;  /* Very faint gold bg */
    border: 1px solid rgba(255, 184, 0, 0.15) !important;
    color: #FFB800 !important; /* Gold Text */
    cursor: default;
    gap: 10px;
}

/* Remove hover effects to make it feel "Locked" */
.btn-lockout:hover {
    background: rgba(255, 184, 0, 0.05) !important;
    transform: none !important;
    color: #FFB800 !important;
}
.btn-lockout svg {
    stroke: #FFB800 !important;
    width: 18px; height: 18px;
}

/* --- RESUMING SESSION CARD --- */
.resuming-layout { display: flex; align-items: center; gap: 16px; width: 100%; }
.pill-auth-session {
    flex: 1; display: flex; align-items: center; gap: 14px;
    padding: 12px 16px; min-height: 56px;
    background: rgba(0, 255, 59, 0.06); 
    border: 1px solid rgba(0, 255, 59, 0.2); border-radius: 16px;
}
.auth-text-col { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
.auth-label { font-size: 11px; color: #00FF3B; opacity: 0.7; font-weight: 500; }
.auth-value { font-size: 13px; color: #00FF3B; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* =========================================
   5. COMPONENT: BUTTONS
   ========================================= */
.action-btn {
    width: 100%; height: 50px;
    background: #fff; color: #000;
    border: none; border-radius: 12px;
    font-size: 14px; font-weight: 500; cursor: pointer;
    transition: transform 0.1s, background 0.2s;
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.action-btn:hover { background: var(--accent); color: #000; }
.action-btn:active { transform: scale(0.98); }

.action-btn.outline { background: transparent; border: 1px solid #333; color: #fff; }
.action-btn.outline:hover { border-color: #fff; background: rgba(255,255,255,0.05); }

.action-btn.ghost { background: #111; color: #888; }
.action-btn.ghost:hover { color: #fff; background: #222; }
.action-btn.ghost.disabled { opacity: 0.5; pointer-events: none; }

.btn-row { display: flex; gap: 12px; width: 100%; }
.btn-row #btn-resend { flex: 1; min-width: 0; }
.btn-row #btn-verify { flex: 2; }

/* Spinners */
.spinner-black {
    width: 20px; height: 20px;
    border: 2px solid rgba(0,0,0,0.1); border-top-color: #000;
    border-radius: 50%; animation: spin 0.8s linear infinite;
}
.spinner-accent {
    width: 26px; height: 26px;
    border: 3px solid rgba(223, 255, 0, 0.1); border-top-color: var(--accent);
    border-radius: 50%; animation: spin 0.8s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================
   6. MAIN UI (WORKSPACE)
   ========================================= */
#main-ui { position: relative; width: 100%; height: 100%; z-index: 2; }
#viewport { position: absolute; inset: 0; background: var(--bg-app); cursor: default; touch-action: none; overflow: hidden; }
canvas { display: block; width: 100%; height: 100%; }

/* --- WORKSPACE HEADER --- */
#workspace-header {
    position: absolute; top: 24px; right: 24px;
    display: flex; align-items: center; gap: 16px;
    z-index: 500;
}

.tool-group { display: flex; align-items: center; gap: 8px; }

/* Zoom Badge */
.zoom-group {
    background: #050505; border-radius: 14px; 
    box-shadow: 0 5px 20px rgba(0,0,0,0.15); 
    border: 1px solid var(--glass-border); padding: 4px;
}
.tool-btn.icon-only {
    width: 32px; height: 32px; border-radius: 10px;
    border: none; background: transparent; color: #888;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: 16px; transition: all 0.2s;
}
.tool-btn.icon-only:hover { color: #fff; background: rgba(255,255,255,0.1); }
.tool-readout { font-family: var(--font-mono); font-size: 12px; color: #ddd; min-width: 32px; text-align: center; }

/* Export Menu */
.export-wrapper { position: relative; }
.pill-btn {
    display: flex; align-items: center; gap: 8px;
    height: 40px; padding: 0 20px;
    background: #050505; border: 1px solid var(--glass-border);
    color: #888; border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.15); 
    transition: all 0.2s var(--ease-out);
}
.pill-btn:hover { background: #1f1f1f; transform: translateY(-2px); }
.pill-btn i { font-size: 18px; }

.export-menu { 
    position: absolute; top: 50px; right: 0; width: 200px; 
    background: #050505; border: 1px solid #222; border-radius: var(--radius-md); 
    padding: 8px; display: none; flex-direction: column; gap: 4px; 
    box-shadow: 0 20px 60px rgba(0,0,0,0.8); z-index: 600; 
    transform-origin: top right; animation: scaleIn 0.2s var(--ease-out);
}
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

.menu-item { 
    background: transparent; border: none; color: #aaa; padding: 12px 16px; 
    font-size: 13px; border-radius: 8px; cursor: pointer; 
    display: flex; justify-content: space-between; align-items: center;
    transition: all 0.1s; font-family: var(--font-ui);
}
.menu-item .ext { font-family: var(--font-mono); font-size: 10px; opacity: 0.5; }
.menu-item:hover { background: #222; color: #fff; }
.menu-item.highlight { color: var(--accent); }
.menu-divider { height: 1px; background: #222; margin: 4px 0; width: 100%;}

/* =========================================
   7. SIDEBAR COMPONENT
   ========================================= */
#sidebar {
    position: absolute; top: 24px; left: var(--sidebar-margin); 
    width: var(--sidebar-width); height: auto; bottom: auto; 
    max-height: calc(100vh - 48px);
    transform: translateZ(0); 
    background: #030303; 
    backdrop-filter: blur(50px); -webkit-backdrop-filter: blur(50px);
    border: 1px solid var(--glass-border); 
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05), 0 24px 60px rgba(0,0,0,0.15);
    border-radius: var(--radius-lg); 
    display: flex; flex-direction: column; z-index: 100;
}

.sidebar-header { 
    padding: 24px 24px 18px; display: flex; justify-content: space-between; align-items: center; 
    flex-shrink: 0; border-bottom: 1px solid #222;
}

.sidebar-header .brand-logo path {
    fill: #ffffff;
    transition: fill 0.3s ease;
}

.sidebar-header .brand-logo:hover path {
    fill: var(--accent); 
}

.brand-logo { height: 32px; width: auto; }

.header-tools .icon-btn {
    width: 32px; height: 32px; border-radius: 50%; 
    background: rgba(255,255,255,0.05); border: none; color: var(--text-muted); 
    cursor: pointer; display: flex; align-items: center; justify-content: center; 
    font-size: 16px; transition: all 0.2s;
}
.header-tools .icon-btn:hover { background: #fff; color: #000; }

.sidebar-content { overflow-y: auto; padding: 24px; scrollbar-width: none; }
.sidebar-content::-webkit-scrollbar { display: none; }
.sidebar-divider { height: 1px; background: #222; width: calc(100% + 48px); margin: 24px -24px; }

/* Control Layouts */
.control-section { margin-top: 0; }
.section-label { 
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; 
    color: #666; margin-bottom: 20px; display: flex; align-items: center; gap: 8px; 
}
.control-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; min-height: 28px; }
.control-row > label { font-size: 12px; color: #bbb; font-weight: 500; width: 70px; min-width: 70px; flex-shrink: 0; }

/* Sliders & Inputs */
.slider-group { display: flex; align-items: center; gap: 12px; flex: 1; margin-left: 8px; width: 100%; }

.input-value::-webkit-outer-spin-button,
.input-value::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input-value { -moz-appearance: textfield; }

.input-value {
    width: 32px; background: transparent; border: 1px solid transparent;
    color: #666; font-family: var(--font-mono); font-size: 12px;
    padding: 4px; border-radius: 4px; text-align: right;
    transition: all 0.2s; cursor: ew-resize !important; 
}
.input-value:hover { background: #1a1a1a; border-color: #333; color: #fff; }
.input-value:focus { background: #000; border-color: #555; text-align: center; cursor: text; color: #fff; }

.input-slider { -webkit-appearance: none; width: 100%; height: 24px; background: transparent; cursor: pointer; margin: 0; }
.input-slider::-webkit-slider-runnable-track { width: 100%; height: 4px; background: #2a2a2a; border-radius: 2px; }
.input-slider::-webkit-slider-thumb {
    -webkit-appearance: none; height: 14px; width: 14px; border-radius: 50%; 
    background: #fff; margin-top: -5px; box-shadow: 0 1px 4px rgba(0,0,0,0.5); transition: transform 0.1s;
}
.input-slider:hover::-webkit-slider-thumb { transform: scale(1.2); }
.input-slider:active::-webkit-slider-thumb { background: var(--accent); }

/* Color & Toggles */
.input-color { 
    -webkit-appearance: none; appearance: none; border: 2px solid #333; width: 28px; height: 28px; 
    border-radius: 50%; overflow: hidden; padding: 0; cursor: pointer; background: none; transition: transform 0.2s; 
}
.input-color:hover { transform: scale(1.1); border-color: #fff; }
.input-color::-webkit-color-swatch-wrapper { padding: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.input-color::-webkit-color-swatch { border: none; border-radius: 50%; padding: 0; width: 100% !important; height: 100% !important; }

.toggle-wrapper { position: relative; width: 40px; height: 22px; }
.ios-toggle { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-btn { 
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; 
    background-color: #2a2a2a; transition: .3s; border-radius: 999px; border: 1px solid #333; 
}
.toggle-btn:before { 
    position: absolute; content: ""; height: 18px; width: 18px; left: 1px; bottom: 1px; 
    background-color: #888; transition: .3s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.2); 
}
.ios-toggle:checked + .toggle-btn { background-color: rgba(223, 255, 0, 0.15); border-color: var(--accent); }
.ios-toggle:checked + .toggle-btn:before { transform: translateX(18px); background-color: var(--accent); }

/* --- SIDEBAR FOOTER --- */
.sidebar-footer { 
    display: flex; flex-direction: column; gap: 16px; padding: 20px; 
    background: rgb(10, 10, 10); border-radius: var(--radius-md); 
    border: 1px solid rgba(255,255,255,0.08); font-size: 11px; color: #666; line-height: 1.5; margin-top: 8px; 
}



/* New Container for Version + Badge */
.footer-meta {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%;
}

.version-pill { 
    display: inline-flex; padding: 4px 8px; 
    background: rgba(223, 255, 0, 0.1); border: 1px solid var(--accent); 
    color: var(--accent); font-size: 10px; font-weight: 700; font-family: var(--font-mono); border-radius: 6px;
}

/* Mobile Inline Badge (Hidden by default on desktop) */
.credit-badge.mobile-inline {
    display: none; 
    position: static !important;
    background: rgb(255, 255, 255); 
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #000000;
    padding: 4px 10px 4px 4px;
    border-radius: 8px;
    font-size: 11px;
    gap: 8px;
    text-decoration: none;
    align-items: center;
    margin: 0;
    transform: none !important;
    opacity: 1 !important;
}
.credit-badge.mobile-inline:hover {
    background: rgba(255, 255, 255, 0.815);
}
.credit-badge.mobile-inline .badge-logo {
    width: 18px; height: 18px;
    background: #000;
    border-radius: 6px;
}
.credit-badge.mobile-inline .badge-logo svg {
        width: 10px; 
        height: auto;
}
/* =========================================
   8. UTILITIES & LOADERS
   ========================================= */

/* Default Credit Badge (Floating / Desktop) */
.credit-badge { 
    position: fixed; bottom: 32px; right: 32px; z-index: 90; 
    background: #ffffff; color: #000000; display: flex; align-items: center; gap: 10px;
    padding: 6px 16px 6px 6px; border-radius: 12px; text-decoration: none; 
    box-shadow: 0 5px 20px rgba(0,0,0,0.15); opacity: 1;
    transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.2s, opacity 0.3s; 
}
/* Only apply hover lift to the floating version */
.credit-badge.desktop-floating:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(0,0,0,0.7); }

.credit-badge.vanished { opacity: 0; transform: translateY(20px) scale(0.9); pointer-events: none; }

.badge-logo { width: 28px; height: 28px; background: #000; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.badge-logo svg { width: 16px; height: auto; }
.badge-text { font-size: 12px; font-weight: 800; }

/* Core Loader */
#core-loader { 
    position: fixed; inset: 0; background: #000; z-index: 10000; 
    display: flex; align-items: center; justify-content: center; 
    opacity: 1; visibility: visible; transition: none;
}
#core-loader.loaded { 
    opacity: 0; visibility: hidden; pointer-events: none; 
    transition: opacity 0.8s cubic-bezier(0.6, 0.2, 0.4, 0.8), visibility 0.8s; 
}
.loader-spinner { 
    width: 40px; height: 40px; border: 3px solid rgba(255, 255, 255, 0.1); 
    border-top-color: var(--accent); border-radius: 50%; 
    animation: spin 0.8s cubic-bezier(0.6, 0.2, 0.4, 0.8) infinite; 
}

/* =========================================
   9. RESPONSIVE DESIGN
   ========================================= */
#sheet-handle { display: none; } 

/* Tablet / Mobile Layout */
@media (max-width: 768px) {
    :root { --sidebar-width: 100%; --sidebar-margin: 0; }
    
    #workspace-header { top: 20px; left: 20px; right: 20px; justify-content: space-between; }
    .pill-btn { background: #050505 !important; }

    /* Bottom Sheet Sidebar */
    #sidebar { 
        position: fixed; top: auto; bottom: 0; left: 0; right: 0; 
        transform: translateY(calc(100% - 70px)); width: 100%; height: auto; max-height: 85vh; 
        border-radius: 32px 32px 0 0; border: 1px solid #222; border-bottom: none; 
        box-shadow: 0 -10px 60px rgba(0,0,0,0.8); 
        transition: none;
        overflow: visible;
        background: rgba(10, 10, 10, 0.85);
    }

    .sidebar-header { cursor: grab; position: relative; padding-top: 30px; }
    #sheet-handle { 
        display: block; position: absolute; top: 12px; left: 50%; transform: translateX(-50%); 
        width: 40px; height: 5px; background: #333; border-radius: 10px; transition: background 0.3s; 
    }
    .sidebar-header:active #sheet-handle { background: var(--accent); }
    
    /* --- BADGE LOGIC UPDATE --- */
    
    /* 1. Hide the old floating badge completely on mobile */
    .credit-badge.desktop-floating { 
        display: none !important; 
    }

    /* 2. Style the new inline badge (inside the footer) */
    .credit-badge.mobile-inline {
        display: flex; /* Activate it */
        background: rgb(255, 255, 255); 
        color: #000000;
        padding: 4px 10px 4px 4px;
        border-radius: 8px;
        font-size: 11px;
        gap: 8px;
        text-decoration: none;
    }
    
    .credit-badge.mobile-inline .badge-logo {
        width: 20px; height: 20px;
        background: #000;
        border-radius: 4px;
    }
    
    /* Ensure the footer row is spaced correctly */
    .footer-meta {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
    }

    .mobile-only-divider {
        display: block;
        height: 1px;
        border: 1px solid rgba(255,255,255,0.08);
        width: calc(100% + 48px); /* Stretch full width */
        margin: 0 -24px 24px -24px; /* Pull to edges and push footer down */
    }
}

/* Small Phone Optimization (Logic Update) */
@media (max-width: 380px) {
    /* Instead of breaking the card, we just scale the whole container */
    .auth-container {
        transform: scale(0.95);
        transform-origin: center center;
    }
    
    .otp-box { width: 40px; height: 46px; font-size: 18px; }
}
