:root {
    --bg: #f3f5f8;
    --card: #ffffff;
    --text: #17202b;
    --muted: #64707f;
    --line: #dfe4ea;
    --primary: #0f4c81;
    --danger: #b3261e;
    --ok: #1b7a43;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #11161d;
        --card: #1a212b;
        --text: #e8ecf1;
        --muted: #98a4b3;
        --line: #2b3542;
        --primary: #5aa2e0;
        --danger: #f08a82;
        --ok: #6fcf97;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.6 "Segoe UI", Tahoma, Arial, sans-serif;
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: #0f4c81;
    color: #fff;
}

.brand { font-weight: 700; }
.brand small { font-weight: 400; opacity: .8; margin-inline-start: 6px; }
.logout { display: flex; gap: 10px; align-items: center; margin: 0; }
.logout .link { color: #fff; }
.who { font-size: 14px; opacity: .85; }

.container { max-width: 760px; margin: 0 auto; padding: 14px 16px; }

h1 { font-size: 20px; margin: 0 0 8px; }
h2 { font-size: 17px; margin: 0 0 10px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
}

.card.empty { text-align: center; color: var(--muted); }
.card.login { max-width: 380px; margin: 8vh auto 0; }
details.card > summary { cursor: pointer; display: flex; gap: 8px; align-items: center; }
details.card[open] > summary { margin-bottom: 12px; }

.list { display: flex; flex-direction: column; gap: 8px; }

.item {
    display: block;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    color: inherit;
    text-decoration: none;
}

.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 14px; }
.danger { color: var(--danger); }
.back { display: inline-block; margin-bottom: 10px; color: var(--primary); text-decoration: none; }

.badge {
    font-size: 13px;
    padding: 2px 10px;
    border-radius: 999px;
    border: 1px solid currentColor;
    white-space: nowrap;
}

.badge.active { color: var(--ok); }
.badge.pending { color: #b7791f; }
.badge.revoked, .badge.expired { color: var(--danger); }

label { display: block; margin-bottom: 10px; font-size: 14px; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 16px; min-height: 36px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 12px; }

input:not([type=checkbox]), select {
    display: block;
    width: 100%;
    min-height: 44px;
    margin-top: 4px;
    padding: 8px 12px;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 10px;
}

input[type=checkbox] { width: 20px; height: 20px; }

.btn {
    display: inline-block;
    min-height: 44px;
    padding: 9px 18px;
    font: inherit;
    color: var(--text);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    text-decoration: none;
    cursor: pointer;
    margin-top: 6px;
}

.btn.primary { background: #0f4c81; border-color: #0f4c81; color: #fff; width: 100%; }
.btn.danger { color: var(--danger); border-color: var(--danger); width: 100%; }
.link { background: none; border: 0; padding: 8px; font: inherit; color: var(--primary); cursor: pointer; }
.link.danger { color: var(--danger); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input { flex: 2 1 180px; margin: 0; }
.filters select { flex: 1 1 130px; margin: 0; }
.filters .btn { margin: 0; }

.inline { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.inline input { flex: 1 1 150px; margin: 0; }
.inline .btn { margin: 0; }

.pager { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }

.alert { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; border: 1px solid currentColor; }
.alert.ok { color: var(--ok); }
.alert.err { color: var(--danger); }

dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 8px 0 12px; }
dt { color: var(--muted); font-size: 14px; }
dd { margin: 0; overflow-wrap: anywhere; }

.serial {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
}

.serial form { margin: 0; }
code { font-family: Consolas, monospace; font-size: 15px; overflow-wrap: anywhere; }

.tabs {
    position: fixed;
    bottom: 0;
    inset-inline: 0;
    display: flex;
    background: var(--card);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
}

.tabs a {
    flex: 1;
    text-align: center;
    padding: 14px 4px;
    color: var(--muted);
    text-decoration: none;
    font-size: 15px;
}

.tabs a.active { color: var(--primary); font-weight: 700; border-top: 2px solid var(--primary); }

/* لوحة الارقام */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }

.stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 14px;
    background: var(--card);
    border: 1px solid var(--line);
    border-inline-start: 4px solid currentColor;
    border-radius: 12px;
    text-decoration: none;
}

.stat b { font-size: 26px; line-height: 1.2; color: var(--text); }
.stat span { font-size: 14px; color: var(--muted); }
.stat.pending { color: #b7791f; }
.stat.active { color: var(--ok); }
.stat.revoked, .stat.expired { color: var(--danger); }
.stat.on { background: var(--bg); border-color: currentColor; }

.item:hover, .stat:hover { border-color: var(--primary); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.serial > div { flex: 1; min-width: 0; }

/* شاشات اللابتوب: التنقل اعلى الصفحة والارقام في صف واحد */
@media (min-width: 800px) {
    body { padding-bottom: 24px; }
    .container { max-width: 960px; padding-top: 68px; }
    .stats { grid-template-columns: repeat(4, 1fr); }
    .tabs {
        top: 46px;
        bottom: auto;
        z-index: 4;
        justify-content: center;
        border-top: 0;
        border-bottom: 1px solid var(--line);
    }
    .tabs a { flex: 0 0 auto; padding: 12px 22px; }
    .tabs a.active { border-top: 0; border-bottom: 2px solid var(--primary); }
    .list { display: grid; grid-template-columns: repeat(2, 1fr); }
    .btn.primary, .btn.danger { width: auto; min-width: 220px; }
}

@media (prefers-reduced-motion: no-preference) {
    .item, .stat, .btn { transition: border-color .15s; }
}
