/* Fonts loaded via HTML */

:root {
    --primary: #d4a017;
    --primary-hover: #b8860b;
    --bg-dark: #121212;
    --bg-card: #1e1e1e;
    --bg-sidebar: rgba(15, 15, 15, 0.95);
    --border: #333;
    --text: #e0e0e0;
    --text-muted: #a0a0a0;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --radius: 12px;
    --shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    --font-ui: 'Inter', sans-serif;
    --font-heading: 'Press Start 2P', cursive;
    --font-mono: 'JetBrains Mono', monospace;
}

* {
    box-sizing: border-box;
}

/* Fallbacks for Old Browsers */
.sidebar {
    background-color: #0f0f0f !important;
}

.main-content {
    background-color: #000 !important;
}

.stat-card {
    background-color: #1e1e1e !important;
}

.btn {
    background-color: #d4a017 !important;
    color: #000 !important;
}

.btn-secondary {
    background-color: #333 !important;
    color: #fff !important;
}

.nav-item.active {
    background-color: #d4a017 !important;
    color: #000 !important;
}

input,
select,
textarea {
    background-color: #252525 !important;
    color: #fff !important;
}

table th {
    background-color: #000 !important;
}

.modal {
    background-color: #181818 !important;
}

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    /* Fallback for var(--font-ui) */
    font-family: var(--font-ui);
    background: #000 url('tlo.png') no-repeat center center fixed;
    background-size: cover;
    color: #e0e0e0;
    /* Fallback for var(--text) */
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    display: flex;
}

/* Typography */
h1,
h2,
h3,
.pixel-font {
    font-family: var(--font-heading);
    text-transform: uppercase;
    letter-spacing: 1px;
    line-height: 1.4;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* --- AUTH SCREEN --- */
#login-screen {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

.login-card {
    background: rgba(20, 20, 20, 0.9);
    padding: 60px 40px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius);
    text-align: center;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 0 50px rgba(212, 160, 23, 0.1);
}

/* --- APP LAYOUT --- */
#app-container {
    display: flex;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
}

#app-container.logged-in {
    opacity: 1;
    pointer-events: all;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px;
    backdrop-filter: blur(20px);
    z-index: 100;
}

.sidebar-header {
    text-align: center;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.nav-item {
    padding: 14px 16px;
    margin-bottom: 8px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-item span {
    margin-right: 12px;
    /* Fallback for gap */
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    transform: translateX(4px);
}

.nav-item.active {
    background: var(--primary);
    color: #000;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(212, 160, 23, 0.3);
}

.sidebar-footer {
    margin-top: auto;
    font-size: 12px;
    color: #555;
    text-align: center;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

/* --- MAIN CONTENT --- */
.main-content {
    flex: 1;
    padding: 40px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.6);
    position: relative;
    backdrop-filter: blur(5px);
}

.view-section {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.view-section.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- DASHBOARD --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-top: 30px;
}

.stat-card {
    background: var(--bg-card);
    padding: 30px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, border-color 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.stat-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
}

.stat-icon {
    font-size: 24px;
    margin-bottom: 15px;
}

.stat-number {
    font-size: 36px;
    color: var(--primary);
    margin: 10px 0 20px;
    font-weight: 700;
}

.quick-actions {
    margin-top: 40px;
    padding: 24px;
    background: rgba(30, 30, 30, 0.5);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* --- UI COMPONENTS --- */
.action-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    background: var(--bg-card);
    padding: 20px 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 20px;
}

.controls-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn {
    padding: 10px 20px;
    background: var(--primary);
    color: #000;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    transition: all 0.2s;
    font-family: var(--font-ui);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(212, 160, 23, 0.3);
}

.btn:active {
    transform: translateY(0);
}

.btn-secondary {
    background: #333;
    color: #fff;
}

.btn-secondary:hover {
    background: #444;
    box-shadow: none;
}

.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid transparent;
    color: #fff;
    cursor: pointer;
    transition: 0.2s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

/* --- DATA TABLE --- */
.table-wrapper {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: auto;
    margin-bottom: 24px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 16px 24px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

th {
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

th:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
}

th.sort-asc::after {
    content: " ▲";
    color: var(--primary);
}

th.sort-desc::after {
    content: " ▼";
    color: var(--primary);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* Status Badges */
.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.status-pending {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.status-progress {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.status-ready {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-delivered {
    background: rgba(107, 114, 128, 0.2);
    color: #9ca3af;
    border: 1px solid rgba(107, 114, 128, 0.3);
}

/* --- EDITOR & JSON --- */
.split-view {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 220px);
    gap: 20px;
}

.split-view .table-wrapper {
    flex: 1;
    min-height: 0;
}

.json-panel {
    display: flex;
    flex-direction: column;
    background: #111;
    padding: 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

textarea.code-editor {
    flex: 1;
    width: 100%;
    background: #0a0a0a;
    color: #a5d6ff;
    font-family: var(--font-mono);
    border: 1px solid #333;
    border-radius: 8px;
    padding: 15px;
    font-size: 12px;
    resize: none;
    margin: 10px 0;
}

/* --- MODALS --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: #181818;
    width: 500px;
    max-width: 90%;
    border: 1px solid #444;
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    transform: scale(0.95) translateY(20px);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}

.modal-overlay.open .modal {
    transform: scale(1) translateY(0);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    max-height: 70vh;
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    color: #aaa;
    font-size: 12px;
    font-weight: 600;
}

input,
select,
textarea {
    width: 100%;
    padding: 12px 16px;
    background: #252525;
    border: 1px solid #444;
    color: #fff;
    border-radius: 8px;
    font-size: 14px;
    transition: 0.2s;
    font-family: var(--font-ui);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    background: #2a2a2a;
    outline: none;
}

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid #333;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* --- TOAST --- */
#toast-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 10000;
}

.toast {
    background: #202020;
    border-left: 4px solid var(--primary);
    padding: 16px 20px;
    min-width: 300px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #ddd;
    font-size: 14px;
    animation: slideInToast 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.success {
    border-color: var(--success);
}

.toast.error {
    border-color: var(--danger);
}

@keyframes slideInToast {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* --- MOBILE RESPONSIVENESS --- */
@media (max-width: 768px) {
    body {
        flex-direction: column;
        overflow-y: auto;
    }

    #app-container {
        flex-direction: column;
        height: auto;
        overflow: visible;
    }

    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        overflow-x: auto;
        padding: 10px;
        position: sticky;
        top: 0;
        border-right: none;
        border-bottom: 2px solid var(--border);
        justify-content: flex-start;
        gap: 10px;
        background: #000;
        /* Solid background for sticky header */
    }

    .sidebar-header,
    .sidebar-footer {
        display: none;
    }

    .nav-item {
        flex-direction: column;
        justify-content: center;
        text-align: center;
        padding: 8px 12px;
        font-size: 10px;
        min-width: 70px;
        /* ensure touch target size */
        margin-bottom: 0;
    }

    .nav-item span {
        font-size: 20px;
        /* Bigger icons */
    }

    .main-content {
        padding: 15px;
        height: auto;
        overflow: visible;
    }

    /* Adjust grid for Dashboard */
    .stats-grid {
        grid-template-columns: 1fr;
        /* Stack cards */
    }

    /* Adjust controls in views */
    .action-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .split-view {
        height: auto;
    }

    .controls-group {
        width: 100%;
        flex-wrap: wrap;
    }

    .table-wrapper {
        overflow-x: auto;
    }

    table {
        min-width: 600px;
    }

    /* Modal fixes */
    .modal {
        width: 95%;
        max-height: 90vh;
    }
}