/* ============================================
   Al-Hall Business Management System - Demo
   ============================================ */

:root {
    --primary: #1e40af;
    --primary-light: #3b82f6;
    --primary-dark: #1e3a8a;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --purple: #a855f7;
    --pink: #ec4899;

    --bg: #f8fafc;
    --bg-card: #ffffff;
    --bg-darker: #f1f5f9;
    --bg-darkest: #e2e8f0;

    --text: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;

    --border: #e2e8f0;
    --border-dark: #cbd5e1;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 4px 6px rgba(0,0,0,0.07);
    --shadow-md: 0 10px 15px rgba(0,0,0,0.1);
    --shadow-lg: 0 20px 25px rgba(0,0,0,0.1);

    --radius-sm: 6px;
    --radius: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;

    --gradient-primary: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    --gradient-success: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    --gradient-warm: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
    --gradient-purple: linear-gradient(135deg, #a855f7 0%, #ec4899 100%);
}

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

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

/* Login Screen */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 50%, #06b6d4 100%);
}

.login-card {
    background: white;
    padding: 40px 32px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
}

.login-card h1 {
    text-align: center;
    color: var(--primary);
    font-size: 1.6rem;
    margin-bottom: 4px;
}

.login-card .login-logo { margin-bottom: 16px; }

.login-card code {
    background: var(--bg-darker);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--primary);
}

/* Form elements */
.form-group {
    margin-bottom: 16px;
}

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: 'Cairo', sans-serif;
    transition: all 0.2s;
    background: var(--bg-card);
    color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

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

.form-row-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

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

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-family: 'Cairo', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

.btn-success { background: var(--gradient-success); color: white; }
.btn-warning { background: var(--gradient-warm); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-info { background: var(--info); color: white; }
.btn-purple { background: var(--gradient-purple); color: white; }

.btn-secondary {
    background: var(--bg-darker);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-darkest); }

.btn-block { width: 100%; justify-content: center; padding: 13px; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-icon { padding: 8px; min-width: 36px; justify-content: center; }

/* App Shell */
.app-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    grid-template-rows: 64px 1fr;
    grid-template-areas: "topbar topbar" "sidebar main";
    min-height: 100vh;
}

.app-shell.hidden { display: none; }

/* Topbar */
.topbar {
    grid-area: topbar;
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    z-index: 100;
    position: sticky;
    top: 0;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.topbar-title { font-weight: 700; font-size: 1.05rem; color: var(--text); }
.topbar-sub { font-size: 0.8rem; color: var(--text-muted); }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: var(--bg-darker);
    color: var(--text);
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}
.icon-btn:hover { background: var(--bg-darkest); }

.badge {
    position: absolute;
    top: -4px;
    left: -4px;
    background: var(--danger);
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 18px;
    text-align: center;
}

.user-menu { position: relative; }

.user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg-darker);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-family: 'Cairo', sans-serif;
    color: var(--text);
    font-weight: 600;
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s;
    z-index: 1000;
}

.user-dropdown.open { opacity: 1; visibility: visible; transform: translateY(0); }

.user-dropdown a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--text);
    text-decoration: none;
    transition: background 0.2s;
}
.user-dropdown a:hover { background: var(--bg-darker); }

.menu-toggle {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: var(--bg-darker);
    cursor: pointer;
    color: var(--text);
}

/* Sidebar */
.sidebar {
    grid-area: sidebar;
    background: white;
    border-left: 1px solid var(--border);
    padding: 16px 12px;
    overflow-y: auto;
    height: calc(100vh - 64px);
    position: sticky;
    top: 64px;
}

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius);
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s;
    cursor: pointer;
    font-weight: 500;
}

.nav-item i { width: 20px; text-align: center; }

.nav-item:hover {
    background: var(--bg-darker);
    color: var(--primary);
}

.nav-item.active {
    background: var(--gradient-primary);
    color: white;
    box-shadow: var(--shadow);
}

.nav-divider {
    margin: 12px 0 6px;
    padding: 0 14px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-light);
    text-transform: uppercase;
}

/* Main Content */
.main-content {
    grid-area: main;
    padding: 24px;
    overflow-x: hidden;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.page-title {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text);
}

.page-title small {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-top: 4px;
}

.toolbar {
    background: white;
    padding: 14px 18px;
    border-radius: var(--radius);
    margin-bottom: 18px;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
}

.search-box {
    flex: 1;
    min-width: 200px;
    position: relative;
}

.search-box i {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
}

.search-box input {
    width: 100%;
    padding: 10px 40px 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    font-family: 'Cairo', sans-serif;
    font-size: 0.95rem;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Cards */
.card {
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 18px;
}

.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-darker);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.card-body { padding: 18px; }

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    padding: 18px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 14px;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 80px;
    height: 80px;
    background: var(--gradient-primary);
    opacity: 0.08;
    border-radius: 50%;
    transform: translate(30%, -30%);
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-card.success::before { background: var(--gradient-success); }
.stat-card.warning::before { background: var(--gradient-warm); }
.stat-card.danger::before { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.stat-card.info::before { background: linear-gradient(135deg, #06b6d4, #0891b2); }
.stat-card.purple::before { background: var(--gradient-purple); }

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: var(--gradient-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-card.success .stat-icon { background: var(--gradient-success); }
.stat-card.warning .stat-icon { background: var(--gradient-warm); }
.stat-card.danger .stat-icon { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.stat-card.info .stat-icon { background: linear-gradient(135deg, #06b6d4, #0891b2); }
.stat-card.purple .stat-icon { background: var(--gradient-purple); }

.stat-value {
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1;
    color: var(--text);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Data Table */
.data-table {
    background: white;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}

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

.data-table th {
    background: var(--bg-darker);
    padding: 12px 14px;
    text-align: right;
    font-weight: 700;
    color: var(--text);
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
}

.data-table tr:hover td { background: var(--bg-darker); }

/* Status Badges */
.status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 700;
}

.status.active { background: #dcfce7; color: #16a34a; }
.status.pending { background: #fef3c7; color: #b45309; }
.status.closed { background: #e2e8f0; color: #475569; }
.status.won { background: #dcfce7; color: #16a34a; }
.status.lost { background: #fee2e2; color: #dc2626; }
.status.paid { background: #dcfce7; color: #16a34a; }
status.sent { background: #dbeafe; color: #1e40af; }
.status.draft { background: #e2e8f0; color: #475569; }
.status.partial { background: #fef3c7; color: #b45309; }
.status.overdue { background: #fee2e2; color: #dc2626; }
.status.cancelled { background: #f3f4f6; color: #6b7280; }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.hidden { display: none; }

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: white;
    border-radius: var(--radius-md);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalSlide 0.3s ease;
}

@keyframes modalSlide {
    from { transform: translateY(-30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-lg { max-width: 900px; }
.modal-sm { max-width: 400px; }

.modal-header {
    padding: 18px 22px;
    background: var(--gradient-primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.modal-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
}

.modal-body {
    padding: 22px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    background: var(--bg-darker);
}

/* Toast */
#toastContainer {
    position: fixed;
    top: 80px;
    left: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: white;
    padding: 12px 18px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    border-right: 4px solid var(--primary);
    animation: toastSlide 0.3s ease;
    min-width: 280px;
    font-weight: 600;
}

.toast.success { border-color: var(--success); color: #16a34a; }
.toast.warning { border-color: var(--warning); color: #b45309; }
.toast.error { border-color: var(--danger); color: #dc2626; }

@keyframes toastSlide {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

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

.empty-state i { font-size: 3rem; opacity: 0.3; margin-bottom: 14px; }

.empty-state h3 { color: var(--text); margin-bottom: 6px; }

/* Detail Grid */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.detail-item {
    background: var(--bg-darker);
    padding: 12px 14px;
    border-radius: var(--radius);
    border-right: 3px solid var(--primary);
}

.detail-item .lbl {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.detail-item .val {
    font-weight: 700;
    color: var(--text);
    font-size: 1rem;
}

/* Grid 2 col */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 18px;
}

@media (max-width: 968px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .app-shell { grid-template-columns: 1fr; grid-template-areas: "topbar" "main"; }
    .sidebar { position: fixed; right: -260px; top: 64px; height: calc(100vh - 64px); z-index: 99; transition: right 0.3s; width: 260px; }
    .sidebar.open { right: 0; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

/* Chart container */
.chart-container {
    background: white;
    padding: 18px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    height: 320px;
}

/* Utility */
.text-gold { color: var(--primary); }
.mb-1 { margin-bottom: 10px; }
.mt-1 { margin-top: 10px; }
.mt-2 { margin-top: 20px; }
.hidden { display: none !important; }
.text-center { text-align: center; }
.flex { display: flex; }
.gap-1 { gap: 10px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* Welcome banner */
.welcome-banner {
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    color: white;
    padding: 24px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
}

.welcome-banner::before {
    content: '🏢';
    position: absolute;
    top: 10px;
    left: 20px;
    font-size: 5rem;
    opacity: 0.15;
}

.welcome-banner h2 { font-size: 1.6rem; margin-bottom: 8px; }
.welcome-banner p { opacity: 0.9; }

/* Quick actions */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.quick-action {
    background: white;
    padding: 20px;
    border-radius: var(--radius-md);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    border: 1.5px solid var(--border);
}

.quick-action:hover {
    transform: translateY(-3px);
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.quick-action i {
    font-size: 2rem;
    color: var(--primary);
    margin-bottom: 10px;
}

.quick-action h4 {
    font-size: 0.95rem;
    margin-bottom: 4px;
    color: var(--text);
}

.quick-action small {
    font-size: 0.78rem;
    color: var(--text-muted);
}