:root {
    --primary: #6366f1;
    --cantina: #ffffff;
    --primary-hover: #4f46e5;
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.1);
    --glass: blur(10px);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* {
    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);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-tap-highlight-color: transparent;
}

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

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    width: 100%;
}

/* Header & Navigation */
header {
    background: var(--bg-card);
    backdrop-filter: var(--glass);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--cantina);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 102;
    /* Ensure logo stays above overlay if needed, though usually menu covers it */
}

.logo img {
    height: 36px;
    width: auto;
    border-radius: 50%;
    border: 2px solid var(--border);
}

/* Desktop Menu */
nav ul {
    display: flex;
    gap: 0.5rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

nav a {
    color: var(--text-muted);
    transition: all 0.2s ease;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    display: block;
}

nav a:hover,
nav a.active {
    color: var(--text-main);
    background: rgba(99, 102, 241, 0.1);
}

nav a.logout-link:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
}

/* Mobile Menu Toggle */
.menu-toggle {
    display: none;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    z-index: 102;
    flex-direction: column;
    gap: 5px;
}

.menu-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background-color: var(--text-main);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.nav-header {
    display: none;
    /* Hidden on desktop */
}

.close-menu {
    display: none;
}

/* Cards */
.card {
    background: var(--bg-card);
    backdrop-filter: var(--glass);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.card-header {
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 1rem;
}

input,
select,
textarea {
    width: 100%;
    padding: 0.875rem;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-main);
    font-family: inherit;
    font-size: 1.05rem;
    transition: border-color 0.2s;
}

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

button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.875rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    min-height: 44px;
}

button:hover {
    background: var(--primary-hover);
}

button:active {
    transform: scale(0.98);
}

button.secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}

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

/* Tables */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    display: block;
    max-width: 100vw;
    /* Ensure it doesn't overflow viewport */
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

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

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

tr:last-child td {
    border-bottom: none;
}

/* Grid */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
}

/* Custom Grids */
.sales-product-grid {
    display: grid;
    grid-template-columns: 2fr 1fr auto;
    align-items: end;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.reports-filter-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    align-items: end;
}

.admin-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1.5rem;
}

/* Ensure Fiado and Products use the same responsive behavior if not already covered */
.fiado-grid,
.products-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1.5rem;
}

/* Utilities */
.text-center {
    text-align: center;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.flex {
    display: flex;
}

.gap-2 {
    gap: 0.5rem;
}

.justify-between {
    justify-content: space-between;
}

.items-center {
    align-items: center;
}

/* Login specific */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
    padding: 1rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.alert.success {
    background: rgba(34, 197, 94, 0.2);
    color: #86efac;
    border-color: rgba(34, 197, 94, 0.2);
}

/* Mobile Responsive */
@media (max-width: 768px) {

    html,
    body {
        overflow-x: hidden;
        width: 100%;
        position: relative;
    }

    .container {
        padding: 1rem;
    }

    .menu-toggle {
        display: flex;
    }

    .nav-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        z-index: 998;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }

    .nav-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    nav {
        position: fixed;
        top: 0;
        right: -100%;
        width: 80%;
        max-width: 320px;
        height: 100vh;
        background: #1e293b;
        /* Fallback */
        background: rgba(30, 41, 59, 0.95);
        backdrop-filter: blur(16px);
        z-index: 999;
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0.3s;
        border-left: 1px solid var(--border);
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.5);
        display: flex;
        flex-direction: column;
        visibility: hidden;
        /* Hide when closed */
    }

    nav.active {
        right: 0;
        visibility: visible;
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0s;
    }

    .nav-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 1.5rem;
        border-bottom: 1px solid var(--border);
    }

    .nav-header span {
        font-weight: 600;
        font-size: 1.25rem;
        color: var(--text-main);
    }

    .close-menu {
        display: block;
        background: transparent;
        border: none;
        color: var(--text-muted);
        font-size: 2rem;
        line-height: 1;
        cursor: pointer;
        padding: 0.5rem;
    }

    nav ul {
        flex-direction: column;
        gap: 0.5rem;
        padding: 1.5rem;
        overflow-y: auto;
    }

    nav li {
        width: 100%;
    }

    nav a {
        padding: 1rem;
        font-size: 1.1rem;
        border-radius: 0.75rem;
        display: flex;
        align-items: center;
    }

    nav a:active {
        background: rgba(99, 102, 241, 0.1);
    }

    /* Adjust layout for mobile */
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .card-header>div {
        width: 100%;
        display: flex;
        justify-content: space-between;
    }


    .grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    table {
        font-size: 0.875rem;
        min-width: 500px;
    }

    th,
    td {
        padding: 0.5rem;
    }

    button {
        width: 100%;
        padding: 1rem;
    }

    .card-title {
        font-size: 1.1rem;
    }

    .logo {
        font-size: 1.1rem;
    }

    .logo img {
        height: 28px;
    }

    /* Responsive layout for specific grids */
    .fiado-grid,
    .products-grid,
    .admin-grid,
    .sales-product-grid,
    .reports-filter-grid {
        grid-template-columns: 1fr !important;
    }

    .sales-product-grid>button {
        width: 100%;
    }

    .fiado-form,
    .products-form {
        order: 1;
    }

    .fiado-records,
    .products-records {
        order: 2;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0.5rem;
    }

    .card {
        padding: 0.875rem;
        max-width: 100%;
        overflow-x: hidden;
    }

    input,
    select,
    textarea {
        max-width: 100%;
    }

    table {
        font-size: 0.8rem;
        min-width: 450px;
    }

    th,
    td {
        padding: 0.4rem;
    }
}

@media print {
    .no-print {
        display: none !important;
    }

    .only-print {
        display: block !important;
    }

    header {
        display: none;
    }

    body {
        background: white;
        color: black;
    }

    .card {
        box-shadow: none;
        border: none;
        background: white;
        color: black;
    }

    table {
        color: black;
    }

    th,
    td {
        border-bottom: 1px solid #ddd;
        color: black;
    }
}