/* ═══════════════════════════════════════
   MediFlow ERP v2.0 - Design System
   ═══════════════════════════════════════ */

:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: #1a2035;
    --bg-hover: #1e2a45;
    --bg-input: #0f1629;
    --border: #1e2d4a;
    --border-light: #283a5e;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-glow: rgba(59, 130, 246, 0.15);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --sidebar-width: 240px;
    --header-height: 60px;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --transition: 200ms ease;
    --surface-2: #141b2d;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.hidden {
    display: none !important;
}

/* ═══ SCROLLBARS ═══ */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

/* ═══ AUTH OVERLAY ═══ */
#auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    background-image: radial-gradient(circle at 20% 50%, rgba(59, 130, 246, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(16, 185, 129, 0.06) 0%, transparent 50%);
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.3);
}

.auth-icon .material-symbols-outlined {
    font-size: 28px;
    color: #fff;
}

.auth-logo h1 {
    font-size: 1.75rem;
    font-weight: 800;
    color: #fff;
}

.auth-logo h1 span {
    color: var(--accent);
}

.auth-logo p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

.auth-form h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
    color: #fff;
}

.auth-switch {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ═══ FORMS ═══ */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.7rem 0.85rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
}

/* ═══ BUTTONS ═══ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: all var(--transition);
}

.btn .material-symbols-outlined {
    font-size: 18px;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover {
    background: #059669;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

.btn-full {
    width: 100%;
    justify-content: center;
    padding: 0.75rem;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.4rem;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.btn-icon:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* ═══ SIDEBAR ═══ */
#sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    z-index: 50;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-icon .material-symbols-outlined {
    font-size: 20px;
    color: #fff;
}

.brand-name {
    font-weight: 800;
    font-size: 1.1rem;
    color: #fff;
}

#sidebar-nav {
    flex: 1;
    padding: 0.75rem;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
    text-decoration: none;
    margin-bottom: 2px;
}

.nav-item:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    text-decoration: none;
}

.nav-item.active {
    color: #fff;
    background: var(--accent);
}

.nav-item .material-symbols-outlined {
    font-size: 20px;
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

#sidebar-user .material-symbols-outlined {
    font-size: 22px;
}

/* ═══ MAIN CONTENT ═══ */
#main-content {
    margin-left: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

#app-header {
    height: var(--header-height);
    padding: 0 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
    z-index: 60;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
    z-index: 61;
}

#page-title {
    font-size: 1.15rem;
    font-weight: 700;
}

.header-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.mobile-only {
    display: none;
}

#page-container {
    flex: 1;
    overflow-y: auto;
}

.page {
    display: none;
    padding: 1.5rem;
}

.page.active {
    display: block;
}

/* ═══ CARDS ═══ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon.blue {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent);
}

.stat-icon.green {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.stat-icon.amber {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.stat-icon.red {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.stat-icon .material-symbols-outlined {
    font-size: 22px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: #fff;
    line-height: 1;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ═══ PAGE HEADER ═══ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-header h3 {
    font-size: 1rem;
    font-weight: 700;
}

/* ═══ TOOLBAR ═══ */
.toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.toolbar input,
.toolbar select {
    padding: 0.55rem 0.85rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}

.toolbar input:focus,
.toolbar select:focus {
    border-color: var(--accent);
}

.toolbar input {
    min-width: 250px;
}

/* ═══ TABLE ═══ */
.table-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrap table {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap;
}

.table-wrap th {
    text-align: left;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.table-wrap td {
    padding: 0.7rem 1rem;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: middle;
}

.table-wrap tr:last-child td {
    border-bottom: none;
}

.table-wrap tr:hover td {
    background: var(--bg-hover);
}

.table-empty {
    text-align: center;
    padding: 2.5rem 1rem !important;
    color: var(--text-muted);
    font-style: italic;
}

.text-bold {
    font-weight: 700;
    color: var(--text-primary);
}

.text-green {
    color: var(--success) !important;
}

.text-red {
    color: var(--danger) !important;
}

.text-amber {
    color: var(--warning) !important;
}

/* ═══ BADGES ═══ */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-green {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.badge-red {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.badge-amber {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.badge-blue {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent);
}

/* ═══ TOAST ═══ */
#toast-container {
    position: fixed;
    top: 1.25rem;
    right: 1.25rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow);
    animation: slideIn 300ms ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toast-success {
    background: var(--success);
}

.toast-error {
    background: var(--danger);
}

.toast-info {
    background: var(--accent);
}

.toast-warning {
    background: var(--warning);
    color: #000;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(30px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ═══ MODAL ═══ */
#modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

#modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

#modal-content h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* ═══ POS LAYOUT ═══ */
.pos-grid {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1rem;
    height: calc(100vh - var(--header-height) - 3rem);
}

.pos-left,
.pos-right {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pos-search-wrap {
    position: relative;
    margin-bottom: 1rem;
}

.pos-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 10;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    max-height: 280px;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.pos-search-item {
    padding: 0.65rem 1rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
    transition: background var(--transition);
}

.pos-search-item:hover {
    background: var(--bg-hover);
}

.pos-search-item:last-child {
    border-bottom: none;
}

.pos-cart {
    flex: 1;
    overflow-y: auto;
}

.pos-cart table {
    width: 100%;
}

.pos-summary {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.pos-summary-row {
    display: flex;
    justify-content: space-between;
    padding: 0.35rem 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.pos-summary-row.total {
    font-size: 1.1rem;
    font-weight: 800;
    color: #fff;
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
    margin-top: 0.5rem;
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 1024px) {
    #sidebar {
        transform: translateX(-100%);
        transition: transform 300ms ease;
        position: fixed;
        z-index: 100;
    }

    #sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow);
    }

    #main-content {
        margin-left: 0;
        width: 100vw;
    }

    .mobile-only {
        display: inline-flex;
    }

    .pos-grid {
        grid-template-columns: 1fr;
        height: auto;
    }
}

@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-grid,
    .pos-grid {
        display: flex;
        flex-direction: column;
    }

    .form-row,
    .form-row-3 {
        grid-template-columns: 1fr;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar input {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .toolbar button {
        width: 100%;
        justify-content: center;
    }

    /* Fix table cramping on mobile */
    .table-responsive {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: var(--radius);
        border: 1px solid var(--border);
    }

    .table-responsive table {
        min-width: 500px;
        /* Force scroll instead of squish */
        border: none;
    }

    .card {
        padding: 1rem;
    }

    #modal-content {
        padding: 1rem;
        width: 95%;
        margin: auto;
    }

    .auth-card {
        padding: 1.5rem;
        margin: 1rem;
        width: calc(100% - 2rem);
    }
}

/* ═══ SCAN INVOICE MODAL ═══ */
.scan-options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.scan-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.25rem 1rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

.scan-option:hover {
    border-color: #8b5cf6;
    background: var(--bg-hover);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.1);
    transform: translateY(-2px);
}

.scan-option-icon {
    font-size: 32px !important;
}

.scan-option-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.scan-option-hint {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.scan-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: #8b5cf6;
    border-radius: 50%;
    margin: 0 auto;
    animation: scanSpin 0.8s linear infinite;
}

@keyframes scanSpin {
    to { transform: rotate(360deg); }
}

/* ═══ PAGE HEADER MOBILE FIX ═══ */
@media (max-width: 640px) {
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .page-header > div[style*="display:flex"] {
        display: flex !important;
        flex-direction: column;
        gap: 0.5rem !important;
    }

    .page-header > div[style*="display:flex"] .btn {
        width: 100%;
        justify-content: center;
    }

    .scan-options-grid {
        grid-template-columns: 1fr 1fr;
    }

    .scan-option {
        padding: 1rem 0.5rem;
    }

    .scan-option-icon {
        font-size: 28px !important;
    }

    .scan-option-label {
        font-size: 0.78rem;
    }
}

@media (max-width: 380px) {
    .scan-options-grid {
        grid-template-columns: 1fr;
    }
}