:root {
    --primary-color: #0d9488;
    /* Teal 600 */
    --primary-hover: #0f766e;
    --secondary-color: #64748b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --error-red: #ef4444;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
}

.hidden {
    display: none !important;
}

/* Auth Screens */
.screen {
    min-height: 100vh;
    display: none;
    /* Default hidden */
}

.screen.active {
    display: flex;
    /* Show when active */
}

#login-screen.active {
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
}

.login-card {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-card h1 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-size: 2rem;
}

.form-group {
    text-align: left;
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 1rem;
}

.btn-primary {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    width: 100%;
    padding: 0.75rem;
    background-color: white;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background-color: #f0fdfa;
    /* Very light teal */
    border-color: var(--primary-hover);
    color: var(--primary-hover);
}

.error-text {
    color: var(--error-red);
    font-size: 0.875rem;
    margin-top: 1rem;
}

/* Main Layout */
#main-app {
    display: flex;
}

.sidebar {
    width: 260px;
    height: 100vh;
    background: #ffffff;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
}

.sidebar-header {
    padding: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    color: var(--primary-color);
    font-size: 1.5rem;
}

.nav-links {
    list-style: none;
    padding: 1rem 0;
    flex-grow: 1;
}

.nav-links li a {
    display: flex;
    align-items: center;
    padding: 0.875rem 2rem;
    color: var(--text-main);
    text-decoration: none;
    transition: all 0.2s;
}

.nav-links li a:hover,
.nav-links li.active a {
    background-color: #f1f5f9;
    color: var(--primary-color);
}

.nav-links li a i {
    margin-right: 1rem;
    width: 20px;
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.top-bar {
    height: 64px;
    background: white;
    border-bottom: 1px solid var(--border-color);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#view-container {
    padding: 2rem;
}

/* UI Components */
.card {
    background: white;
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary-color);
}

.stat-card h3 {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.stat-card p {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.data-table th,
.data-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background-color: #f8fafc;
    font-weight: 600;
    color: var(--text-muted);
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

.table-responsive .data-table {
    min-width: 600px;
}

.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    cursor: pointer;
}

.btn-sm:hover {
    background: #e2e8f0;
}

/* Forms in Modules */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 1rem;
    width: 95%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.grid-cols-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.medical-form h4 {
    margin: 1.5rem 0 1rem 0;
    color: var(--primary-color);
    border-bottom: 2px solid #f1f5f9;
    padding-bottom: 0.5rem;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.multi-select {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.5rem;
}

.form-control {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
}

.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.bg-success {
    background: #dcfce7;
    color: #166534;
}

.bg-warning {
    background: #fef9c3;
    color: #854d0e;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    z-index: 100;
    max-height: 200px;
    overflow-y: auto;
}

.search-item {
    padding: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid #f8fafc;
}

.search-item:hover {
    background: #f1f5f9;
}

/* Mobile Nav Toggle */
.btn-icon {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--primary-color);
    cursor: pointer;
    padding: 0.5rem;
    display: none;
    /* Hidden on desktop */
}

#sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
}

/* Responsive */
@media (max-width: 768px) {
    .btn-icon {
        display: block;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 999;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .top-bar {
        padding: 0 1rem;
    }

    #view-container {
        padding: 1rem;
    }

    .grid-cols-2 {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    /* Stack card headers vertically so buttons are always visible on the left/full-width */
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .card-header button {
        width: 100% !important;
    }

    /* Modals layout for mobile keyboards */
    .modal {
        align-items: flex-start;
        padding: 0;
    }

    .modal-content {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        max-width: 100vw;
        border-radius: 0;
        padding: 1rem;
        margin: 0;
    }

    /* Tables & Calendar */
    .calendar-grid {
        min-width: auto;
        /* User prefers squished calendar without scrolling */
    }

    #calendar-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.5rem;
    }
}

/* Calendar Styling */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background-color: var(--border-color);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    overflow: hidden;
}

.calendar-day-header {
    background-color: #f8fafc;
    padding: 0.75rem;
    text-align: center;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.calendar-cell {
    background-color: white;
    min-height: 100px;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: background-color 0.2s;
}

.calendar-cell:hover:not(.empty) {
    background-color: #f1f5f9;
}

.calendar-cell.has-citas {
    background-color: #f0fdfa;
    /* Light teal tint */
}

.calendar-cell.empty {
    background-color: #f8fafc;
    cursor: default;
}

.day-number {
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.calendar-indicator {
    background-color: var(--primary-color);
    color: white;
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    text-align: center;
    margin-top: auto;
}

/* Product Search Tags */
.product-tag {
    display: inline-flex;
    align-items: center;
    background-color: #f1f5f9;
    border: 1px solid var(--border-color);
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
}

.remove-product-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-left: 0.5rem;
    cursor: pointer;
    line-height: 1;
}

.remove-product-btn:hover {
    color: var(--error-red);
}