/* ============================================================
   FormSaaS - Design System
   ============================================================ */

:root {
    --color-primary: #4f46e5;
    --color-primary-hover: #4338ca;
    --color-secondary: #6b7280;
    --color-success: #16a34a;
    --color-danger: #dc2626;
    --color-warning: #d97706;
    --color-info: #0891b2;

    --bg-body: #f4f5f7;
    --bg-surface: #ffffff;
    --bg-sidebar: #111827;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-inverse: #f9fafb;
    --border-color: #e5e7eb;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08);

    --font-family: 'Tajawal', 'Segoe UI', Tahoma, Arial, sans-serif;
    --sidebar-width: 260px;
}

[data-theme="dark"] {
    --bg-body: #0f1115;
    --bg-surface: #171a21;
    --bg-sidebar: #0b0d11;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --border-color: #262b36;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-body);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 15px;
    line-height: 1.6;
}

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

h1, h2, h3, h4 { margin: 0 0 .5em; font-weight: 700; }

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

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-inverse);
    flex-shrink: 0;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: transform .25s ease;
}

.sidebar .brand {
    font-size: 20px;
    font-weight: 800;
    color: #fff;
    padding: 8px 10px 20px;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #cbd5e1;
    padding: 11px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    font-weight: 500;
}

.sidebar nav a:hover,
.sidebar nav a.active {
    background: rgba(255,255,255,.08);
    color: #fff;
    text-decoration: none;
}

.main-content {
    flex: 1;
    min-width: 0;
    padding: 24px 28px 60px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-primary);
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        right: 0;
        z-index: 50;
        transform: translateX(100%);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: inline-block; }
    .main-content { padding: 16px; }
}

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

.stat-card { display: flex; flex-direction: column; gap: 6px; }
.stat-card .label { color: var(--text-secondary); font-size: 13px; }
.stat-card .value { font-size: 28px; font-weight: 800; }

.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .grid-4, .grid-2 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .grid-4, .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease, box-shadow .15s ease;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); text-decoration: none; }
.btn-outline { background: transparent; border-color: var(--border-color); color: var(--text-primary); }
.btn-outline:hover { background: var(--bg-body); text-decoration: none; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }

.form-control {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
}
.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
.form-hint { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--color-danger); margin-top: 4px; }

/* ---------- Alerts ---------- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid transparent;
}
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
[data-theme="dark"] .alert-error { background: #2a1414; color: #fca5a5; }
[data-theme="dark"] .alert-success { background: #10241a; color: #86efac; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 12px 14px; border-bottom: 1px solid var(--border-color); font-size: 14px; }
th { color: var(--text-secondary); font-weight: 600; font-size: 13px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-secondary { background: #e5e7eb; color: #374151; }

/* ---------- Auth Pages ---------- */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    padding: 20px;
}
.auth-card {
    background: var(--bg-surface);
    width: 100%;
    max-width: 420px;
    padding: 36px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}
.auth-card h1 { font-size: 22px; text-align: center; margin-bottom: 4px; }
.auth-card .subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 24px; font-size: 14px; }
.auth-links { text-align: center; margin-top: 16px; font-size: 14px; }

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

/* ---------- Utilities ---------- */
.text-muted { color: var(--text-secondary); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }

/* ============================================================
   PHASE 10 - UI Polish: Modal, Toast, Loading, Skeleton
   ============================================================ */

/* ---------- Modal ---------- */
.ui-modal-overlay {
    position: fixed; inset: 0; background: rgba(15,17,21,.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 10000; opacity: 0; pointer-events: none; transition: opacity .15s ease;
    padding: 16px;
}
.ui-modal-overlay.open { opacity: 1; pointer-events: auto; }
.ui-modal {
    background: var(--bg-surface); border-radius: var(--radius-lg); padding: 24px;
    max-width: 400px; width: 100%; box-shadow: var(--shadow-md);
    transform: translateY(10px); transition: transform .15s ease;
}
.ui-modal-overlay.open .ui-modal { transform: translateY(0); }
.ui-modal-title { margin: 0 0 8px; font-size: 17px; }
.ui-modal-message { margin: 0 0 20px; color: var(--text-secondary); font-size: 14px; line-height: 1.6; }
.ui-modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Toast (موحّد بدل التكرار في كل ملف JS) ---------- */
.ui-toast-container {
    position: fixed; bottom: 20px; left: 20px; z-index: 10001;
    display: flex; flex-direction: column; gap: 8px;
}
.ui-toast {
    min-width: 220px; max-width: 320px; padding: 12px 16px; border-radius: var(--radius-sm);
    font-size: 14px; box-shadow: var(--shadow-md); animation: ui-toast-in .2s ease;
}
.ui-toast-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.ui-toast-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.ui-toast-out { opacity: 0; transform: translateY(6px); transition: all .25s ease; }
@keyframes ui-toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Loading / Skeleton ---------- */
.btn.is-loading { opacity: .7; pointer-events: none; position: relative; }
.skeleton {
    background: linear-gradient(90deg, var(--bg-body) 25%, var(--border-color) 37%, var(--bg-body) 63%);
    background-size: 400% 100%; animation: ui-skeleton 1.4s ease infinite; border-radius: var(--radius-sm);
}
@keyframes ui-skeleton { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Dropdown (بسيط، يُستخدم عند الحاجة) ---------- */
.ui-dropdown { position: relative; display: inline-block; }
.ui-dropdown-menu {
    position: absolute; top: calc(100% + 4px); left: 0; background: var(--bg-surface);
    border: 1px solid var(--border-color); border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
    min-width: 160px; z-index: 50; display: none; overflow: hidden;
}
.ui-dropdown-menu.open { display: block; }
.ui-dropdown-menu a, .ui-dropdown-menu button {
    display: block; width: 100%; text-align: right; padding: 9px 14px; background: none; border: none;
    font-family: inherit; font-size: 14px; cursor: pointer; color: var(--text-primary);
}
.ui-dropdown-menu a:hover, .ui-dropdown-menu button:hover { background: var(--bg-body); text-decoration: none; }
