/* ============================================================
   OFFICIAL MAIL SYSTEM — MAIN STYLESHEET
   Font: IBM Plex Sans Arabic + JetBrains Mono
   Theme: Deep slate institutional, refined minimalist
   ============================================================ */

:root {
    --bg-base:       #0d0f14;
    --bg-raised:     #13161d;
    --bg-card:       #181c25;
    --bg-input:      #1e2330;
    --border:        #252b38;
    --border-strong: #303848;

    --text-primary:  #e8eaf0;
    --text-secondary:#8a93a8;
    --text-muted:    #4a5368;
    --text-inverse:  #0d0f14;

    --accent:        #4f7ef8;
    --accent-dim:    #1e2d54;
    --accent-hover:  #6b96ff;

    --green:         #34c77a;
    --green-dim:     #0e2e1e;
    --amber:         #f0a842;
    --amber-dim:     #2e2008;
    --red:           #e85050;
    --red-dim:       #2e0f0f;

    --sidebar-w:     260px;
    --topbar-h:      60px;
    --radius:        8px;
    --radius-sm:     4px;
    --radius-lg:     14px;

    --shadow-sm:  0 1px 3px rgba(0,0,0,.4);
    --shadow-md:  0 4px 16px rgba(0,0,0,.5);
    --shadow-lg:  0 12px 40px rgba(0,0,0,.6);

    --transition: 180ms cubic-bezier(.4,0,.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
    font-family: 'IBM Plex Sans Arabic', sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    direction: rtl;
    min-height: 100vh;
    display: flex;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* ===========================
   SIDEBAR
   =========================== */
.sidebar {
    position: fixed;
    top: 0; right: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--bg-raised);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 200;
    transition: transform var(--transition);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 22px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.brand-mark {
    width: 30px; height: 30px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    position: relative;
    flex-shrink: 0;
}
.brand-mark::after {
    content: '';
    position: absolute;
    inset: 5px;
    background: var(--bg-raised);
    border-radius: 2px;
}

.brand-text {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--text-primary);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: .9rem;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
}
.nav-item:hover {
    background: var(--bg-input);
    color: var(--text-primary);
}
.nav-item.active {
    background: var(--accent-dim);
    color: var(--accent);
}

.nav-icon {
    font-size: .6rem;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    opacity: .7;
}

.nav-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 0;
}

.sidebar-footer {
    padding: 14px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.user-avatar {
    width: 34px; height: 34px;
    background: var(--accent-dim);
    color: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .95rem;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.user-name {
    font-size: .85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-role {
    font-size: .75rem;
    color: var(--text-muted);
}

.logout-btn {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 1.1rem;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: color var(--transition), background var(--transition);
    flex-shrink: 0;
}
.logout-btn:hover { background: var(--red-dim); color: var(--red); }

/* ===========================
   MAIN WRAPPER
   =========================== */
.main-wrapper {
    flex: 1;
    margin-right: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
}

.topbar {
    position: sticky;
    top: 0;
    height: var(--topbar-h);
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 28px;
    z-index: 100;
    flex-shrink: 0;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
}
.sidebar-toggle:hover { background: var(--bg-input); }

.page-heading {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.topbar-right { display: flex; align-items: center; gap: 12px; }

.content {
    padding: 28px;
    flex: 1;
}

/* ===========================
   ALERTS
   =========================== */
.alert {
    margin: 0 28px;
    padding: 12px 18px;
    border-radius: var(--radius);
    font-size: .9rem;
    border: 1px solid transparent;
}
.alert-success { background: var(--green-dim); border-color: var(--green); color: var(--green); }
.alert-error   { background: var(--red-dim);   border-color: var(--red);   color: var(--red);   }

/* ===========================
   CARDS
   =========================== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ===========================
   STAT CARDS
   =========================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    position: relative;
    overflow: hidden;
    transition: border-color var(--transition);
}
.stat-card:hover { border-color: var(--border-strong); }
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 3px;
    height: 100%;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}
.stat-card.blue::before   { background: var(--accent); }
.stat-card.green::before  { background: var(--green); }
.stat-card.amber::before  { background: var(--amber); }
.stat-card.red::before    { background: var(--red); }

.stat-label {
    font-size: .8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-bottom: 10px;
}

.stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}
.stat-card.blue  .stat-value { color: var(--accent); }
.stat-card.green .stat-value { color: var(--green); }
.stat-card.amber .stat-value { color: var(--amber); }
.stat-card.red   .stat-value { color: var(--red); }

.stat-sub {
    font-size: .78rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* ===========================
   TABLE
   =========================== */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
}

thead tr {
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
}

th {
    padding: 12px 16px;
    text-align: right;
    font-weight: 600;
    color: var(--text-muted);
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-raised); }

td {
    padding: 12px 16px;
    color: var(--text-primary);
    vertical-align: middle;
}

.td-mono {
    font-family: 'JetBrains Mono', monospace;
    font-size: .82rem;
    color: var(--text-secondary);
}

/* ===========================
   BADGES
   =========================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: .76rem;
    font-weight: 600;
    letter-spacing: .03em;
}
.badge-pending  { background: var(--amber-dim); color: var(--amber); }
.badge-received { background: var(--green-dim);  color: var(--green); }
.badge-urgent   { background: var(--red-dim);    color: var(--red); }
.badge-normal   { background: var(--bg-input);   color: var(--text-secondary); }

/* ===========================
   BUTTONS
   =========================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: var(--radius);
    font-family: 'IBM Plex Sans Arabic', sans-serif;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: background var(--transition), transform 80ms;
    white-space: nowrap;
}
.btn:active { transform: scale(.97); }

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
    background: var(--red-dim);
    color: var(--red);
    border: 1px solid var(--red);
}
.btn-danger:hover { background: var(--red); color: #fff; }

.btn-success {
    background: var(--green-dim);
    color: var(--green);
    border: 1px solid var(--green);
}
.btn-success:hover { background: var(--green); color: var(--text-inverse); }

.btn-sm {
    padding: 5px 12px;
    font-size: .8rem;
}

/* ===========================
   FORMS
   =========================== */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.form-group.full { grid-column: 1 / -1; }

label {
    font-size: .82rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: .03em;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="email"],
input[type="search"],
select,
textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-family: 'IBM Plex Sans Arabic', sans-serif;
    font-size: .9rem;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    appearance: none;
    -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79,126,248,.15);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }

textarea { resize: vertical; min-height: 90px; }

.form-hint {
    font-size: .77rem;
    color: var(--text-muted);
}

.file-upload-area {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
    position: relative;
}
.file-upload-area:hover {
    border-color: var(--accent);
    background: var(--accent-dim);
}
.file-upload-area input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}
.file-upload-label {
    font-size: .9rem;
    color: var(--text-secondary);
    pointer-events: none;
}
.file-upload-label strong { color: var(--accent); }

/* ===========================
   SEARCH BAR
   =========================== */
.search-bar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    margin-bottom: 20px;
}

.search-bar .form-group { flex: 1; min-width: 160px; }

/* ===========================
   PAGINATION
   =========================== */
.pagination {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: center;
    margin-top: 24px;
    flex-wrap: wrap;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border-radius: var(--radius);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: .85rem;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.page-link:hover { background: var(--bg-input); color: var(--text-primary); }
.page-link.current { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.page-link.disabled { opacity: .3; pointer-events: none; }

/* ===========================
   MODAL
   =========================== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.75);
    z-index: 400;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.modal-backdrop.show { display: flex; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    box-shadow: var(--shadow-lg);
    padding: 28px;
}

.modal-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ===========================
   DETAIL PANEL
   =========================== */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.detail-item {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.detail-label {
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .07em;
    margin-bottom: 5px;
}

.detail-value {
    font-size: .92rem;
    color: var(--text-primary);
    word-break: break-word;
}

/* ===========================
   EMPTY STATE
   =========================== */
.empty-state {
    padding: 56px 24px;
    text-align: center;
    color: var(--text-muted);
}
.empty-state-icon {
    font-size: 2rem;
    margin-bottom: 12px;
    opacity: .4;
}
.empty-state p { font-size: .9rem; }

/* ===========================
   LOGIN PAGE
   =========================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-base);
    padding: 24px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}

.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-bottom: 32px;
}

.login-logo-mark {
    width: 40px; height: 40px;
    background: var(--accent);
    border-radius: var(--radius);
    position: relative;
    flex-shrink: 0;
}
.login-logo-mark::after {
    content: '';
    position: absolute;
    inset: 7px;
    background: var(--bg-card);
    border-radius: 2px;
}

.login-logo-text {
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.3;
}

.login-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 8px;
}
.login-sub {
    font-size: .85rem;
    color: var(--text-muted);
    margin-bottom: 28px;
}

.login-card .form-group { margin-bottom: 16px; }

.login-error {
    background: var(--red-dim);
    border: 1px solid var(--red);
    color: var(--red);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: .88rem;
    margin-bottom: 18px;
}

/* ===========================
   CHART BARS
   =========================== */
.bar-chart {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bar-label {
    width: 140px;
    font-size: .82rem;
    color: var(--text-secondary);
    text-align: right;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-track {
    flex: 1;
    height: 10px;
    background: var(--bg-input);
    border-radius: 5px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 5px;
    transition: width .6s cubic-bezier(.4,0,.2,1);
}

.bar-count {
    font-family: 'JetBrains Mono', monospace;
    font-size: .8rem;
    color: var(--text-muted);
    width: 30px;
    text-align: left;
    flex-shrink: 0;
}

/* ===========================
   UTILITY
   =========================== */
.d-flex       { display: flex; }
.align-center { align-items: center; }
.gap-8        { gap: 8px; }
.gap-12       { gap: 12px; }
.gap-16       { gap: 16px; }
.mb-4         { margin-bottom: 4px; }
.mb-8         { margin-bottom: 8px; }
.mb-16        { margin-bottom: 16px; }
.mb-24        { margin-bottom: 24px; }
.mb-28        { margin-bottom: 28px; }
.mt-16        { margin-top: 16px; }
.text-muted   { color: var(--text-muted); }
.text-sm      { font-size: .82rem; }
.font-mono    { font-family: 'JetBrains Mono', monospace; }
.text-accent  { color: var(--accent); }
.text-green   { color: var(--green); }
.text-amber   { color: var(--amber); }
.text-red     { color: var(--red); }

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}
.section-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* ===========================
   OVERLAY (mobile sidebar)
   =========================== */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 190;
}
.overlay.show { display: block; }

/* ===========================
   RESPONSIVE
   =========================== */
@media (max-width: 768px) {
    :root { --sidebar-w: 0px; }

    .sidebar {
        transform: translateX(100%);
        width: 260px;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open ~ #overlay { display: block; }

    .main-wrapper { margin-right: 0; }
    .sidebar-toggle { display: flex; }
    .content { padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid { grid-template-columns: 1fr; }
}