/*
 * نظام أرشفة الخطابات - ليسن فالي
 * ملف التصميم الرئيسي
 * الألوان: أخضر داكن #023A38 | ذهبي #AA986A | كريمي #F8F5EE
 * الخطوط: Noto Naskh Arabic (عناوين) | Noto Sans Arabic (محتوى) | Cairo (أرقام)
 */

/* ─── متغيرات الألوان ─────────────────────────────────────────────────── */
:root {
    --green-dark:    #023A38;
    --green-mid:     #04503E;
    --green-light:   #0A6B54;
    --gold:          #AA986A;
    --gold-light:    #C4B07E;
    --gold-dark:     #8A7A50;
    --cream:         #F8F5EE;
    --cream-dark:    #EDE9DF;
    --white:         #FFFFFF;
    --text-dark:     #1A2428;
    --text-mid:      #3D4F55;
    --text-light:    #6B7C82;
    --border:        rgba(2, 58, 56, 0.12);
    --shadow-sm:     0 1px 3px rgba(2,58,56,0.08), 0 2px 8px rgba(2,58,56,0.04);
    --shadow-md:     0 4px 16px rgba(2,58,56,0.10), 0 2px 6px rgba(2,58,56,0.06);
    --shadow-lg:     0 8px 32px rgba(2,58,56,0.14), 0 4px 12px rgba(2,58,56,0.08);
    --radius:        10px;
    --radius-sm:     6px;
    --radius-lg:     16px;
    --sidebar-w:     260px;
    --topbar-h:      64px;
    --font-heading:  'Noto Naskh Arabic', serif;
    --font-body:     'Noto Sans Arabic', sans-serif;
    --font-num:      'Cairo', sans-serif;
}

/* ─── Reset & Base ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
    font-family: var(--font-body);
    background: var(--cream);
    color: var(--text-dark);
    direction: rtl;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }

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

/* ─── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #023A38 0%, #02312F 100%);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0; right: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.3s ease;
}
.sidebar::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url('../img/laysen-sidebar-pattern.png');
    background-size: cover;
    opacity: 0.06;
    pointer-events: none;
}

.sidebar-header {
    padding: 28px 20px 20px;
    position: relative;
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}
.logo-diamond svg { width: 42px; height: 42px; }
.logo-text { display: flex; flex-direction: column; }
.logo-ar {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--white);
    line-height: 1.2;
}
.logo-en {
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--gold);
    letter-spacing: 2px;
    text-transform: uppercase;
}
.sidebar-subtitle {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.45);
    padding-right: 4px;
    font-family: var(--font-body);
}

.sidebar-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    opacity: 0.3;
    margin: 4px 16px;
}

.sidebar-nav {
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.65);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    position: relative;
}
.nav-item:hover {
    background: rgba(255,255,255,0.08);
    color: var(--white);
}
.nav-item.active {
    background: rgba(170,152,106,0.18);
    color: var(--gold-light);
    font-weight: 600;
}
.nav-item.active::before {
    content: '';
    position: absolute;
    right: 0; top: 20%; bottom: 20%;
    width: 3px;
    background: var(--gold);
    border-radius: 2px 0 0 2px;
}
.nav-icon {
    width: 18px; height: 18px;
    flex-shrink: 0;
    opacity: 0.8;
}
.nav-item.active .nav-icon { opacity: 1; }

.sidebar-footer {
    margin-top: auto;
    padding: 16px 20px;
    font-size: 0.7rem;
    color: rgba(255,255,255,0.25);
    text-align: center;
}

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

/* ─── Topbar ──────────────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 1px 0 var(--border);
}
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-left  { display: flex; align-items: center; gap: 10px; }
.topbar-title h1 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--green-dark);
    line-height: 1.2;
}
.topbar-subtitle {
    display: block;
    font-size: 0.72rem;
    color: var(--text-light);
    margin-top: 1px;
}
.sidebar-toggle {
    display: none;
    padding: 8px;
    border-radius: var(--radius-sm);
    color: var(--green-dark);
    transition: background 0.2s;
}
.sidebar-toggle:hover { background: rgba(2,58,56,0.08); }

/* ─── Page Body ───────────────────────────────────────────────────────── */
.page-body { padding: 28px; flex: 1; }

/* ─── Buttons ─────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    font-family: var(--font-body);
    transition: all 0.2s;
    cursor: pointer;
    border: none;
    text-decoration: none;
}
.btn-sm { padding: 7px 14px; font-size: 0.8rem; }
.btn-lg { padding: 13px 28px; font-size: 0.95rem; }
.btn-primary {
    background: linear-gradient(135deg, var(--green-dark) 0%, var(--green-mid) 100%);
    color: var(--white);
    box-shadow: 0 2px 8px rgba(2,58,56,0.25);
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(2,58,56,0.3); }
.btn-primary:active { transform: translateY(0); }
.btn-secondary {
    background: var(--cream-dark);
    color: var(--green-dark);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--cream); border-color: var(--green-dark); }
.btn-danger {
    background: #FEF2F2;
    color: #DC2626;
    border: 1px solid #FECACA;
}
.btn-danger:hover { background: #DC2626; color: var(--white); }
.btn-gold {
    background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
    color: var(--white);
}
.btn-gold:hover { opacity: 0.9; }
.btn-outline {
    background: transparent;
    color: var(--green-dark);
    border: 1.5px solid rgba(2,58,56,0.2);
}
.btn-outline:hover { background: rgba(2,58,56,0.05); border-color: var(--green-dark); }

/* ─── Stats Grid ──────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 18px 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid transparent;
    transition: all 0.2s;
    text-decoration: none;
    display: block;
}
.stat-card:hover {
    box-shadow: var(--shadow-md);
    border-color: rgba(170,152,106,0.2);
    transform: translateY(-2px);
}
.stat-icon {
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 12px;
    font-size: 1.1rem;
}
.stat-value {
    font-family: var(--font-num);
    font-size: 1.8rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 4px;
}
.stat-label {
    font-size: 0.75rem;
    color: var(--text-light);
    line-height: 1.3;
}

/* ─── Letters Table ───────────────────────────────────────────────────── */
.table-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}
.table-card-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.table-card-title {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 700;
    color: var(--green-dark);
}
.table-wrapper { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
thead th {
    background: var(--cream);
    color: var(--text-mid);
    font-weight: 600;
    font-size: 0.78rem;
    padding: 11px 16px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody tr {
    border-bottom: 1px solid rgba(2,58,56,0.05);
    transition: background 0.15s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(248,245,238,0.8); }
tbody td {
    padding: 13px 16px;
    vertical-align: middle;
    color: var(--text-dark);
}
.td-number {
    font-family: monospace;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--green-dark);
    background: rgba(2,58,56,0.06);
    padding: 3px 8px;
    border-radius: 4px;
    white-space: nowrap;
}
.td-subject {
    font-weight: 500;
    max-width: 280px;
}
.td-subject a { color: var(--text-dark); transition: color 0.15s; }
.td-subject a:hover { color: var(--green-dark); }
.td-date { color: var(--text-light); font-size: 0.8rem; white-space: nowrap; }
.td-actions { display: flex; gap: 6px; align-items: center; }

/* ─── Badges ──────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    font-family: var(--font-body);
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.badge-warning  { background: #FEF3C7; color: #92400E; border: 1px solid #FDE68A; }
.badge-success  { background: #D1FAE5; color: #065F46; border: 1px solid #A7F3D0; }
.badge-info     { background: #DBEAFE; color: #1E40AF; border: 1px solid #BFDBFE; }
.badge-default  { background: #F3F4F6; color: #4B5563; border: 1px solid #E5E7EB; }
.badge-outgoing { background: rgba(2,58,56,0.08); color: var(--green-dark); border: 1px solid rgba(2,58,56,0.15); }
.badge-incoming { background: rgba(170,152,106,0.12); color: var(--gold-dark); border: 1px solid rgba(170,152,106,0.25); }

/* ─── Search & Filter Bar ─────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.search-box {
    position: relative;
    flex: 1;
    min-width: 200px;
    max-width: 320px;
}
.search-box input {
    width: 100%;
    padding: 8px 38px 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--cream);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    color: var(--text-dark);
}
.search-box input:focus {
    border-color: var(--green-dark);
    box-shadow: 0 0 0 3px rgba(2,58,56,0.08);
}
.search-icon {
    position: absolute;
    right: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    pointer-events: none;
}
.filter-select {
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--cream);
    font-size: 0.85rem;
    color: var(--text-dark);
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
    font-family: var(--font-body);
}
.filter-select:focus { border-color: var(--green-dark); }

/* ─── Forms ───────────────────────────────────────────────────────────── */
.form-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
    max-width: 760px;
}
.form-card-header {
    background: linear-gradient(135deg, var(--green-dark) 0%, var(--green-mid) 100%);
    padding: 22px 28px;
    position: relative;
    overflow: hidden;
}
.form-card-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url('../img/laysen-sidebar-pattern.png');
    background-size: cover;
    opacity: 0.07;
}
.form-card-header h2 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--white);
    position: relative;
}
.form-card-header p {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.6);
    margin-top: 4px;
    position: relative;
}
.form-card-body { padding: 28px; }
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
.form-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-mid);
}
.form-label .required { color: #DC2626; margin-right: 2px; }
.form-control {
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--cream);
    font-size: 0.875rem;
    color: var(--text-dark);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: var(--font-body);
    width: 100%;
}
.form-control:focus {
    border-color: var(--green-dark);
    box-shadow: 0 0 0 3px rgba(2,58,56,0.08);
    background: var(--white);
}
.form-control.error { border-color: #DC2626; }
textarea.form-control { resize: vertical; min-height: 90px; }
.form-actions {
    display: flex;
    gap: 10px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    margin-top: 24px;
}
.form-error { color: #DC2626; font-size: 0.75rem; margin-top: 3px; }

/* ─── Detail View ─────────────────────────────────────────────────────── */
.detail-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    overflow: hidden;
    max-width: 760px;
}
.detail-header {
    background: linear-gradient(135deg, var(--green-dark) 0%, var(--green-mid) 100%);
    padding: 28px;
    position: relative;
    overflow: hidden;
}
.detail-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url('../img/laysen-sidebar-pattern.png');
    background-size: cover;
    opacity: 0.07;
}
.detail-header-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    position: relative;
    flex-wrap: wrap;
}
.detail-number {
    font-family: monospace;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--gold);
    background: rgba(255,255,255,0.1);
    padding: 4px 10px;
    border-radius: 4px;
}
.detail-title {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--white);
    line-height: 1.4;
    position: relative;
}
.detail-body { padding: 28px; }
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}
.detail-field label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-light);
    display: block;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.detail-field p {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-dark);
}
.detail-description {
    background: var(--cream);
    border: 1px solid rgba(170,152,106,0.15);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 24px;
}
.detail-description label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-light);
    display: block;
    margin-bottom: 8px;
}
.detail-description p {
    font-size: 0.875rem;
    color: var(--text-mid);
    line-height: 1.7;
}
.detail-actions {
    display: flex;
    gap: 10px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

/* ─── Flash Messages ──────────────────────────────────────────────────── */
.flash-message {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 0.875rem;
    font-weight: 500;
    animation: slideDown 0.3s ease;
}
.flash-icon { font-size: 1rem; font-weight: 700; }
.flash-success { background: #D1FAE5; color: #065F46; border: 1px solid #A7F3D0; }
.flash-error   { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.flash-info    { background: #DBEAFE; color: #1E40AF; border: 1px solid #BFDBFE; }

/* ─── Empty State ─────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}
.empty-state-icon {
    width: 64px; height: 64px;
    background: rgba(2,58,56,0.07);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px;
    font-size: 1.6rem;
}
.empty-state h3 {
    font-family: var(--font-heading);
    font-size: 1.05rem;
    color: var(--text-mid);
    margin-bottom: 6px;
}
.empty-state p { font-size: 0.85rem; }

/* ─── Pagination ──────────────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 16px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}
.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px; height: 34px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-mid);
    border: 1px solid var(--border);
    background: var(--white);
    transition: all 0.15s;
    text-decoration: none;
}
.page-link:hover { background: var(--cream); border-color: var(--green-dark); color: var(--green-dark); }
.page-link.active { background: var(--green-dark); color: var(--white); border-color: var(--green-dark); }
.page-link.disabled { opacity: 0.4; pointer-events: none; }

/* ─── Dashboard ───────────────────────────────────────────────────────── */
.section-title {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 700;
    color: var(--green-dark);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ─── Confirm Dialog ──────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(4px);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal-box {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    text-align: center;
}
.modal-icon {
    width: 56px; height: 56px;
    background: #FEE2E2;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px;
    font-size: 1.4rem;
}
.modal-box h3 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    color: var(--text-dark);
    margin-bottom: 8px;
}
.modal-box p { font-size: 0.875rem; color: var(--text-light); margin-bottom: 24px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }

/* ─── Animations ──────────────────────────────────────────────────────── */
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ─── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }
    .main-content { margin-right: 0; }
    .sidebar-toggle { display: flex; }
    .form-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .page-body { padding: 16px; }
    .topbar { padding: 0 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    table { font-size: 0.8rem; }
    thead th, tbody td { padding: 10px 10px; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .search-box { max-width: 100%; }
}
