/* ═══════════════════════════════════════════════════════════════════════════
   IMV PBX Dashboard — Styles
   RTL Arabic-first, modern clean design
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    --primary: #5b3b6d;
    --primary-dark: #4a2f5a;
    --primary-light: #f3eff5;
    --secondary: #9fcd9a;
    --secondary-light: #e8f5e6;
    --success: #059669;
    --success-light: #ecfdf5;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --warning: #d97706;
    --warning-light: #fffbeb;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --radius: 10px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --font: 'Cairo', -apple-system, BlinkMacSystemFont, sans-serif;
    --mono: 'JetBrains Mono', monospace;
}

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

body {
    font-family: var(--font);
    background: var(--gray-50);
    color: var(--gray-800);
    min-height: 100vh;
    direction: rtl;
}

/* ── NAVBAR ─────────────────────────────────────────────────────────────── */

.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    height: 60px;
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--gray-900);
}

.nav-icon { font-size: 1.4rem; }

.nav-links {
    display: flex;
    gap: 0.5rem;
}

.nav-link {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    text-decoration: none;
    color: var(--gray-600);
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s;
}
.nav-link:hover { background: var(--gray-100); color: var(--gray-800); }
.nav-link.active { background: var(--primary-light); color: var(--primary); }

.nav-logo {
    height: 36px;
    width: auto;
    object-fit: contain;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}
.user-name {
    color: var(--gray-500);
    font-size: 0.9rem;
}

/* ── CONTAINER ──────────────────────────────────────────────────────────── */

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 2rem;
}

/* ── PAGE HEADER ────────────────────────────────────────────────────────── */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
}

/* ── BUTTONS ────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline {
    background: #fff;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-400); }

.btn-danger {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid transparent;
}
.btn-danger:hover { background: #fee2e2; }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── FORMS ──────────────────────────────────────────────────────────────── */

.form-group {
    margin-bottom: 1.2rem;
}
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.35rem;
}
.form-control {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1.5px solid var(--gray-300);
    border-radius: 8px;
    font-family: var(--font);
    font-size: 0.95rem;
    color: var(--gray-800);
    background: #fff;
    transition: border-color 0.2s;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(91,59,109,0.15);
}
.form-hint {
    font-size: 0.8rem;
    color: var(--gray-400);
    margin-top: 0.3rem;
    display: block;
}
.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* ── MODAL ──────────────────────────────────────────────────────────────── */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 200;
    justify-content: center;
    align-items: center;
}
.modal-overlay.active {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s ease-out;
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
}
.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-400);
    line-height: 1;
}
.modal-close:hover { color: var(--gray-700); }

.modal-body {
    padding: 1.5rem;
}
.modal-footer {
    display: flex;
    justify-content: flex-start;
    gap: 0.8rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
    border-radius: 0 0 16px 16px;
}

/* ── JOB PANEL ──────────────────────────────────────────────────────────── */

.job-panel {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    overflow: hidden;
    border: 1px solid var(--gray-200);
}
.job-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
}
.job-status-badge {
    display: inline-block;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}
.job-status-badge.running { background: #dbeafe; color: #1d4ed8; }
.job-status-badge.completed { background: var(--success-light); color: var(--success); }
.job-status-badge.failed { background: var(--danger-light); color: var(--danger); }

.job-meta {
    color: var(--gray-500);
    font-size: 0.85rem;
    margin-right: 1rem;
}

.job-progress {
    padding: 0 1.5rem 1rem;
}
.progress-bar {
    height: 6px;
    background: var(--gray-200);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    width: 0%;
    transition: width 0.5s ease;
}
.progress-fill.animating {
    animation: progressPulse 2s ease-in-out infinite;
}
.progress-fill.done { background: var(--success); }
.progress-fill.failed { background: var(--danger); }

@keyframes progressPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.job-output {
    margin: 0;
    padding: 1rem 1.5rem;
    background: var(--gray-900);
    color: #a5f3fc;
    font-family: var(--mono);
    font-size: 0.8rem;
    line-height: 1.6;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    direction: ltr;
    text-align: left;
}

/* ── REPORTS GRID ───────────────────────────────────────────────────────── */

.reports-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1rem;
}

.report-card {
    background: #fff;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    transition: all 0.2s;
    overflow: hidden;
}
.report-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--gray-300);
}

.report-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.2rem 0;
}
.report-date {
    font-size: 0.85rem;
    color: var(--gray-500);
    font-family: var(--mono);
}
.report-month-tag {
    background: var(--secondary-light);
    color: #3a7a35;
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: var(--mono);
}

.report-card-body {
    padding: 0.6rem 1.2rem;
}
.report-filename {
    font-size: 0.85rem;
    color: var(--gray-700);
    font-family: var(--mono);
    word-break: break-all;
}
.report-size {
    font-size: 0.8rem;
    color: var(--gray-400);
    margin-top: 0.2rem;
}

.report-card-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.8rem 1.2rem;
    border-top: 1px solid var(--gray-100);
    background: var(--gray-50);
}

/* ── EMPTY STATE ────────────────────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    grid-column: 1 / -1;
}
.empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h3 { color: var(--gray-600); margin-bottom: 0.5rem; }
.empty-state p { color: var(--gray-400); }

/* ── REPORT TOOLBAR ─────────────────────────────────────────────────────── */

.report-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.8rem;
}
.toolbar-actions {
    display: flex;
    gap: 0.5rem;
}

/* ── ALERT ──────────────────────────────────────────────────────────────── */

.alert {
    padding: 0.8rem 1.2rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    font-weight: 500;
}
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid #a7f3d0; }
.alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid #fde68a; }

/* ── CARD ───────────────────────────────────────────────────────────────── */

.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
    overflow: hidden;
}

/* ── USERS TABLE ────────────────────────────────────────────────────────── */

.users-table {
    width: 100%;
    border-collapse: collapse;
}
.users-table th {
    text-align: right;
    padding: 0.8rem 1.2rem;
    background: var(--gray-50);
    color: var(--gray-600);
    font-size: 0.85rem;
    font-weight: 600;
    border-bottom: 1px solid var(--gray-200);
}
.users-table td {
    padding: 0.8rem 1.2rem;
    border-bottom: 1px solid var(--gray-100);
}
.users-table tr:last-child td { border-bottom: none; }
.users-table tr:hover { background: var(--gray-50); }
.users-table code {
    background: var(--gray-100);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 0.85rem;
    direction: ltr;
}

.role-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
}
.role-admin { background: #fef3c7; color: #92400e; }
.role-viewer { background: var(--gray-100); color: var(--gray-600); }

/* ── LOGIN ──────────────────────────────────────────────────────────────── */

.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #5b3b6d 0%, #9fcd9a 100%);
    padding: 1rem;
}

.login-card {
    background: #fff;
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    overflow: hidden;
}

.login-header {
    text-align: center;
    padding: 2.5rem 2rem 1.5rem;
}
.login-icon {
    margin-bottom: 0.8rem;
}
.login-icon img {
    height: 64px;
    width: auto;
}
.login-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 0.3rem;
}
.login-header p {
    color: var(--gray-500);
    font-size: 0.9rem;
}

.login-form {
    padding: 0 2rem 2rem;
}

/* ── RESPONSIVE ─────────────────────────────────────────────────────────── */

/* ── Stats Grid ───────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1.2rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,.4);
}
.stat-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--gray-400); font-size: 0.85rem; margin-top: 0.3rem; }

/* ── Data Table ──────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th,
.data-table td {
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
    text-align: right;
}
.data-table th {
    background: rgba(255,255,255,0.04);
    color: var(--gray-400);
    font-weight: 600;
    white-space: nowrap;
}
.data-table tr:hover td { background: rgba(91,59,109,0.06); }
.text-wrap { max-width: 300px; word-wrap: break-word; }

/* ── GLOBAL DATE FILTER ─────────────────────────────────────────── */

.nav-date-filter {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0 0.5rem;
}
.date-preset-btns {
    display: flex;
    gap: 2px;
    background: var(--gray-100);
    border-radius: 8px;
    padding: 2px;
}
.date-preset {
    padding: 4px 10px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    background: transparent;
    color: var(--gray-500);
    transition: all 0.15s;
    white-space: nowrap;
}
.date-preset:hover {
    background: var(--gray-200);
    color: var(--gray-700);
}
.date-preset.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 1px 3px rgba(91,59,109,0.3);
}
.date-custom-range {
    display: flex;
    align-items: center;
    gap: 6px;
}
.date-custom-range input[type="date"] {
    padding: 3px 8px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 12px;
    font-family: var(--font);
    color: var(--gray-700);
    width: 130px;
}
.date-custom-range span {
    color: var(--gray-400);
    font-size: 12px;
}
.date-apply-btn {
    padding: 3px 10px;
    border: none;
    border-radius: 6px;
    background: var(--secondary);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}
.date-apply-btn:hover { opacity: 0.85; }
.date-range-label {
    font-size: 11px;
    color: var(--gray-400);
    white-space: nowrap;
}

@media (max-width: 768px) {
    .navbar { padding: 0 1rem; flex-wrap: wrap; height: auto; min-height: 60px; }
    .nav-title { display: none; }
    .nav-date-filter { order: 10; width: 100%; padding: 6px 0; justify-content: center; }
    .date-preset-btns { flex-wrap: wrap; justify-content: center; }
    .date-range-label { display: none; }
    .container { padding: 1rem; }
    .reports-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .page-header { flex-direction: column; gap: 0.8rem; align-items: stretch; }
    .page-header .btn { text-align: center; }
    .report-toolbar { flex-direction: column; }
    .toolbar-actions { width: 100%; justify-content: stretch; }
    .toolbar-actions .btn { flex: 1; justify-content: center; }
}
