/* ==================== RESET & BASE ==================== */

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

/* ==================== CSS VARIABLES ==================== */

:root {
    /* Dark Theme (Default) */
    --bg-primary: #0a0e27;
    --bg-secondary: #131935;
    --bg-tertiary: #1a2147;
    
    --text-primary: #f8fafc;
    --text-secondary: #a0aec0;
    --text-muted: #6b7280;
    
    --accent-primary: #3b82f6;
    --accent-success: #10b981;
    --accent-danger: #ef4444;
    --accent-warning: #f59e0b;
    
    --border-color: #2d3748;
    --shadow: rgba(0, 0, 0, 0.35);
    --shadow-strong: rgba(0, 0, 0, 0.55);
    --card-highlight: rgba(255, 255, 255, 0.06);

    --font-sans: ui-sans-serif, "Avenir Next", Avenir, "SF Pro Display", "SF Pro Text",
        -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", "Helvetica Neue", Helvetica, Arial,
        sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
        monospace;

    --app-bg: radial-gradient(1200px 700px at 12% -10%, rgba(59, 130, 246, 0.25), transparent 60%),
        radial-gradient(900px 600px at 112% 0%, rgba(16, 185, 129, 0.12), transparent 55%),
        radial-gradient(700px 520px at 55% 115%, rgba(245, 158, 11, 0.09), transparent 58%),
        linear-gradient(180deg, #070b1d 0%, var(--bg-primary) 55%, #070b1d 100%);
    --app-grid: repeating-linear-gradient(
            90deg,
            rgba(255, 255, 255, 0.035) 0px,
            rgba(255, 255, 255, 0.035) 1px,
            transparent 1px,
            transparent 56px
        ),
        repeating-linear-gradient(
            0deg,
            rgba(255, 255, 255, 0.035) 0px,
            rgba(255, 255, 255, 0.035) 1px,
            transparent 1px,
            transparent 56px
        );

    --sidebar-bg: linear-gradient(180deg, rgba(19, 25, 53, 0.92) 0%, rgba(10, 14, 39, 0.92) 100%);
    --bottom-nav-bg: rgba(19, 25, 53, 0.78);
    --nav-hover-bg: rgba(255, 255, 255, 0.04);
    --nav-active-bg: linear-gradient(135deg, rgba(59, 130, 246, 0.22) 0%, rgba(59, 130, 246, 0.07) 72%);
    --nav-active-border: rgba(59, 130, 246, 0.38);
    --focus-ring: rgba(59, 130, 246, 0.38);
    
    /* Responsive */
    --container-padding: 16px;
    --card-gap: 12px;
    --font-scale: 1;
}

/* Light Theme */
[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f7fafc;
    --bg-tertiary: #edf2f7;
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --border-color: #e2e8f0;
    --shadow: rgba(15, 23, 42, 0.12);
    --shadow-strong: rgba(15, 23, 42, 0.18);
    --card-highlight: rgba(15, 23, 42, 0.04);

    --app-bg: radial-gradient(900px 640px at 18% -10%, rgba(59, 130, 246, 0.18), transparent 58%),
        radial-gradient(860px 580px at 112% 0%, rgba(16, 185, 129, 0.12), transparent 55%),
        linear-gradient(180deg, #ffffff 0%, #f4f7ff 100%);
    --app-grid: repeating-linear-gradient(
            90deg,
            rgba(15, 23, 42, 0.05) 0px,
            rgba(15, 23, 42, 0.05) 1px,
            transparent 1px,
            transparent 56px
        ),
        repeating-linear-gradient(
            0deg,
            rgba(15, 23, 42, 0.05) 0px,
            rgba(15, 23, 42, 0.05) 1px,
            transparent 1px,
            transparent 56px
        );

    --sidebar-bg: linear-gradient(180deg, rgba(247, 250, 252, 0.97) 0%, rgba(255, 255, 255, 0.94) 100%);
    --bottom-nav-bg: rgba(255, 255, 255, 0.82);
    --nav-hover-bg: rgba(15, 23, 42, 0.04);
    --nav-active-bg: linear-gradient(135deg, rgba(59, 130, 246, 0.16) 0%, rgba(59, 130, 246, 0.06) 72%);
    --nav-active-border: rgba(59, 130, 246, 0.28);
    --focus-ring: rgba(59, 130, 246, 0.3);
}

/* ── Global input / select / textarea baseline ──────────────────────────────
   Consistent look across all templates & themes. Template-level rules that
   set width, specific padding etc. remain additive — no conflicts.          */

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
input:not([type]),
select,
textarea {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    padding: 9px 12px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
}

/* Hide number spinners — clean look */
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

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

input:hover:not(:focus):not(:disabled),
select:hover:not(:focus):not(:disabled),
textarea:hover:not(:focus):not(:disabled) {
    border-color: var(--text-secondary);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

input:disabled,
select:disabled,
textarea:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Custom select chevron — dark theme */
select {
    padding-right: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    cursor: pointer;
}

/* ── Light theme overrides — bright white, clearly visible ──────────────── */

[data-theme="light"] input[type="text"],
[data-theme="light"] input[type="number"],
[data-theme="light"] input[type="email"],
[data-theme="light"] input[type="password"],
[data-theme="light"] input[type="search"],
[data-theme="light"] input[type="url"],
[data-theme="light"] input:not([type]),
[data-theme="light"] select,
[data-theme="light"] textarea {
    background: #ffffff;
    border-color: #cbd5e1;
    color: #0f172a;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

[data-theme="light"] input::placeholder,
[data-theme="light"] textarea::placeholder { color: #94a3b8; }

[data-theme="light"] input:hover:not(:focus):not(:disabled),
[data-theme="light"] select:hover:not(:focus):not(:disabled),
[data-theme="light"] textarea:hover:not(:focus):not(:disabled) {
    border-color: #94a3b8;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.1);
}

[data-theme="light"] input:focus,
[data-theme="light"] select:focus,
[data-theme="light"] textarea:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
    background: #ffffff;
}

/* Custom select chevron — light theme */
[data-theme="light"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-color: #ffffff;
}

/* Tablet */
@media (min-width: 768px) {
    :root {
        --container-padding: 24px;
        --card-gap: 16px;
        --font-scale: 1.05;
    }
}

/* Desktop */
@media (min-width: 1024px) {
    :root {
        --container-padding: 32px;
        --card-gap: 20px;
        --font-scale: 1.1;
    }
}

/* Large Desktop */
@media (min-width: 1440px) {
    :root {
        --container-padding: 40px;
        --card-gap: 24px;
        --font-scale: 1.15;
    }
}

/* ==================== BASE STYLES ==================== */

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-primary);
    background-image: var(--app-grid), var(--app-bg);
    background-repeat: repeat, no-repeat;
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

/* ==================== TYPOGRAPHY ==================== */

h1 {
    font-size: calc(24px * var(--font-scale));
    font-weight: 700;
    line-height: 1.2;
}

h2 {
    font-size: calc(20px * var(--font-scale));
    font-weight: 600;
    line-height: 1.3;
}

h3 {
    font-size: calc(18px * var(--font-scale));
    font-weight: 600;
    line-height: 1.4;
}

@media (min-width: 768px) {
    h1 {
        font-size: calc(32px * var(--font-scale));
    }
    
    h2 {
        font-size: calc(24px * var(--font-scale));
    }
}

/* ==================== LAYOUT ==================== */

.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 1000;
    transition: left 0.3s;
    box-shadow: 0 18px 60px var(--shadow);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.sidebar-header {
    padding: 18px 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-logo-mark {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    background: radial-gradient(70% 70% at 30% 20%, rgba(59, 130, 246, 0.35) 0%, transparent 60%),
        radial-gradient(90% 90% at 80% 80%, rgba(16, 185, 129, 0.18) 0%, transparent 65%),
        rgba(255, 255, 255, 0.03);
    box-shadow: 0 10px 30px var(--shadow);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.brand-logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.brand-logo--dark {
    display: block;
}

.brand-logo--light {
    display: none;
}

[data-theme="light"] .brand-logo--dark {
    display: none;
}

[data-theme="light"] .brand-logo--light {
    display: block;
}

.sidebar-logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1.05;
    min-width: 0;
}

.sidebar-logo-name {
    font-size: 16px;
    font-weight: 750;
    letter-spacing: 0.2px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-logo-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav {
    padding: 14px 10px 22px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
}

.sidebar .nav-item {
    border-radius: 12px;
    margin: 4px 8px;
    padding: 12px 14px;
}

.sidebar .nav-item:hover {
    background: var(--nav-hover-bg);
    color: var(--text-primary);
}

.sidebar .nav-item.active {
    background: var(--nav-active-bg);
    color: var(--text-primary);
    box-shadow: inset 0 0 0 1px var(--nav-active-border);
}

/* Icons (SVG sprite) */
.icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
}

.icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 240px;
    padding: var(--container-padding);
    max-width: 100%;
}

@media (prefers-reduced-motion: no-preference) {
    .main-content {
        animation: page-in 420ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
    }
}

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

/* Sidebar overlay (mobile backdrop) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 999;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile: Hide sidebar by default */
@media (max-width: 767px) {
    .sidebar {
        left: -260px;
        width: 260px;
        box-shadow: none;
    }

    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 40px rgba(0, 0, 0, 0.5);
    }

    .main-content {
        margin-left: 0;
        /* Top padding clears the fixed hamburger button (16px top + 44px btn + 8px gap) */
        padding-top: calc(var(--container-padding) + 68px);
    }
}

/* Tablet: Collapsible sidebar */
@media (min-width: 768px) and (max-width: 1023px) {
    .sidebar {
        left: -260px;
        width: 260px;
        box-shadow: none;
    }

    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 40px rgba(0, 0, 0, 0.5);
    }

    .main-content {
        margin-left: 0;
        /* Top padding clears hamburger on tablet too */
        padding-top: calc(var(--container-padding) + 68px);
    }
}

/* ==================== HEADER ==================== */

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.header-left h1 {
    margin-bottom: 4px;
}

.header-left p {
    color: var(--text-secondary);
    font-size: 14px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Search */
.search-box {
    display: flex;
    align-items: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    min-width: 300px;
}

.search-box input {
    border: none;
    background: transparent;
    color: var(--text-primary);
    outline: none;
    width: 100%;
}

@media (max-width: 767px) {
    .search-box {
        min-width: auto;
        width: 100%;
    }
}

/* Theme Toggle */
.theme-toggle {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s, box-shadow 0.2s, border-color 0.2s;
    box-shadow: 0 1px 0 var(--card-highlight), 0 12px 24px var(--shadow);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: var(--text-primary);
}

.theme-toggle:hover {
    background: var(--nav-hover-bg);
    transform: translateY(-1px);
}

/* User Menu */
.user-menu {
    position: relative;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    cursor: pointer;
}

/* ==================== CARDS ==================== */

.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 0 var(--card-highlight), 0 18px 40px var(--shadow);
    transition: all 0.3s;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 1px 0 var(--card-highlight), 0 26px 70px var(--shadow-strong);
}

/* ==================== BUTTONS ==================== */

button,
.btn {
    min-height: 44px;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    font-size: 15px;
    color: inherit;
}

button:active,
.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-secondary {
    background: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
}

.btn-success {
    background: var(--accent-success);
    color: white;
}

.btn-danger {
    background: var(--accent-danger);
    color: white;
}

/* ==================== BADGES ==================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.badge.breaking {
    background: rgba(239, 68, 68, 0.2);
    color: var(--accent-danger);
    border: 1px solid var(--accent-danger);
}

.badge.breaking::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: currentColor;
    margin-right: 8px;
}

.badge.political {
    background: rgba(245, 158, 11, 0.2);
    color: var(--accent-warning);
    border: 1px solid var(--accent-warning);
}

.badge.political::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: currentColor;
    margin-right: 8px;
}

.badge.buy {
    background: rgba(16, 185, 129, 0.2);
    color: var(--accent-success);
    border: 1px solid var(--accent-success);
}

.badge.sell {
    background: rgba(239, 68, 68, 0.2);
    color: var(--accent-danger);
    border: 1px solid var(--accent-danger);
}

/* ==================== GRID ==================== */

.grid {
    display: grid;
    gap: var(--card-gap);
    grid-template-columns: 1fr;
}

@media (min-width: 768px) {
    .grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ==================== BOTTOM NAVIGATION (removed — sidebar-only on mobile) ==================== */

/* Keep .bottom-nav hidden in case any cached page still renders it */
.bottom-nav {
    display: none !important;
}

/* ==================== UTILITIES ==================== */

.positive {
    color: var(--accent-success);
}

.negative {
    color: var(--accent-danger);
}

.no-scrollbar {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.no-scrollbar::-webkit-scrollbar {
    display: none;
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-secondary) 0%,
        var(--bg-tertiary) 50%,
        var(--bg-secondary) 100%
    );
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--accent-primary);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-link:focus {
    top: 0;
}

/* Reduce motion */
.reduce-motion * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
}

/* ==================== HAMBURGER MENU ==================== */

.hamburger {
    display: none;
    position: fixed;
    top: calc(16px + env(safe-area-inset-top));
    left: calc(16px + env(safe-area-inset-left));
    z-index: 1600;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px;
    cursor: pointer;
    box-shadow: 0 1px 0 var(--card-highlight), 0 12px 24px var(--shadow);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    transition: transform 0.2s, background 0.2s, box-shadow 0.2s;
    color: var(--text-primary);
}

.hamburger:hover {
    background: var(--nav-hover-bg);
    transform: translateY(-1px);
}

@media (max-width: 1023px) {
    .hamburger {
        display: block;
    }
}

/* ==================== MODALS ==================== */

.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 32px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
}

.app-dialog-content {
    max-width: 460px;
}

.app-dialog-title {
    margin: 0 0 12px;
    font-size: 22px;
    font-weight: 700;
}

.app-dialog-message {
    color: var(--text-secondary);
    line-height: 1.6;
}

.app-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.app-dialog-actions .btn {
    min-width: 110px;
}

/* ==================== RESPONSIVE TYPOGRAPHY ==================== */

@media (max-width: 767px) {
    body {
        font-size: calc(14px * var(--font-scale));
    }

    .app-dialog-content {
        width: calc(100% - 24px);
        padding: 20px;
    }

    .app-dialog-actions {
        justify-content: stretch;
    }

    .app-dialog-actions .btn {
        flex: 1;
        min-width: 0;
    }
}

/* ==================== TOAST NOTIFICATIONS ==================== */

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

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    max-width: 340px;
    pointer-events: auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.35);
    animation: toast-in 0.2s ease;
    border-left: 3px solid transparent;
}

.toast.toast-success {
    background: var(--bg-secondary);
    border-left-color: #10b981;
    color: var(--text-primary);
}

.toast.toast-error {
    background: var(--bg-secondary);
    border-left-color: #ef4444;
    color: var(--text-primary);
}

.toast.toast-info {
    background: var(--bg-secondary);
    border-left-color: #3b82f6;
    color: var(--text-primary);
}

.toast.toast-warning {
    background: var(--bg-secondary);
    border-left-color: #f59e0b;
    color: var(--text-primary);
}

.toast-icon {
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 1px;
}

.toast-body { flex: 1; }

.toast-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    font-size: 14px;
    flex-shrink: 0;
    line-height: 1;
}

.toast.toast-out {
    animation: toast-out 0.2s ease forwards;
}

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

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

/* Inline field error */
.field-error-msg {
    font-size: 12px;
    color: #ef4444;
    margin-top: 4px;
    display: none;
}
.field-error-msg.visible { display: block; }

@media (max-width: 767px) {
    .toast-container { bottom: calc(24px + env(safe-area-inset-bottom)); right: 12px; left: 12px; }
    .toast { max-width: 100%; }
}

/* ==================== MOBILE ENHANCEMENTS ==================== */

/* ── Sidebar close button (shown on mobile inside sidebar header) ── */
.sidebar-close {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    color: var(--text-secondary);
    margin-left: auto;
    min-height: unset;
    font-size: 13px;
}

@media (max-width: 1023px) {
    .sidebar-header {
        display: flex;
        align-items: center;
    }
    .sidebar-close {
        display: flex;
        align-items: center;
        gap: 6px;
    }
    .sidebar-close:hover {
        background: var(--nav-hover-bg);
        color: var(--text-primary);
    }
}

/* ── Body locked when sidebar open ── */
body.sidebar-open {
    overflow: hidden;
}

/* ── Hamburger: better touch target & visual ── */
@media (max-width: 1023px) {
    .hamburger {
        min-height: 44px;
        min-width: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ── Sidebar nav: larger touch targets on mobile ── */
@media (max-width: 767px) {
    .sidebar .nav-item {
        padding: 14px 14px;
        font-size: 15px;
    }

    .sidebar .icon {
        width: 22px;
        height: 22px;
        flex: 0 0 22px;
    }

    .sidebar .icon svg {
        width: 22px;
        height: 22px;
    }

    .sidebar-nav {
        padding: 10px 8px calc(30px + env(safe-area-inset-bottom));
    }
}

/* ── Cards: remove hover lift on touch devices (no hover) ── */
@media (hover: none) and (pointer: coarse) {
    .card:hover {
        transform: none;
        box-shadow: 0 1px 0 var(--card-highlight), 0 18px 40px var(--shadow);
    }
}

/* ── Tables: horizontal scroll on small screens ── */
@media (max-width: 767px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }

    /* Ensure tables inside cards don't break layout */
    .card table {
        min-width: max-content;
    }

    /* Header: stack on mobile */
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 20px;
    }

    .header-right {
        width: 100%;
        justify-content: flex-end;
    }

    /* Cards: reduce padding on mobile */
    .card {
        padding: 16px;
    }

    /* Grid utilities: all single-column on small phone */
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }
}

/* ── Smooth sidebar transition ── */
.sidebar {
    transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.28s ease;
    will-change: left;
}

/* ── Prevent content flash on initial load ── */
@media (max-width: 1023px) {
    .sidebar:not(.open) + .hamburger + .main-content,
    .sidebar:not(.open) ~ .main-content {
        /* already at margin-left: 0 — no shift needed */
    }
}
