:root {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --panel-2: #f7f9fd;
    --ink: #1c2431;
    --muted: #6b7688;
    --line: #e2e7f0;
    --brand: #1f5fd0;
    --brand-dark: #17458f;
    --ok: #167a4b;
    --ok-bg: #e6f6ee;
    --bad: #b0342c;
    --bad-bg: #fdecea;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    min-height: 100vh;
    color: var(--ink);
    font: 15px/1.7 "Segoe UI", Tahoma, "Noto Naskh Arabic", "Noto Sans Arabic", Arial, sans-serif;
}

[dir="rtl"] body,
body[dir="rtl"] { text-align: right; }

a { color: var(--brand); }

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 14px 24px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.site-header nav { display: flex; gap: 10px 18px; flex-wrap: wrap; align-items: center; }
.site-header nav a { text-decoration: none; font-weight: 600; padding: 9px 2px; }
.site-header nav a.muted { color: var(--muted); font-weight: 500; }

.container { max-width: 980px; margin: 0 auto; padding: 28px 20px 60px; }
.container.narrow { max-width: 460px; }

h1 { font-size: 24px; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.subtitle { color: var(--muted); margin: 0 0 24px; }

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 22px;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px rgba(28, 36, 49, .05);
}

label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.field { margin-bottom: 16px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

input[type=text], input[type=password], input[type=date], input[type=number], input[type=file], textarea {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    font: inherit;
    color: inherit;
}

input::placeholder, textarea::placeholder { color: #9aa4b3; }
input:focus, textarea:focus { outline: 2px solid rgba(31, 95, 208, .35); border-color: var(--brand); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }

.btn {
    display: inline-block;
    padding: 11px 20px;
    border: 0;
    border-radius: 10px;
    background: var(--brand);
    color: #fff;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}
.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: #eef1f7; color: var(--ink); }
.btn.danger { background: transparent; color: var(--bad); padding: 11px 10px; font-size: 13px; font-weight: 600; }
.btn.block { display: block; width: 100%; text-align: center; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td.actions { white-space: nowrap; text-align: end; }
td.actions a { display: inline-block; padding: 11px 10px; margin-inline-end: 4px; }

.badge { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.6; }
.badge.active { background: var(--ok-bg); color: var(--ok); }
.badge.expired { background: var(--bad-bg); color: var(--bad); }

.alert { padding: 12px 15px; border-radius: 12px; margin-bottom: 18px; font-size: 14px; }
.alert-success { background: var(--ok-bg); color: var(--ok); }
.alert-error { background: var(--bad-bg); color: var(--bad); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type=text] { flex: 1; min-width: 200px; }

/* Public document page: plain sheet with the department heading and a verify link. */
body.sheet { background: #fff; }
.container.bare { max-width: 640px; padding-top: 40px; }
.doc-message { text-align: center; padding: 10px 18px 40px; }
.doc-message .doc-logo { width: 150px; height: auto; margin-bottom: 18px; }
.doc-message .org-name { font-size: 17px; font-weight: 700; margin: 0; }
.doc-message .org-dept { font-size: 16px; color: #c62828; margin: 4px 0; }
.doc-message .org-unit { font-size: 16px; margin: 0; }
.doc-greeting { font-size: 17px; margin: 56px 0 16px; line-height: 2; }
.doc-verify { margin: 0; font-size: 16px; }
.doc-verify a { color: #c62828; font-weight: 600; text-decoration: underline; }

.doc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 0 22px; }
.doc-grid div {
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 16px;
}
.doc-grid div span { display: block; color: var(--muted); font-size: 12.5px; }
.doc-grid div b { font-size: 16px; font-weight: 700; }

.qr-panel { text-align: center; }
.qr-panel img { width: 190px; height: 190px; border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 8px; }
.qr-links { display: flex; justify-content: center; gap: 10px; margin: 6px 0 0; }
.qr-links a { display: inline-block; padding: 11px 14px; border-radius: 10px; background: #eef1f7; border: 1px solid var(--line); text-decoration: none; font-size: 13px; font-weight: 600; }
.qr-panel code { display: block; margin-top: 10px; font-size: 12px; color: var(--muted); word-break: break-all; direction: ltr; }

.lang-switch { display: inline-flex; gap: 4px; align-items: center; font-size: 13px; }
.lang-switch b, .lang-switch a { padding: 9px 8px; }
.lang-switch b { color: var(--ink); }
.lang-switch a { color: var(--muted); text-decoration: none; font-weight: 600; }
.lang-switch a:hover { color: var(--brand); }

.site-footer {
    max-width: 980px;
    margin: 0 auto;
    padding: 18px 20px 28px;
    color: var(--muted);
    font-size: 13px;
}

.page-links { display: flex; gap: 8px; }
.page-links a, .page-links span { padding: 6px 11px; border-radius: 9px; text-decoration: none; font-size: 13px; }
.page-links span { background: var(--brand); color: #fff; font-weight: 700; }

@media (max-width: 640px) {
    .grid-2, .doc-grid { grid-template-columns: 1fr; }
    .stats { grid-template-columns: 1fr 1fr; }
    .container { padding: 20px 14px 40px; }
    .card { padding: 16px; }
    .doc-greeting { font-size: 17px; }

    /* The documents table becomes one card per row so it never overflows. */
    table.documents thead { display: none; }
    table.documents, table.documents tbody, table.documents tr, table.documents td { display: block; width: auto; }
    table.documents tr {
        background: var(--panel-2);
        border: 1px solid var(--line);
        border-radius: 12px;
        padding: 6px 12px;
        margin-bottom: 12px;
    }
    table.documents td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        padding: 7px 0;
        border-bottom: 1px dashed var(--line);
    }
    table.documents td:last-child { border-bottom: 0; }
    table.documents td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 12px;
        font-weight: 600;
        flex: 0 0 auto;
    }
    table.documents td.actions { justify-content: flex-start; gap: 6px; padding-top: 10px; }
}
