:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
}

.light-mode {
    --bg-dark: #f1f5f9;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.6;
}

a {
    text-decoration: none;
    color: inherit;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
/* Header */
header {
    background: var(--bg-card);
    /* was rgba(30, 41, 59, 0.8) */
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 1rem 0;
}

/* ... skipped ... */
.stat-card {
    background: var(--bg-card);
    /* was linear-gradient */
    padding: 24px;
    border-radius: 16px;
    border: 1px solid var(--border);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    margin: 10px 0 5px;
    color: var(--text-main);
}

/* ... skipped ... */
.stat-label {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.nav-wrapper {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
}

.header-start {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

nav ul {
    display: flex;
    gap: 20px;
    list-style: none;
    justify-self: center;
    /* Ensure grid item is centered */
}

/* Explicitly align grid items if needed, but grid layout usually handles the containers. 
   We need to target the nav element itself if it's the grid child.
*/
#main-nav {
    justify-self: center;
}

.nav-actions {
    justify-self: end;
}

nav a {
    color: var(--text-muted);
    font-weight: 500;
    transition: color 0.2s;
}

nav a:hover,
nav a.active {
    color: var(--primary);
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

/* Removed duplicate stat-card styles */

/* Forms */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-muted);
    font-weight: 500;
}

input,
select,
textarea {
    width: 100%;
    padding: 12px;
    background: var(--bg-card);
    /* Use variable instead of hardcoded dark color */
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 1rem;
    transition: border-color 0.2s;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    gap: 8px;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.btn-secondary:hover {
    border-color: var(--text-muted);
    color: var(--text-main);
}

/* Tables */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9rem;
}

tr:hover {
    background: var(--border);
    /* subtle highlight using border color which is lighter in dark mode, need verification */
}

.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge-stock {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.badge-lent {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

.badge-sold {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary);
}

/* Device Grid & Cards */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.device-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.device-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    border-color: var(--primary);
}

.device-header {
    padding: 15px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background: rgba(255, 255, 255, 0.02);
}

.device-model {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 4px;
}

.device-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.device-body {
    padding: 15px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.info-row:last-child {
    margin-bottom: 0;
}

.info-row .label {
    color: var(--text-muted);
}

.info-row .value {
    font-weight: 500;
}

.monospace {
    font-family: monospace;
    letter-spacing: 0.05em;
}

.device-footer {
    padding: 15px;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
}

/* QR Scanner */
#reader {
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 20px;
}

/* View Toggles (Hybrid Layout) */
.view-mobile {
    display: none;
}

.view-desktop {
    display: block;
}

/* Mobile Responsiveness */
.btn-menu {
    display: none;
    background: none;
    border: none;
    color: var(--text-main);
    cursor: pointer;
}

@media (max-width: 768px) {

    /* Hybrid View Toggle for Mobile */
    .view-desktop {
        display: none;
    }

    .view-mobile {
        display: grid;
    }

    .nav-wrapper {
        display: flex;
        /* Reset grid to flex for mobile stack */
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
    }

    .header-start {
        width: 100%;
        justify-content: space-between;
    }

    .btn-menu {
        display: block;
    }

    #main-nav,
    .nav-actions {
        display: none;
        width: 100%;
        margin-top: 15px;
    }

    #main-nav.active,
    .nav-actions.active {
        display: block;
    }

    nav ul {
        flex-direction: column;
        width: 100%;
        gap: 10px;
    }

    nav a {
        display: block;
        padding: 10px;
        background: rgba(255, 255, 255, 0.03);
        border-radius: 8px;
    }

    .nav-actions {
        margin-top: 15px;
    }

    .nav-actions .btn {
        width: 100%;
    }

    .container {
        padding: 15px;
    }

    .card {
        padding: 15px;
    }

    /* Stack form grids on mobile */
    div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }

    /* Improve tap targets */
    button,
    input,
    select,
    .btn {
        min-height: 48px;
    }

    /* Adjust headings */
    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.25rem;
    }

    /* Adjust header padding */
    header {
        padding: 0.5rem 0;
    }

    /* Inventory Controls Mobile */
    .inventory-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .inventory-controls {
        flex-direction: column-reverse;
        /* Put Search on top of Filter on Mobile? Or keep standard? Let's keep filter on top or side? 
                                     Actually, let's keep standard column but make sure they take full width */
        width: 100%;
        gap: 10px;
    }

    .toggle-wrapper,
    .search-wrapper {
        width: 100%;
        display: flex;
    }

    .toggle-wrapper button {
        width: 100%;
        /* Full width button on mobile */
        justify-content: center;
    }

    .search-wrapper input {
        flex: 1;
        /* Input takes remaining space */
    }

}

/* Default Inventory Styles (Desktop) */
.inventory-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    /* allow wrapping if really tight */
    gap: 20px;
}

.inventory-controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

.toggle-wrapper {
    display: flex;
    align-items: center;
}

.search-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.search-wrapper input {
    min-width: 250px;
    /* Wider search bar on desktop */
}