/* ==========================================
   Portal — Ultra Modern Dashboard Styles
   ========================================== */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    /* Brand colors injected via PHP */
    --brand-primary: #2563EB;
    --brand-primary-dark: #1D4ED8;
    --brand-primary-light: #DBEAFE;
    --brand-accent: #F97316;
    --brand-gradient-from: #2563EB;
    --brand-gradient-to: #1E3A8A;

    /* Neutrals */
    --bg: #F8FAFC;
    --bg-card: #FFFFFF;
    --bg-sidebar: #0F172A;
    --bg-sidebar-hover: #1E293B;
    --bg-sidebar-active: rgba(255,255,255,0.08);
    --text: #1E293B;
    --text-secondary: #64748B;
    --text-sidebar: #CBD5E1;
    --text-sidebar-active: #FFFFFF;
    --border: #E2E8F0;
    --border-light: #F1F5F9;

    /* Status */
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --info: #3B82F6;

    /* Spacing */
    --sidebar-width: 260px;
    --header-height: 64px;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.05);

    /* Transitions */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; -webkit-font-smoothing: antialiased; }

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
}

a { color: var(--brand-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Login Screen ---- */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--brand-gradient-from) 0%, var(--brand-gradient-to) 100%);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.login-screen::before {
    content: '';
    position: absolute;
    width: 600px; height: 600px;
    border-radius: 50%;
    background: rgba(255,255,255,0.03);
    top: -200px; right: -200px;
}

.login-screen::after {
    content: '';
    position: absolute;
    width: 400px; height: 400px;
    border-radius: 50%;
    background: rgba(255,255,255,0.04);
    bottom: -100px; left: -100px;
}

.login-card {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 48px 40px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-xl), 0 0 80px rgba(0,0,0,0.15);
    position: relative;
    z-index: 1;
    animation: slideUp 0.5s var(--ease) both;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-card .brand-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-card .brand-logo img {
    height: 42px;
}

.login-card .brand-logo .brand-text {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--brand-gradient-from), var(--brand-gradient-to));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-card h2 {
    font-size: 1.5rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 8px;
    color: var(--text);
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 0.93rem;
}

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

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text);
    background: var(--bg);
    transition: all 0.2s var(--ease);
    outline: none;
}

.form-input:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(var(--brand-primary), 0.1);
    background: #fff;
}

.form-input::placeholder {
    color: #94A3B8;
}

.form-input:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px var(--brand-primary-light);
    background: #fff;
}

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748B' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

textarea.form-input {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    text-decoration: none !important;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-dark));
    color: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1.5px solid var(--border);
}
.btn-secondary:hover { background: var(--border-light); }

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover { background: #DC2626; }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
}
.btn-ghost:hover { color: var(--text); background: var(--border-light); }

.btn-sm { padding: 8px 16px; font-size: 0.82rem; }
.btn-full { width: 100%; }

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.btn .spinner {
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Dashboard Layout ---- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s var(--ease);
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-header .brand-text {
    font-size: 1.3rem;
    font-weight: 700;
    color: #fff;
}

.sidebar-header .brand-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 4px;
    background: var(--brand-primary);
    color: #fff;
    margin-top: 4px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-section-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #475569;
    padding: 16px 12px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-sidebar);
    font-size: 0.9rem;
    font-weight: 450;
    cursor: pointer;
    transition: all 0.15s var(--ease);
    margin-bottom: 2px;
    text-decoration: none !important;
}

.nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: #fff;
}

.nav-item.active {
    background: var(--bg-sidebar-active);
    color: var(--text-sidebar-active);
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    width: 3px;
    height: 24px;
    background: var(--brand-primary);
    border-radius: 0 3px 3px 0;
}

.nav-item svg {
    width: 20px; height: 20px;
    flex-shrink: 0;
    opacity: 0.7;
}
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
}

.sidebar-user .avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-accent));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.sidebar-user .user-info {
    overflow: hidden;
}

.sidebar-user .user-name {
    color: #fff;
    font-size: 0.88rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user .user-role {
    color: #64748B;
    font-size: 0.75rem;
    text-transform: capitalize;
}

/* Main content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.top-header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.top-header .page-title {
    font-size: 1.2rem;
    font-weight: 600;
}

.top-header .header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--text);
}

/* Page content */
.page-content {
    flex: 1;
    padding: 32px;
    max-width: 1400px;
    width: 100%;
}

/* ---- Cards ---- */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.card-header h3 {
    font-size: 1.05rem;
    font-weight: 600;
}

.card-body { padding: 24px; }

/* ---- Stat Cards ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s var(--ease);
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--brand-primary), var(--brand-accent));
    opacity: 0;
    transition: opacity 0.2s;
}

.stat-card:hover::after { opacity: 1; }
.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-card .stat-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius-sm);
    background: var(--brand-primary-light);
    color: var(--brand-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 4px;
    color: var(--text);
}

.stat-card .stat-label {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-weight: 500;
}

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

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

table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    background: var(--border-light);
    border-bottom: 1px solid var(--border);
}

table td {
    padding: 14px 16px;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-light);
    color: var(--text);
}

table tbody tr {
    transition: background 0.1s;
}

table tbody tr:hover {
    background: #F8FAFC;
}

/* ---- Status Badges ---- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.badge-draft { background: #F1F5F9; color: #64748B; }
.badge-submitted { background: #DBEAFE; color: #2563EB; }
.badge-reviewed { background: #FEF3C7; color: #D97706; }
.badge-approved { background: #D1FAE5; color: #059669; }
.badge-rejected { background: #FEE2E2; color: #DC2626; }
.badge-active { background: #D1FAE5; color: #059669; }
.badge-inactive { background: #FEE2E2; color: #DC2626; }
.badge-admin { background: #EDE9FE; color: #7C3AED; }
.badge-customer { background: #E0F2FE; color: #0284C7; }

/* ---- Search / Filter Bar ---- */
.filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 10px 16px 10px 40px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text);
    background: var(--bg-card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") no-repeat 14px center;
    outline: none;
    transition: all 0.2s;
}

.search-input:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px var(--brand-primary-light);
}

.filter-select {
    padding: 10px 36px 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text);
    background: var(--bg-card);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748B' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    outline: none;
    cursor: pointer;
}

/* ---- Pagination ---- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 20px 0;
}

.pagination button {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg-card);
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}

.pagination button:hover { background: var(--border-light); }

.pagination button.active {
    background: var(--brand-primary);
    color: #fff;
    border-color: var(--brand-primary);
}

.pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn { from { opacity: 0; } }

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: modalSlide 0.3s var(--ease-bounce);
}

@keyframes modalSlide {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 { font-size: 1.1rem; font-weight: 600; }

.modal-close {
    width: 32px; height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.modal-close:hover { background: var(--border-light); color: var(--text); }

.modal-body { padding: 24px; }

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ---- Toast Notifications ---- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s var(--ease-bounce);
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 380px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }
.toast-info { background: var(--info); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
}

/* ---- Empty state ---- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 64px; height: 64px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state h4 {
    font-size: 1.1rem;
    color: var(--text);
    margin-bottom: 8px;
}

/* ---- Loading ---- */
.page-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
}

.page-loader .dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--brand-primary);
    animation: dotPulse 1.2s ease-in-out infinite;
    margin: 0 4px;
}

.page-loader .dot:nth-child(2) { animation-delay: 0.2s; }
.page-loader .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* ---- Utility ---- */
.text-muted { color: var(--text-secondary); }
.text-sm { font-size: 0.82rem; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 16px; }
.hidden { display: none !important; }

.link-btn {
    background: none;
    border: none;
    color: var(--brand-primary);
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
    padding: 0;
    font-weight: 500;
}
.link-btn:hover { text-decoration: underline; }

/* ---- Password Strength ---- */
.password-strength {
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin-top: 8px;
    overflow: hidden;
}

.password-strength-bar {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s, background 0.3s;
    width: 0;
}

.password-strength-text {
    font-size: 0.75rem;
    margin-top: 4px;
    color: var(--text-secondary);
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 10px 0 30px rgba(0,0,0,0.3);
    }
    .main-content {
        margin-left: 0;
    }
    .mobile-menu-btn {
        display: flex;
    }
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 99;
    }
}

@media (max-width: 768px) {
    .page-content {
        padding: 20px 16px;
    }
    .top-header {
        padding: 0 16px;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .filter-bar {
        flex-direction: column;
    }
    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .login-card {
        padding: 32px 24px;
    }
    table {
        font-size: 0.82rem;
    }
    table th, table td {
        padding: 10px 10px;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .stat-card .stat-value {
        font-size: 1.5rem;
    }
    .modal {
        max-height: 95vh;
        border-radius: var(--radius) var(--radius) 0 0;
    }
    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }
}
