:root {
    --bg: #f4f3fa;
    --card: #ffffff;
    --text: #1f1d2b;
    --muted: #6b6880;
    --border: #e2e0ee;
    --brand: #26215c;
    --accent: #ef9f27;
    --focus: #534ab7;
    --danger: #a32d2d;
    --danger-bg: #fcebeb;
    --chip: #eeedfe;
}

:root[data-theme="dark"] {
    --bg: #14121f;
    --card: #1d1a2e;
    --text: #eeedfe;
    --muted: #a9a6c2;
    --border: #332f4d;
    --focus: #afa9ec;
    --danger: #f7c1c1;
    --danger-bg: #501313;
    --chip: #332f4d;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif;
    line-height: 1.6;
}

.auth-card {
    display: grid;
    grid-template-columns: 1.05fr 1fr;
    width: 100%;
    max-width: 880px;
    min-height: 500px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
}

.brand-panel {
    background: var(--brand);
    color: #eeedfe;
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 24px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-name { font-size: 18px; font-weight: 600; }

.logo-box {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--accent);
    color: #412402;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.logo-box img { width: 100%; height: 100%; object-fit: contain; }
.logo-box svg { width: 26px; height: 26px; }

.route { width: 100%; height: auto; }
.tagline { font-size: 22px; font-weight: 600; line-height: 1.5; margin: 0 0 6px; }
.tagline-sub { font-size: 13px; color: #afa9ec; margin: 0; }

.form-panel {
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.toolbar { display: flex; justify-content: flex-end; gap: 6px; margin-bottom: 24px; }
.toolbar a,
.toolbar button {
    font: inherit;
    font-size: 12px;
    padding: 3px 10px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--muted);
    text-decoration: none;
    cursor: pointer;
}
.toolbar a.active { background: var(--chip); color: var(--focus); font-weight: 600; }

h1 { font-size: 22px; margin: 0 0 4px; }
.lead { margin: 0 0 20px; font-size: 13px; color: var(--muted); }

.field { margin-bottom: 14px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

input[type="text"],
input[type="password"] {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    font: inherit;
}
input:focus { outline: 2px solid var(--focus); outline-offset: 1px; }

.btn {
    width: 100%;
    height: 44px;
    border: 0;
    border-radius: 10px;
    background: var(--brand);
    color: #ffffff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.btn:hover { opacity: 0.92; }
:root[data-theme="dark"] .btn { background: #534ab7; }

.error {
    background: var(--danger-bg);
    color: var(--danger);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 14px;
}

.links { margin-top: 14px; text-align: center; font-size: 13px; }
.links a { color: var(--focus); text-decoration: none; }

.notice {
    margin-top: 20px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--muted);
}

.dash {
    width: 100%;
    max-width: 560px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
}

@media (max-width: 720px) {
    .auth-card { grid-template-columns: 1fr; }
    .brand-panel { display: none; }
}
.dash.wide { max-width: 900px; }

.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.head h1 { margin: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: start; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
small { color: var(--muted); }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; background: var(--chip); color: var(--text); }
.badge.pending { background: #faeeda; color: #633806; }
.badge.issued { background: #eeedfe; color: #3c3489; }
.badge.used { background: #eaf3de; color: #27500a; }
.badge.expired { background: #f1efe8; color: #444441; }

.btn.small { width: auto; height: 34px; padding: 0 14px; font-size: 13px; }
.btn.ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}
:root[data-theme="dark"] .btn.ghost { background: transparent; }

.stack { display: flex; flex-direction: column; gap: 10px; }

.code-card { border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 18px; text-align: center; }
.code-title { margin: 0 0 4px; font-weight: 600; }
.code { font-size: 32px; font-weight: 600; letter-spacing: 4px; margin: 10px 0 4px; font-variant-numeric: tabular-nums; }
.code-once { margin: 0 0 14px; font-size: 12px; color: #854f0b; }
.row { display: flex; justify-content: center; gap: 8px; }

.status { background: #eaf3de; color: #27500a; border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }
.back { display: block; margin-top: 18px; text-align: center; font-size: 13px; color: var(--focus); text-decoration: none; }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

.code-input { text-align: center; letter-spacing: 4px; font-size: 18px; }
.hint { margin: 0 0 12px; font-size: 12px; color: var(--muted); }

.meter { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 8px 0 4px; }
.meter span { height: 4px; border-radius: 2px; background: var(--border); }
.meter span.on.weak { background: #e24b4a; }
.meter span.on.medium { background: #ef9f27; }
.meter span.on.strong { background: #639922; }
.strength { margin: 0; min-height: 18px; font-size: 12px; color: var(--muted); }

.rules { list-style: none; margin: 0 0 14px; padding: 0; font-size: 12px; color: var(--muted); }
.rules li { padding: 2px 0; }
.rules li::before { content: "\25CB"; margin-inline-end: 6px; }
.rules li.ok { color: #3b6d11; }
.rules li.ok::before { content: "\2713"; }
:root[data-theme="dark"] .rules li.ok { color: #97c459; }

.done { text-align: center; }
.done-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 10px;
    border-radius: 50%;
    background: #eaf3de;
    color: #27500a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}
.notes {
    list-style: none;
    margin: 0 0 16px;
    padding: 12px;
    text-align: start;
    background: var(--bg);
    border-radius: 10px;
    font-size: 12px;
    color: var(--muted);
}
.notes li { padding: 3px 0; }
.idle-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 18, 24, 0.55);
    backdrop-filter: blur(3px);
}
.idle-overlay[hidden] { display: none; }

.idle-box {
    width: min(380px, calc(100% - 32px));
    padding: 28px 24px 24px;
    border-radius: 16px;
    text-align: center;
    background: #ffffff;
    color: #1a1a1a;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
:root[data-theme="dark"] .idle-box { background: #1e2127; color: #f1f1f1; }
.idle-box h2 { margin: 0 0 8px; font-size: 20px; }
.idle-box p { margin: 0 0 20px; font-size: 14px; line-height: 1.6; opacity: 0.75; }

.idle-ring { position: relative; width: 84px; height: 84px; margin: 0 auto 14px; }
.idle-ring svg { transform: rotate(-90deg); }
.idle-ring circle { fill: none; stroke-width: 4; }
.idle-track { stroke: #e5e5e5; }
:root[data-theme="dark"] .idle-track { stroke: #3a3f47; }
.idle-progress { stroke: #378add; stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
#idle-count {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

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