/* ==========================================================================
   Reborn Surveys
   Palette from the Reborn wordmark navy; one warm accent (gold) reserved for
   the rating scale and the active-page marker.
   ========================================================================== */

:root {
    --rb-navy: #20244c;
    --rb-navy-2: #2d3266;
    --rb-gold: #e2a93b;
    --rb-sage: #2f8f6b;

    --rail-w: 76px;
    --sidebar-w: 264px;
    --topbar-h: 64px;
    --ease: cubic-bezier(.2, .7, .2, 1);

    --bs-font-sans-serif: "IBM Plex Sans", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --bs-border-radius: .5rem;
    --bs-border-radius-lg: .75rem;
}

html[dir="rtl"] {
    --bs-font-sans-serif: "IBM Plex Sans Arabic", "IBM Plex Sans", system-ui, Tahoma, Arial, sans-serif;
}

[data-bs-theme="light"] {
    --app-bg: #eef0f6;
    --surface: #ffffff;
    --surface-2: #f6f7fb;
    --line: #dde0ec;
    --ink: #1a1d3a;
    --muted: #5d6280;
    --sidebar-bg: #20244c;
    --sidebar-fg: #c3c7e4;
    --sidebar-fg-strong: #ffffff;
    --sidebar-hover: rgba(255, 255, 255, .07);
    --brand: #20244c;
    --brand-contrast: #ffffff;
    --brand-soft: #e3e5f3;

    --bs-body-bg: var(--app-bg);
    --bs-body-color: var(--ink);
    --bs-secondary-color: var(--muted);
    --bs-border-color: var(--line);
    --bs-tertiary-bg: var(--surface-2);
    --bs-link-color-rgb: 45, 50, 102;
    --bs-link-hover-color-rgb: 32, 36, 76;
}

[data-bs-theme="dark"] {
    --app-bg: #111329;
    --surface: #191c37;
    --surface-2: #20244a;
    --line: #2c3159;
    --ink: #e6e8f5;
    --muted: #9ea3c4;
    --sidebar-bg: #0c0e20;
    --sidebar-fg: #a2a7cb;
    --sidebar-fg-strong: #ffffff;
    --sidebar-hover: rgba(255, 255, 255, .06);
    --brand: #a9afef;
    --brand-contrast: #14173a;
    --brand-soft: #262b57;

    --bs-body-bg: var(--app-bg);
    --bs-body-color: var(--ink);
    --bs-secondary-color: var(--muted);
    --bs-border-color: var(--line);
    --bs-tertiary-bg: var(--surface-2);
    --bs-link-color-rgb: 169, 175, 239;
    --bs-link-hover-color-rgb: 205, 209, 250;
}

body { background: var(--app-bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, h5 { letter-spacing: -.01em; font-weight: 600; }
html[dir="rtl"] h1, html[dir="rtl"] h2, html[dir="rtl"] h3 { letter-spacing: 0; }
:focus-visible { outline: 2px solid var(--rb-gold); outline-offset: 2px; }
.skip-link { position: fixed; top: .5rem; inset-inline-start: .5rem; z-index: 2000; background: var(--surface); padding: .5rem 1rem; border-radius: .5rem; }

/* Brand-coloured primary button (navy in light, periwinkle in dark) */
.btn-primary {
    --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-color: var(--brand-contrast);
    --bs-btn-hover-bg: var(--rb-navy-2); --bs-btn-hover-border-color: var(--rb-navy-2); --bs-btn-hover-color: #fff;
    --bs-btn-active-bg: var(--rb-navy-2); --bs-btn-active-border-color: var(--rb-navy-2);
    --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand);
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-hover-bg: #c3c8f7; --bs-btn-hover-border-color: #c3c8f7; --bs-btn-hover-color: var(--brand-contrast); --bs-btn-active-bg: #c3c8f7; }
.btn-outline-primary {
    --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); --bs-btn-hover-color: var(--brand-contrast);
    --bs-btn-active-bg: var(--brand); --bs-btn-active-color: var(--brand-contrast);
}
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--brand) 22%, transparent); }
.text-brand { color: var(--brand) !important; }

/* ---------------------------------------------------------------- Sidebar
   Desktop: a 76px icon rail that slides open on hover / keyboard focus and
   closes again when the pointer leaves (auto-hide). "Keep sidebar open"
   pins it and pushes the content. Mobile: an off-canvas drawer.            */
.sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 1040;
    width: var(--rail-w); background: var(--sidebar-bg); color: var(--sidebar-fg);
    display: flex; flex-direction: column; overflow: hidden;
    transition: width .22s var(--ease), box-shadow .22s var(--ease), transform .25s var(--ease);
}
.sidebar:hover, .sidebar:focus-within, body.sidebar-pinned .sidebar { width: var(--sidebar-w); }
body:not(.sidebar-pinned) .sidebar:hover, body:not(.sidebar-pinned) .sidebar:focus-within { box-shadow: 0 0 0 100vmax rgba(10, 12, 30, .18), 8px 0 32px rgba(0, 0, 0, .25); }

.sidebar-brand { height: var(--topbar-h); display: flex; align-items: center; padding-inline: 22px; flex-shrink: 0; }
.brand-link { color: var(--sidebar-fg-strong); display: flex; align-items: center; height: 30px; }
.brand-mark { height: 30px; width: auto; }
.brand-full { height: 26px; width: auto; display: none; }
.sidebar:hover .brand-mark, .sidebar:focus-within .brand-mark, body.sidebar-pinned .brand-mark { display: none; }
.sidebar:hover .brand-full, .sidebar:focus-within .brand-full, body.sidebar-pinned .brand-full { display: block; }

.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 8px 12px; }
.sidebar-foot { padding: 8px 12px 16px; border-top: 1px solid rgba(255, 255, 255, .08); }

.nav-item {
    position: relative; display: flex; align-items: center; gap: 14px;
    width: 100%; height: 44px; padding-inline: 14px; margin-block: 2px;
    color: var(--sidebar-fg); text-decoration: none; border: 0; background: none;
    border-radius: 10px; white-space: nowrap; font-size: .95rem;
}
.nav-item i { font-size: 1.2rem; width: 22px; text-align: center; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-fg-strong); }
.nav-item.active { background: rgba(255, 255, 255, .1); color: var(--sidebar-fg-strong); font-weight: 500; }
.nav-item.active::before {
    content: ""; position: absolute; inset-inline-start: -12px; top: 10px; bottom: 10px;
    width: 4px; border-start-end-radius: 4px; border-end-end-radius: 4px; background: var(--rb-gold);
}
.nav-label { opacity: 0; transition: opacity .15s var(--ease); }
.sidebar:hover .nav-label, .sidebar:focus-within .nav-label, body.sidebar-pinned .nav-label { opacity: 1; transition-delay: .05s; }
.nav-section { height: 28px; margin: 14px 14px 4px; display: flex; align-items: center; font-size: .78rem; color: rgba(255, 255, 255, .45); }
.nav-section::before { content: ""; width: 22px; height: 1px; background: rgba(255, 255, 255, .18); flex-shrink: 0; }
.sidebar:hover .nav-section::before, .sidebar:focus-within .nav-section::before, body.sidebar-pinned .nav-section::before { display: none; }
.nav-section .nav-label { position: absolute; }
.sidebar:hover .nav-section .nav-label, .sidebar:focus-within .nav-section .nav-label, body.sidebar-pinned .nav-section .nav-label { position: static; }
.pin-toggle .icon-pinned { display: none; }
body.sidebar-pinned .pin-toggle .icon-pinned { display: inline-block; }
body.sidebar-pinned .pin-toggle .icon-unpinned { display: none; }

/* ---------------------------------------------------------------- Main */
.app-main { margin-inline-start: var(--rail-w); min-height: 100vh; transition: margin .22s var(--ease); }
body.sidebar-pinned .app-main { margin-inline-start: var(--sidebar-w); }

.topbar {
    position: sticky; top: 0; z-index: 1030; height: var(--topbar-h);
    display: flex; align-items: center; gap: 12px; padding-inline: 28px;
    background: color-mix(in srgb, var(--app-bg) 86%, transparent);
    backdrop-filter: saturate(140%) blur(10px);
    border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 1.15rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.btn-icon { width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 10px; color: var(--ink); font-size: 1.15rem; border: 0; }
.btn-icon:hover, .btn-icon[aria-expanded="true"] { background: var(--surface-2); color: var(--ink); }
.user-chip { display: flex; align-items: center; gap: 10px; border-radius: 999px; padding: 4px 14px 4px 4px; color: var(--ink); border: 1px solid var(--line); background: var(--surface); }
html[dir="rtl"] .user-chip { padding: 4px 4px 4px 14px; }
.user-chip:hover { border-color: var(--brand); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 600; font-size: .8rem; }
.theme-check { visibility: hidden; }
.dropdown-item.is-current .theme-check { visibility: visible; }

.app-content { padding: 28px; max-width: 1400px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-head h2 { font-size: 1.5rem; margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------------------------------------------------------------- Surfaces */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.panel-body { padding: 22px; }
.panel-head { padding: 16px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-head h3 { font-size: 1rem; margin: 0; }
.table { --bs-table-bg: transparent; margin: 0; }
.table > :not(caption) > * > * { padding: .85rem 1.1rem; border-color: var(--line); }
.table thead th { font-weight: 500; color: var(--muted); font-size: .85rem; background: var(--surface-2); }
.table-actions { white-space: nowrap; text-align: end; }

.stat { padding: 18px 22px; }
.stat-value { font-size: 2rem; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: .9rem; }

.badge-status { font-weight: 500; padding: .35em .7em; border-radius: 999px; font-size: .78rem; }
.status-open { background: color-mix(in srgb, var(--rb-sage) 16%, transparent); color: var(--rb-sage); }
.status-draft { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.status-scheduled { background: color-mix(in srgb, var(--rb-gold) 18%, transparent); color: #a2721a; }
[data-bs-theme="dark"] .status-scheduled { color: var(--rb-gold); }
[data-bs-theme="dark"] .status-open { color: #5cc49c; }
.status-closed { background: color-mix(in srgb, #c0453b 14%, transparent); color: #c0453b; }
.status-inactive { background: color-mix(in srgb, #c0453b 14%, transparent); color: #c0453b; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty i { font-size: 2rem; display: block; margin-bottom: 8px; color: var(--brand); }

/* ---------------------------------------------------------------- Survey cards (staff) */
.survey-card { display: flex; flex-direction: column; gap: 10px; height: 100%; padding: 22px; text-decoration: none; color: inherit; transition: border-color .15s; }
.survey-card:hover { border-color: var(--brand); color: inherit; }
.survey-card h3 { font-size: 1.1rem; margin: 0; }
.survey-meta { color: var(--muted); font-size: .88rem; }

/* ---------------------------------------------------------------- Survey form (staff) */
.take-wrap { max-width: 760px; }
.take-header { padding: 28px; border-radius: 14px; background: var(--rb-navy); color: #fff; margin-bottom: 18px; }
[data-bs-theme="dark"] .take-header { background: var(--surface-2); }
.take-header h2 { font-size: 1.6rem; margin: 0 0 6px; }
.take-header .meta { color: rgba(255, 255, 255, .72); display: flex; flex-wrap: wrap; gap: 4px 16px; }
.question { padding: 22px; margin-bottom: 14px; }
.question-text { font-size: 1.05rem; font-weight: 500; margin-bottom: 14px; }
.question-num { color: var(--muted); font-variant-numeric: tabular-nums; margin-inline-end: 6px; }
.req { color: #c0453b; }

/* The rating scale: five tall segments, gold when chosen. */
.rating { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; border: 0; margin: 0; padding: 0; }
.rating input { position: absolute; opacity: 0; pointer-events: none; }
.rating label {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    min-height: 78px; padding: 10px 4px; border: 1px solid var(--line); border-radius: 10px;
    background: var(--surface-2); cursor: pointer; text-align: center; transition: background .12s, border-color .12s, transform .12s;
}
.rating label .n { font-size: 1.4rem; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.rating label .t { font-size: .78rem; color: var(--muted); line-height: 1.2; }
.rating label:hover { border-color: var(--brand); }
.rating input:checked + label { background: var(--rb-gold); border-color: var(--rb-gold); color: #2a1d00; transform: translateY(-2px); }
.rating input:checked + label .t { color: #4a3510; }
.rating input:focus-visible + label { outline: 2px solid var(--brand); outline-offset: 2px; }
.rating-ends { display: none; justify-content: space-between; margin-top: 6px; font-size: .78rem; color: var(--muted); }
@media (max-width: 575.98px) {
    .rating label { min-height: 56px; }
    .rating label .t { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
    .rating-ends { display: flex; }
}

.choice { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; cursor: pointer; background: var(--surface-2); }
.choice:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.choice .form-check-input { margin: 0; flex-shrink: 0; }
.question.is-invalid { border-color: #c0453b; }

/* ---------------------------------------------------------------- Builder */
.q-row { padding: 18px; margin-bottom: 12px; }
.q-row .q-index { width: 30px; height: 30px; border-radius: 8px; display: inline-grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 600; font-size: .85rem; flex-shrink: 0; }
.lang-tag { font-size: .72rem; padding: .1rem .45rem; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.perm-group { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; height: 100%; background: var(--surface-2); }
.perm-group h4 { font-size: .95rem; margin: 0; }

/* ---------------------------------------------------------------- Results */
.bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.bar.gold > span { background: var(--rb-gold); }
.avg-score { font-size: 2.4rem; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.text-answers { max-height: 360px; overflow: auto; }
.text-answer { padding: 10px 0; border-bottom: 1px solid var(--line); }
.text-answer:last-child { border-bottom: 0; }

/* ---------------------------------------------------------------- Guest / login */
.guest { min-height: 100vh; }
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-brand { background: var(--rb-navy); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
[data-bs-theme="dark"] .auth-brand { background: #0c0e20; }
.auth-brand .logo { height: 44px; width: auto; color: #fff; }
.auth-brand h1 { font-size: clamp(2rem, 3.4vw, 3rem); font-weight: 600; max-width: 14ch; line-height: 1.1; }
.auth-brand p { color: rgba(255, 255, 255, .7); max-width: 40ch; }
.auth-brand .giant-r { position: absolute; inset-inline-end: -60px; bottom: -40px; height: 120%; width: auto; color: rgba(255, 255, 255, .05); pointer-events: none; }
html[dir="rtl"] .auth-brand .giant-r { transform: scaleX(-1); }
.auth-form { display: flex; flex-direction: column; padding: 32px; }
.auth-form .inner { width: 100%; max-width: 380px; margin: auto; }
.auth-form .form-control { padding: .7rem .9rem; }
.auth-tools { display: flex; justify-content: flex-end; gap: 4px; }
@media (max-width: 860px) {
    .auth { grid-template-columns: 1fr; }
    .auth-brand { padding: 28px; min-height: auto; }
    .auth-brand h1, .auth-brand p, .auth-brand .giant-r { display: none; }
}

/* ---------------------------------------------------------------- Mobile drawer */
.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
    .sidebar { width: var(--sidebar-w) !important; transform: translateX(-100%); box-shadow: none !important; }
    html[dir="rtl"] .sidebar { transform: translateX(100%); }
    body.sidebar-open .sidebar { transform: none; }
    .sidebar .nav-label { opacity: 1; }
    .sidebar .brand-mark { display: none; }
    .sidebar .brand-full { display: block; }
    .sidebar .nav-section::before { display: none; }
    .sidebar .nav-section .nav-label { position: static; }
    .app-main, body.sidebar-pinned .app-main { margin-inline-start: 0; }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 1035; background: rgba(10, 12, 30, .45); }
    .topbar { padding-inline: 16px; }
    .app-content { padding: 18px 16px; }
}

/* ---------------------------------------------------------------- Print (QR page) */
@media print {
    .sidebar, .topbar, .no-print, .alert { display: none !important; }
    .app-main { margin: 0 !important; }
    .panel { border: 0; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
