@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&display=swap');

:root {
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --sidebar: #111827;
    --page-bg: #f4f6fb;
    --text: #172033;
    --muted: #6b7280;
    --border: #e5e7eb;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0284c7;
    --sidebar-width: 280px;
    --sidebar-mini: 88px;
    --radius: 18px;
    --shadow: 0 12px 35px rgba(22, 32, 51, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Cairo', sans-serif;
    color: var(--text);
    background: var(--page-bg);
}

a { text-decoration: none; }

.form-control,
.form-select,
.input-group-text {
    border-color: #dfe3eb;
    border-radius: 11px;
}

.form-control:focus,
.form-select:focus {
    border-color: rgba(79, 70, 229, .55);
    box-shadow: 0 0 0 .22rem rgba(79, 70, 229, .12);
}

textarea.form-control { line-height: 1.9; resize: vertical; }

.btn {
    border-radius: 10px;
    font-weight: 700;
    padding: .65rem 1.1rem;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

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

.required-label::after { content: ' *'; color: var(--danger); }

/* Login */
.login-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at 10% 15%, rgba(79,70,229,.18), transparent 28%),
        radial-gradient(circle at 90% 85%, rgba(2,132,199,.16), transparent 28%),
        #f7f8fc;
}

.login-wrapper {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px 16px;
}

.login-card {
    width: min(100%, 500px);
    padding: 42px;
    background: rgba(255,255,255,.96);
    border-radius: 28px;
    box-shadow: 0 30px 80px rgba(31,41,55,.14);
}

.login-brand {
    display: flex;
    gap: 18px;
    align-items: center;
    margin-bottom: 34px;
}

.brand-icon,
.sidebar-logo {
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(145deg, var(--primary), #7c3aed);
}

.brand-icon {
    width: 66px;
    height: 66px;
    border-radius: 20px;
    font-size: 28px;
}

.login-brand h1 { margin: 0 0 6px; font-size: 24px; font-weight: 800; }
.login-brand p { margin: 0; color: var(--muted); font-size: 14px; }

.login-demo {
    margin-top: 25px;
    padding: 14px;
    display: flex;
    justify-content: space-between;
    border-radius: 13px;
    background: #f8fafc;
    color: #475569;
    font-size: 13px;
}

/* Admin shell */
.sidebar {
    width: var(--sidebar-width);
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    color: #fff;
    background: var(--sidebar);
    z-index: 1040;
    transition: width .25s ease, transform .25s ease;
    overflow: hidden;
}

.sidebar-brand {
    height: 86px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 24px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    white-space: nowrap;
}

.sidebar-logo {
    width: 45px;
    height: 45px;
    flex: 0 0 45px;
    border-radius: 14px;
}

.sidebar-brand-text { display: flex; flex-direction: column; }
.sidebar-brand-text span { color: #94a3b8; font-size: 12px; }

.sidebar-nav {
    flex: 1;
    padding: 24px 14px;
    overflow-y: auto;
}

.sidebar-section-label {
    padding: 0 12px 10px;
    color: #64748b;
    font-size: 11px;
    white-space: nowrap;
}

.sidebar-link {
    width: 100%;
    min-height: 48px;
    margin-bottom: 7px;
    padding: 0 15px;
    display: flex;
    align-items: center;
    gap: 14px;
    border: 0;
    border-radius: 12px;
    color: #cbd5e1;
    background: transparent;
    text-align: right;
    white-space: nowrap;
}

.sidebar-link:hover,
.sidebar-link.active {
    color: #fff;
    background: rgba(99,102,241,.16);
}

.dropdown-arrow { margin-right: auto; }

.sidebar-submenu {
    margin: 2px 26px 12px 0;
    padding-right: 14px;
    border-right: 1px solid rgba(148,163,184,.2);
}

.sidebar-submenu a {
    display: block;
    padding: 9px 10px;
    color: #94a3b8;
    border-radius: 9px;
    font-size: 13px;
}

.sidebar-submenu a:hover { color: #fff; background: rgba(255,255,255,.06); }

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid rgba(255,255,255,.08);
}

.admin-main {
    min-height: 100vh;
    margin-right: var(--sidebar-width);
    transition: margin-right .25s ease;
}

.top-navbar {
    min-height: 86px;
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    position: sticky;
    top: 0;
    z-index: 1020;
    background: rgba(244,246,251,.92);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(229,231,235,.8);
}

.navbar-start,
.navbar-end {
    display: flex;
    align-items: center;
    gap: 16px;
}

.icon-button {
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: #475569;
    background: #fff;
}

.page-heading h1 { margin: 0 0 2px; font-size: 21px; font-weight: 800; }
.page-heading p { margin: 0; color: var(--muted); font-size: 12px; }

.current-date,
.user-menu {
    display: flex;
    align-items: center;
    gap: 9px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
}

.current-date { padding: 9px 13px; color: #64748b; font-size: 13px; }

.user-menu {
    min-width: 180px;
    padding: 8px 12px;
}

.user-avatar {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    color: var(--primary);
    background: #eef2ff;
}

.user-info { flex: 1; flex-direction: column; text-align: right; }
.user-info strong { font-size: 12px; }
.user-info small { color: var(--muted); font-size: 10px; }

.content-wrapper { padding: 28px; }

.content-card {
    padding: 25px;
    border: 1px solid rgba(229,231,235,.8);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow);
}

.card-heading { margin-bottom: 24px; }

.card-heading-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.card-heading h2 { margin: 3px 0 5px; font-size: 20px; font-weight: 800; }
.card-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.eyebrow { color: var(--primary); font-size: 11px; font-weight: 800; }

/* Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0,1fr));
    gap: 20px;
}

.stat-card {
    min-height: 120px;
    padding: 21px;
    display: flex;
    align-items: center;
    gap: 17px;
    border: 1px solid rgba(229,231,235,.8);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow);
}

.stat-card span { display: block; color: var(--muted); font-size: 12px; }
.stat-card strong { font-size: 28px; font-weight: 800; }

.stat-icon {
    width: 58px;
    height: 58px;
    flex: 0 0 58px;
    display: grid;
    place-items: center;
    border-radius: 17px;
    font-size: 22px;
}

.stat-icon.primary { color: var(--primary); background: #eef2ff; }
.stat-icon.success { color: var(--success); background: #ecfdf3; }
.stat-icon.warning { color: var(--warning); background: #fff7ed; }
.stat-icon.info { color: var(--info); background: #eff6ff; }

.quick-actions { display: grid; gap: 15px; }

.quick-action-card {
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 15px;
    border: 1px solid var(--border);
    border-radius: 15px;
    color: var(--text);
}

.quick-action-card:hover { color: var(--text); box-shadow: var(--shadow); }

.quick-action-icon {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    display: grid;
    place-items: center;
    border-radius: 13px;
    color: #fff;
    background: var(--primary);
}

.quick-action-icon.alt { background: var(--info); }
.quick-action-card span:nth-child(2) { flex: 1; display: flex; flex-direction: column; }
.quick-action-card small { color: var(--muted); font-size: 11px; }

.last-record { text-align: center; }
.last-record-icon {
    width: 68px;
    height: 68px;
    margin: 0 auto 15px;
    display: grid;
    place-items: center;
    border-radius: 20px;
    color: var(--primary);
    background: #eef2ff;
    font-size: 27px;
}

/* DataTable */
.table > :not(caption) > * > * {
    padding: 15px 12px;
    border-bottom-color: #edf0f4;
    vertical-align: middle;
}

.table thead th {
    color: #64748b;
    background: #f8fafc;
    font-size: 12px;
    white-space: nowrap;
}

.table-title-cell {
    min-width: 220px;
    display: flex;
    align-items: center;
    gap: 11px;
}

.table-title-icon {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    color: var(--primary);
    background: #eef2ff;
}

.count-badge {
    min-width: 34px;
    height: 30px;
    padding: 0 9px;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    color: var(--primary);
    background: #eef2ff;
    font-weight: 800;
}

.table-actions { display: flex; gap: 6px; }

.action-button {
    width: 34px;
    height: 34px;
    display: inline-grid;
    place-items: center;
    border: 0;
    border-radius: 9px;
}

.action-button.view { color: #0369a1; background: #e0f2fe; }
.action-button.edit { color: #a16207; background: #fef3c7; }
.action-button.pdf { color: #334155; background: #e2e8f0; }
.action-button.delete { color: #b91c1c; background: #fee2e2; }

/* Forms */
.details-container { display: grid; gap: 20px; }

.detail-item {
    overflow: hidden;
    border: 1px solid #dfe3eb;
    border-radius: 16px;
    background: #fff;
}

.detail-item-header {
    min-height: 65px;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(90deg,#f8faff,#fff);
    border-bottom: 1px solid #e9edf3;
}

.detail-item-header > div { display: flex; flex-direction: column; }
.detail-number { font-size: 14px; font-weight: 800; }
.detail-item-header small { color: var(--muted); font-size: 11px; }
.detail-item-body { padding: 22px; }

.image-preview-box {
    min-height: 180px;
    padding: 10px;
    display: grid;
    place-items: center;
    border: 1px dashed #cbd5e1;
    border-radius: 14px;
    background: #f8fafc;
    position: relative;
    overflow: hidden;
}

.image-preview-box img { max-width: 100%; max-height: 260px; border-radius: 10px; }

.image-preview-placeholder {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: #94a3b8;
}

.image-preview-placeholder i { font-size: 34px; }
.image-preview-box.empty .image-preview-placeholder { display: flex; }

.image-marked-for-removal { opacity: .45; }
.image-marked-for-removal::after {
    content: 'سيتم حذف الصورة';
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #fff;
    background: rgba(185,28,28,.75);
    font-weight: 800;
}

.form-actions {
    margin-top: 28px;
    padding-top: 22px;
    display: flex;
    justify-content: flex-end;
    gap: 11px;
    border-top: 1px solid var(--border);
}

/* View */
.record-view-toolbar {
    margin-bottom: 18px;
    display: flex;
    justify-content: space-between;
    gap: 15px;
}

.record-hero {
    min-height: 230px;
    padding: 34px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    border-radius: 24px;
    color: #fff;
    background: linear-gradient(135deg,#312e81,#4f46e5 55%,#7c3aed);
    box-shadow: 0 18px 45px rgba(49,46,129,.23);
}

.record-badge {
    display: inline-flex;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 999px;
    background: rgba(255,255,255,.14);
    font-size: 12px;
}

.record-hero h2 {
    margin: 18px 0;
    font-size: clamp(25px,3vw,38px);
    font-weight: 800;
}

.record-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    color: rgba(255,255,255,.82);
    font-size: 12px;
}

.record-hero-count {
    width: 125px;
    height: 125px;
    flex: 0 0 125px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255,255,255,.24);
    border-radius: 50%;
    background: rgba(255,255,255,.11);
}

.record-hero-count strong { font-size: 35px; }

.record-details-list { margin-top: 24px; display: grid; gap: 20px; }

.record-detail-card {
    padding: 25px;
    display: grid;
    grid-template-columns: 52px minmax(0,1fr);
    gap: 20px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: #fff;
    box-shadow: var(--shadow);
}

.record-detail-number {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    color: var(--primary);
    background: #eef2ff;
    font-size: 18px;
    font-weight: 800;
}

.record-detail-card h3 { font-size: 16px; font-weight: 800; }
.record-detail-text { color: #344054; line-height: 2; }

.record-detail-image {
    margin: 22px 0 0;
    padding: 10px;
    display: inline-block;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: #f8fafc;
}

.record-detail-image img {
    max-width: min(100%,820px);
    max-height: 560px;
    border-radius: 11px;
}

.empty-state { padding: 40px; text-align: center; color: var(--muted); }

/* Collapsed */
.admin-shell.sidebar-collapsed .sidebar { width: var(--sidebar-mini); }
.admin-shell.sidebar-collapsed .admin-main { margin-right: var(--sidebar-mini); }
.admin-shell.sidebar-collapsed .sidebar-brand { padding: 0 21px; }
.admin-shell.sidebar-collapsed .sidebar-brand-text,
.admin-shell.sidebar-collapsed .sidebar-section-label,
.admin-shell.sidebar-collapsed .sidebar-link span,
.admin-shell.sidebar-collapsed .dropdown-arrow,
.admin-shell.sidebar-collapsed .sidebar-submenu { display: none; }
.admin-shell.sidebar-collapsed .sidebar-link { justify-content: center; padding: 0; }
.sidebar-overlay { display: none; }

/* Responsive */
@media (max-width: 1199.98px) {
    .dashboard-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(100%); width: min(86vw,var(--sidebar-width)); }
    .admin-main,
    .admin-shell.sidebar-collapsed .admin-main { margin-right: 0; }
    .admin-shell.sidebar-mobile-open .sidebar { transform: translateX(0); }
    .admin-shell.sidebar-mobile-open .sidebar-overlay {
        position: fixed;
        inset: 0;
        display: block;
        background: rgba(15,23,42,.48);
        z-index: 1030;
    }
    .content-wrapper { padding: 20px; }
}

@media (max-width: 767.98px) {
    .top-navbar { padding: 12px 16px; }
    .page-heading p { display: none; }
    .content-wrapper { padding: 15px; }
    .content-card { padding: 18px; border-radius: 15px; }
    .dashboard-grid { grid-template-columns: 1fr; gap: 14px; }
    .card-heading-actions,
    .record-view-toolbar { flex-direction: column; align-items: stretch; }
    .record-hero { padding: 25px 20px; flex-direction: column; align-items: flex-start; }
    .record-hero-count { width: 95px; height: 95px; flex-basis: 95px; }
    .record-detail-card { padding: 18px; grid-template-columns: 1fr; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; }
    .login-card { padding: 28px 20px; }
    .login-demo { flex-direction: column; text-align: center; }
}
