/* FreeLoan — Main stylesheet
   CSS custom properties enable per-location theming.
   --color-primary and --color-secondary are injected per page via inline <style>. */

:root {
    --color-primary:       #2563eb;
    --color-primary-dark:  #1d4ed8;
    --color-primary-light: #eff6ff;
    --color-secondary:     #1d4ed8;
    --color-success:       #047857;   /* white text 5.5:1 (WCAG 1.4.3) */
    --color-warning:       #f59e0b;
    --color-danger:        #dc2626;   /* white text 4.8:1 */
    --color-danger-text:   #b91c1c;   /* red text on light backgrounds 6.5:1 */
    --color-info:          #3b82f6;
    --color-bg:            #f8fafc;
    --color-surface:       #ffffff;
    --color-border:        #e2e8f0;
    --color-text:          #1e293b;
    --color-text-muted:    #64748b;
    --sidebar-bg:          #1e293b;
    --sidebar-text:        #cbd5e1;
    --sidebar-active:      #ffffff;
    --sidebar-width:       260px;
    --radius:              8px;
    --radius-lg:           12px;
    --shadow:              0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:           0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
    --shadow-lg:           0 10px 15px rgba(0,0,0,.10), 0 4px 6px rgba(0,0,0,.05);
    --font:                -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --transition:          150ms ease;
    --color-link:          var(--color-primary);
    --focus-ring:          rgba(37,99,235,.15);
    --tint-green-bg: #d1fae5; --tint-green-fg: #065f46; --tint-green-bd: #a7f3d0;
    --tint-red-bg:   #fee2e2; --tint-red-fg:   #991b1b; --tint-red-bd:   #fca5a5;
    --tint-amber-bg: #fef3c7; --tint-amber-fg: #92400e; --tint-amber-bd: #fde68a;
    --tint-blue-bg:  #dbeafe; --tint-blue-fg:  #1e40af; --tint-blue-bd:  #bfdbfe;
    --tint-gray-bg:  #f1f5f9; --tint-gray-fg:  #475569;
    --row-overdue:   #fff5f5;
}

/* Dark theme — only admin/superadmin pages set data-theme (theme picker in the top bar,
   cookie fl_theme). "auto" follows the device setting. Public pages are unaffected. */
:root[data-theme="dark"] {
    color-scheme: dark;
    --color-primary-light: rgba(59,130,246,.16);
    --color-link:          #60a5fa;
    --color-danger-text:   #f87171;   /* red text on dark backgrounds 5.3:1 */
    --color-bg:            #0f172a;
    --color-surface:       #1e293b;
    --color-border:        #334155;
    --color-text:          #e2e8f0;
    --color-text-muted:    #94a3b8;
    --sidebar-bg:          #020617;
    --shadow:              0 1px 3px rgba(0,0,0,.4);
    --shadow-md:           0 4px 6px rgba(0,0,0,.35);
    --shadow-lg:           0 10px 15px rgba(0,0,0,.4);
    --focus-ring:          rgba(96,165,250,.3);
    --tint-green-bg: rgba(16,185,129,.15);  --tint-green-fg: #6ee7b7;  --tint-green-bd: rgba(16,185,129,.35);
    --tint-red-bg:   rgba(239,68,68,.15);   --tint-red-fg:   #fca5a5;  --tint-red-bd:   rgba(239,68,68,.35);
    --tint-amber-bg: rgba(245,158,11,.15);  --tint-amber-fg: #fcd34d;  --tint-amber-bd: rgba(245,158,11,.35);
    --tint-blue-bg:  rgba(59,130,246,.15);  --tint-blue-fg:  #93c5fd;  --tint-blue-bd:  rgba(59,130,246,.35);
    --tint-gray-bg:  rgba(148,163,184,.15); --tint-gray-fg:  #cbd5e1;
    --row-overdue:   rgba(239,68,68,.08);
}
@media (prefers-color-scheme: dark) {
    :root[data-theme="auto"] {
        color-scheme: dark;
        --color-primary-light: rgba(59,130,246,.16);
        --color-link:          #60a5fa;
        --color-danger-text:   #f87171;   /* red text on dark backgrounds 5.3:1 */
        --color-bg:            #0f172a;
        --color-surface:       #1e293b;
        --color-border:        #334155;
        --color-text:          #e2e8f0;
        --color-text-muted:    #94a3b8;
        --sidebar-bg:          #020617;
        --shadow:              0 1px 3px rgba(0,0,0,.4);
        --shadow-md:           0 4px 6px rgba(0,0,0,.35);
        --shadow-lg:           0 10px 15px rgba(0,0,0,.4);
        --focus-ring:          rgba(96,165,250,.3);
        --tint-green-bg: rgba(16,185,129,.15);  --tint-green-fg: #6ee7b7;  --tint-green-bd: rgba(16,185,129,.35);
        --tint-red-bg:   rgba(239,68,68,.15);   --tint-red-fg:   #fca5a5;  --tint-red-bd:   rgba(239,68,68,.35);
        --tint-amber-bg: rgba(245,158,11,.15);  --tint-amber-fg: #fcd34d;  --tint-amber-bd: rgba(245,158,11,.35);
        --tint-blue-bg:  rgba(59,130,246,.15);  --tint-blue-fg:  #93c5fd;  --tint-blue-bd:  rgba(59,130,246,.35);
        --tint-gray-bg:  rgba(148,163,184,.15); --tint-gray-fg:  #cbd5e1;
        --row-overdue:   rgba(239,68,68,.08);
    }
}

/* ================================================================== Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { font-family: var(--font); color: var(--color-text); background: var(--color-bg); line-height: 1.6; }
img  { max-width: 100%; display: block; }
a    { color: var(--color-link); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ================================================================== Typography */
h1 { font-size: 1.875rem; font-weight: 700; line-height: 1.2; }
h2 { font-size: 1.5rem;   font-weight: 700; line-height: 1.3; }
h3 { font-size: 1.25rem;  font-weight: 600; }
h4 { font-size: 1.125rem; font-weight: 600; }
p  { margin-bottom: .75rem; }
p:last-child { margin-bottom: 0; }

/* ================================================================== Layout helpers */
.container         { max-width: 1200px; margin: 0 auto; padding: 0 1.25rem; }
.container--narrow { max-width: 720px;  margin: 0 auto; padding: 0 1.25rem; }

/* ================================================================== Buttons */
.btn {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .5rem 1.1rem; border-radius: var(--radius); border: none; cursor: pointer;
    font-weight: 500; font-size: .925rem; line-height: 1.4; text-decoration: none;
    transition: background var(--transition), box-shadow var(--transition), opacity var(--transition);
}
.btn:hover { text-decoration: none; opacity: .92; }
.logout-form { display: inline; margin: 0; }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-decoration: underline; }
.btn:active { transform: translateY(1px); }

.btn-primary   { background: var(--color-primary); color: var(--color-on-primary, #fff); }
.btn-primary:hover { background: var(--color-primary-dark); opacity: 1; }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); opacity: 1; }
.btn-danger    { background: var(--color-danger); color: #fff; }
.btn-success   { background: var(--color-success); color: #fff; }
.btn-warning   { background: var(--color-warning); color: #451a03; }   /* dark text: 7:1 on amber */
.btn-ghost     { background: transparent; color: var(--color-link); }
.btn-ghost:hover { background: var(--color-primary-light); opacity: 1; }
.btn-sm  { padding: .3rem .75rem; font-size: .825rem; }
.btn-lg  { padding: .75rem 1.75rem; font-size: 1.05rem; }
.btn-icon { padding: .45rem; }

/* ================================================================== Cards */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-body   { padding: 1.25rem 1.5rem; }
.card-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--color-border); font-weight: 600; }
.card-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--color-border); background: var(--color-bg); }

/* ================================================================== Forms */
.form-group   { margin-bottom: 1rem; }
.form-label   { display: block; font-weight: 500; font-size: .9rem; margin-bottom: .35rem; color: var(--color-text); }
.form-control {
    display: block; width: 100%;
    padding: .55rem .85rem;
    border: 1px solid var(--color-border); border-radius: var(--radius);
    background: var(--color-surface); color: var(--color-text);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--focus-ring);
}
.form-control::placeholder { color: var(--color-text-muted); }
.form-hint { font-size: .825rem; color: var(--color-text-muted); margin-top: .3rem; }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 100px; }

.form-check { display: flex; align-items: center; gap: .5rem; }
.form-check input { width: 1rem; height: 1rem; cursor: pointer; accent-color: var(--color-primary); }

/* ================================================================== Alerts / Flash */
.alert {
    padding: .85rem 1.1rem; border-radius: var(--radius); font-size: .925rem;
    display: flex; align-items: flex-start; gap: .6rem; margin-bottom: 1rem;
}
.alert-success { background: var(--tint-green-bg); color: var(--tint-green-fg); border: 1px solid var(--tint-green-bd); }
.alert-error   { background: var(--tint-red-bg);   color: var(--tint-red-fg);   border: 1px solid var(--tint-red-bd); }
.alert-warning { background: var(--tint-amber-bg); color: var(--tint-amber-fg); border: 1px solid var(--tint-amber-bd); }
.alert-info    { background: var(--tint-blue-bg);  color: var(--tint-blue-fg);  border: 1px solid var(--tint-blue-bd); }

/* ================================================================== Tables */
.table-wrap  { overflow-x: auto; }
.table {
    width: 100%; border-collapse: collapse; font-size: .9rem;
}
.table th, .table td { padding: .7rem 1rem; text-align: left; border-bottom: 1px solid var(--color-border); }
.table th   { font-weight: 600; color: var(--color-text-muted); background: var(--color-bg); font-size: .825rem; text-transform: uppercase; letter-spacing: .04em; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--color-bg); }
.table .actions { display: flex; gap: .4rem; }

/* ================================================================== Badges */
.badge {
    display: inline-flex; align-items: center;
    padding: .2rem .6rem; border-radius: 999px;
    font-size: .75rem; font-weight: 600; letter-spacing: .02em;
}
.badge-green  { background: var(--tint-green-bg); color: var(--tint-green-fg); }
.badge-red    { background: var(--tint-red-bg);   color: var(--tint-red-fg); }
.badge-blue   { background: var(--tint-blue-bg);  color: var(--tint-blue-fg); }
.badge-yellow { background: var(--tint-amber-bg); color: var(--tint-amber-fg); }
.badge-gray   { background: var(--tint-gray-bg);  color: var(--tint-gray-fg); }

/* ================================================================== Stats row */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-lg); padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow);
}
.stat-card .stat-value { font-size: 2rem; font-weight: 700; color: var(--color-link); line-height: 1; }
.stat-card .stat-label { font-size: .825rem; color: var(--color-text-muted); margin-top: .25rem; }

/* ================================================================== Page header */
.page-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap;
}
.page-header h1 { font-size: 1.5rem; }

/* ================================================================== =====================
   PUBLIC LAYOUT
   ===================================================================================== */

/* Top nav */
.pub-nav {
    background: var(--color-primary);
    color: var(--color-on-primary, #fff);
    box-shadow: var(--shadow-md);
    position: sticky; top: 0; z-index: 100;
}
.pub-nav__inner {
    display: flex; align-items: center; justify-content: space-between;
    padding: .75rem 1.25rem; max-width: 1200px; margin: 0 auto;
}
.pub-nav__logo {
    display: flex; align-items: center; gap: .75rem;
    font-weight: 700; font-size: 1.1rem; color: var(--color-on-primary, #fff); text-decoration: none;
}
.pub-nav__logo img { height: 36px; width: auto; border-radius: 4px; }
.pub-nav__links { display: flex; align-items: center; gap: 1rem; }
.pub-nav__links a { color: var(--color-on-primary, #fff); font-size: .925rem; transition: color var(--transition); }
.pub-nav__links a:hover { color: var(--color-on-primary, #fff); text-decoration: underline; }
.pub-nav__links .btn { padding: .4rem .9rem; font-size: .875rem; }
.pub-nav__toggle { display: none; background: none; border: none; cursor: pointer; color: var(--color-on-primary, #fff); padding: .25rem; }

/* Hero */
.pub-hero {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
    color: var(--color-on-primary, #fff); padding: 3.5rem 1.25rem 3rem;
}
.pub-hero__inner { max-width: 1200px; margin: 0 auto; }
.pub-hero__logo  { height: 60px; margin-bottom: 1rem; border-radius: 8px; }
.pub-hero h1     { font-size: 2.25rem; margin-bottom: .5rem; }
.pub-hero p      { opacity: .88; font-size: 1.1rem; max-width: 560px; }
.pub-hero__meta  { margin-top: 1rem; font-size: .9rem; opacity: .8; display: flex; gap: 1.5rem; flex-wrap: wrap; }

/* Main content area */
.pub-main { padding: 2.5rem 1.25rem; max-width: 1200px; margin: 0 auto; }

/* Section headings */
.section-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 1.25rem; display: flex; align-items: center; gap: .5rem; }
.section-title::after { content: ''; flex: 1; height: 2px; background: var(--color-border); border-radius: 2px; }

/* News cards */
.news-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.25rem; margin-bottom: 2.5rem; }
.news-card {
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow);
    transition: box-shadow var(--transition), transform var(--transition);
}
.news-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.news-card__img  { width: 100%; height: 160px; object-fit: cover; }
.news-card__body { padding: 1rem 1.25rem; }
.news-card__date { font-size: .8rem; color: var(--color-text-muted); margin-bottom: .4rem; }
.news-card__title { font-size: 1.05rem; font-weight: 600; margin-bottom: .5rem; }
.news-card__excerpt { font-size: .9rem; color: var(--color-text-muted); }
.news-card__tag  { display: inline-block; font-size: .75rem; padding: .15rem .5rem; border-radius: 4px; margin-bottom: .5rem; }
.news-card__tag--global { background: var(--tint-blue-bg); color: var(--tint-blue-fg); }
.news-card__tag--local  { background: var(--color-primary-light); color: var(--color-primary-dark); }

/* Product grid */
.product-filters { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1.5rem; align-items: center; }
.filter-btn {
    padding: .4rem 1rem; border-radius: 999px; border: 1.5px solid var(--color-border);
    background: var(--color-surface); font-size: .875rem; cursor: pointer; font-weight: 500;
    transition: all var(--transition); color: var(--color-text);
}
.filter-btn:hover, .filter-btn.active {
    background: var(--color-primary); color: var(--color-on-primary, #fff); border-color: var(--color-primary);
}
.product-search { display: flex; gap: .5rem; margin-bottom: 1rem; }
.product-search .form-control { max-width: 320px; }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1.25rem; }
.product-card {
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow);
    transition: box-shadow var(--transition), transform var(--transition);
    display: flex; flex-direction: column;
}
.product-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.product-card__img  {
    width: 100%; height: 180px; object-fit: cover;
    background: var(--color-bg);
}
.product-card__img-placeholder {
    width: 100%; height: 180px; display: flex; align-items: center; justify-content: center;
    background: var(--color-bg); color: var(--color-text-muted); font-size: 2.5rem;
}
.product-card__body { padding: .9rem 1rem; flex: 1; }
.product-card__id   { font-size: .75rem; color: var(--color-text-muted); margin-bottom: .2rem; }
.product-card__name { font-weight: 600; font-size: .975rem; margin-bottom: .3rem; }
.product-card__meta { font-size: .825rem; color: var(--color-text-muted); }
.product-card__status { padding: .5rem 1rem; border-top: 1px solid var(--color-border); }
.product-card--loaned { opacity: .6; }

/* Footer */
.pub-footer {
    background: var(--color-surface); border-top: 1px solid var(--color-border);
    padding: 2rem 1.25rem; margin-top: 3rem; color: var(--color-text-muted); font-size: .875rem;
}
.pub-footer__inner { max-width: 1200px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; }

/* My loans lookup */
.lookup-form { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 2rem; max-width: 480px; margin: 2rem auto; box-shadow: var(--shadow-md); }
.loan-result-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); margin-bottom: 1.5rem; overflow: hidden; box-shadow: var(--shadow); }
.loan-result-card__header { padding: 1rem 1.25rem; background: var(--color-primary-light); border-bottom: 1px solid var(--color-border); }
.loan-result-card__products { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; padding: 1.25rem; }
.loan-product-item { display: flex; gap: .75rem; align-items: center; }
.loan-product-item img { width: 60px; height: 60px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.loan-product-item .info .name { font-weight: 600; font-size: .9rem; }
.loan-product-item .info .meta { font-size: .8rem; color: var(--color-text-muted); }

/* Home — location cards */
.location-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.5rem; margin-top: 2rem; }
.location-card {
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow);
    transition: box-shadow var(--transition), transform var(--transition);
    display: flex; flex-direction: column;
}
.location-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-3px); text-decoration: none; }
.location-card__color-bar { height: 5px; }
.location-card__body { padding: 1.5rem; flex: 1; display: flex; flex-direction: column; }
.location-card__logo { width: 48px; height: 48px; object-fit: contain; margin-bottom: .75rem; border-radius: 8px; }
.location-card__name { font-size: 1.1rem; font-weight: 700; margin-bottom: .3rem; }
.location-card__city { font-size: .875rem; color: var(--color-text-muted); margin-bottom: .75rem; }
.location-card__cta  { margin-top: auto; }

/* ================================================================== =====================
   ADMIN LAYOUT
   ===================================================================================== */

.admin-wrap { display: flex; min-height: 100vh; }

/* Sidebar */
.admin-sidebar {
    width: var(--sidebar-width); background: var(--sidebar-bg);
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; height: 100vh; overflow-y: auto;
    z-index: 200;
    transition: transform var(--transition);
}
.admin-sidebar__head {
    padding: 1.25rem 1.5rem; display: flex; align-items: center; gap: .75rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.admin-sidebar__head img { height: 36px; width: auto; border-radius: 6px; }
.admin-sidebar__title { font-weight: 700; color: #fff; font-size: .95rem; line-height: 1.3; }
.admin-sidebar__subtitle { font-size: .75rem; color: var(--sidebar-text); }

.admin-sidebar__nav  { flex: 1; padding: .75rem 0; }
.admin-sidebar__nav a {
    display: flex; align-items: center; gap: .65rem;
    padding: .6rem 1.5rem; color: var(--sidebar-text); font-size: .9rem;
    transition: background var(--transition), color var(--transition);
    text-decoration: none; border-left: 3px solid transparent;
}
.admin-sidebar__nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.admin-sidebar__nav a.active { background: rgba(255,255,255,.1); color: var(--sidebar-active); border-left-color: var(--color-primary); font-weight: 600; }
.admin-sidebar__nav .nav-section { padding: .75rem 1.5rem .35rem; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: rgba(255,255,255,.7); }   /* was .35 (3.2:1) */
.admin-sidebar__footer {
    padding: .75rem 1.5rem 1rem; border-top: 1px solid rgba(255,255,255,.08);
    font-size: .825rem; color: var(--sidebar-text);
}
.admin-sidebar__footer a { color: var(--sidebar-text); }
.admin-sidebar__footer a:hover { color: #fff; }

/* Main content */
.admin-content { margin-left: var(--sidebar-width); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.admin-topbar {
    background: var(--color-surface); border-bottom: 1px solid var(--color-border);
    padding: .75rem 1.5rem; display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow);
}
.admin-topbar__toggle { display: none; background: none; border: none; cursor: pointer; color: var(--color-text); padding: .25rem; }
.admin-topbar__breadcrumb { font-size: .9rem; color: var(--color-text-muted); }
.admin-topbar__breadcrumb strong { color: var(--color-text); }
.admin-topbar__user { display: flex; align-items: center; gap: .75rem; }
.admin-topbar__username { font-size: .875rem; font-weight: 500; }
.theme-select {
    padding: .3rem .5rem; border: 1px solid var(--color-border); border-radius: var(--radius);
    background: var(--color-surface); color: var(--color-text); font-size: .825rem; cursor: pointer;
}

/* Quill (news editor) follows the theme */
.ql-toolbar.ql-snow, .ql-container.ql-snow { border-color: var(--color-border) !important; }
.ql-snow .ql-stroke { stroke: var(--color-text-muted) !important; }
.ql-snow .ql-fill { fill: var(--color-text-muted) !important; }
.ql-snow .ql-picker { color: var(--color-text-muted) !important; }
.ql-snow .ql-picker-options { background: var(--color-surface) !important; }
.ql-editor.ql-blank::before { color: var(--color-text-muted) !important; }

.admin-inner { padding: 1.5rem; flex: 1; }

/* ================================================================== Superadmin overrides */
.superadmin-layout .admin-sidebar { background: #312e81; }
.superadmin-layout .admin-sidebar__nav a.active { border-left-color: #818cf8; }

/* ================================================================== Auth page */
.auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
    padding: 1.5rem;
}
.auth-card {
    background: var(--color-surface); border-radius: var(--radius-lg);
    padding: 2.5rem; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg);
}
.auth-card__logo { height: 52px; margin: 0 auto 1.25rem; display: block; }
.auth-card__title { text-align: center; margin-bottom: .5rem; }
.auth-card__subtitle { text-align: center; color: var(--color-text-muted); font-size: .9rem; margin-bottom: 1.75rem; }

/* ================================================================== Loan session builder */
.session-builder { display: grid; grid-template-columns: 1fr 360px; gap: 1.5rem; }
.session-builder__main {}
.session-builder__sidebar {}

.product-finder { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.product-finder__result { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1rem; margin-top: .75rem; display: none; }
.product-finder__result.visible { display: flex; gap: 1rem; align-items: center; }
.product-finder__result img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.product-finder__result .info { flex: 1; }
.product-finder__result .info .name { font-weight: 600; }
.product-finder__result .info .meta { font-size: .85rem; color: var(--color-text-muted); }

.session-info { background: var(--color-primary-light); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 1.25rem; }
.session-info__name  { font-size: 1.25rem; font-weight: 700; }
.session-info__phone { color: var(--color-text-muted); font-size: .9rem; }
.session-info__dates { margin-top: .75rem; font-size: .875rem; display: flex; gap: 1.25rem; flex-wrap: wrap; }
.session-info__dates span { color: var(--color-text-muted); }
.session-info__dates strong { color: var(--color-text); }

.loan-items-list { display: flex; flex-direction: column; gap: .75rem; margin-top: 1rem; }
.loan-item {
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius); padding: .85rem 1rem;
    display: flex; align-items: center; gap: .85rem;
}
.loan-item img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.loan-item .img-placeholder { width: 56px; height: 56px; background: var(--color-bg); border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0; }
.loan-item .info { flex: 1; }
.loan-item .info .name { font-weight: 600; font-size: .925rem; }
.loan-item .info .meta { font-size: .8rem; color: var(--color-text-muted); }

/* ================================================================== Overdue row */
tr.overdue td { background: var(--row-overdue) !important; }
tr.overdue .badge-overdue { background: var(--tint-red-bg); color: var(--tint-red-fg); }

/* ================================================================== Two-column grid (collapses on mobile) */
.two-col-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ================================================================== Responsive */
@media (max-width: 1024px) {
    .session-builder { grid-template-columns: 1fr; }
    .session-builder__sidebar { order: -1; }
}

@media (max-width: 768px) {
    .admin-sidebar { transform: translateX(-100%); }
    .admin-sidebar.open { transform: translateX(0); }
    .admin-content { margin-left: 0; }
    .admin-topbar__toggle { display: flex; }
    .admin-topbar__username { display: none; }

    .pub-nav__links { display: none; flex-direction: column; position: absolute; top: 100%; left: 0; right: 0; background: var(--color-primary); padding: 1rem; }
    .pub-nav__links.open { display: flex; }
    .pub-nav__toggle { display: flex; }
    .pub-nav { position: relative; }

    .pub-hero h1 { font-size: 1.75rem; }
    .product-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .two-col-grid { grid-template-columns: 1fr; }
    h1 { font-size: 1.5rem; }

    /* Större klickytor på touch */
    .btn { min-height: 44px; }
    .btn-sm { min-height: 36px; }
}

@media (max-width: 480px) {
    .product-grid { grid-template-columns: repeat(2, 1fr); }
    .admin-inner { padding: 1rem; }
    .card-body { padding: 1rem; }
    .card-header { padding: .75rem 1rem; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .page-header { flex-direction: column; align-items: flex-start; }
    .admin-topbar { padding: .6rem 1rem; }
    .form-control { font-size: 16px; } /* Förhindrar auto-zoom på iOS */
}

/* ================================================================== Overlay (mobile sidebar) */
.sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 199;
}
.sidebar-overlay.active { display: block; }

/* ================================================================== Rich content (news articles) */
.rich-content { line-height: 1.8; font-size: 1rem; }
.rich-content p { margin-bottom: 1rem; }
.rich-content ul, .rich-content ol { margin-bottom: 1rem; padding-left: 1.5rem; }
.rich-content li { margin-bottom: .35rem; }
.rich-content h3 { margin: 1.5rem 0 .75rem; }
.rich-content h4 { margin: 1.25rem 0 .5rem; }
.rich-content blockquote { border-left: 4px solid var(--color-primary); padding: .5rem 1rem; margin: 1rem 0; background: var(--color-bg); border-radius: 0 var(--radius) var(--radius) 0; }
.rich-content a { color: var(--color-link); text-decoration: underline; }
.rich-content strong, .rich-content b { font-weight: 700; }

/* ================================================================== Utilities */
.text-muted   { color: var(--color-text-muted); }
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-sm      { font-size: .875rem; }
.text-xs      { font-size: .8rem; }
.font-bold    { font-weight: 700; }
.mt-1  { margin-top: .25rem; }
.mt-2  { margin-top: .5rem; }
.mt-3  { margin-top: .75rem; }
.mt-4  { margin-top: 1rem; }
.mt-6  { margin-top: 1.5rem; }
.mb-2  { margin-bottom: .5rem; }
.mb-4  { margin-bottom: 1rem; }
.mb-6  { margin-bottom: 1.5rem; }
.flex  { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.grid  { display: grid; }
.w-full { width: 100%; }
.d-none { display: none; }

/* Visitor "+" buttons: press effect (was inline onmousedown, which the CSP blocks) */
#dashboard-visitor-btn:active, #visitor-btn:active { transform: scale(.93); }

/* Privacy policy, loan terms, accessibility statement (Services\Documents) */
.legal-text h2 { font-size: 1.15rem; margin: 1.75rem 0 .5rem; }
.legal-text h2:first-child { margin-top: 0; }
.legal-text h3 { font-size: 1rem; }
.legal-text mark { background: var(--tint-amber-bg); color: var(--tint-amber-fg); padding: 0 .2em; border-radius: 3px; }
#doc-editor .ql-editor { font-size: 1rem; line-height: 1.6; min-height: 320px; }
#doc-editor .ql-editor p, #doc-editor .ql-editor ul { margin-bottom: .6rem; }

/* Lending: what the borrower was told (privacy policy, loan terms) */
.desk-confirm { border: 1px solid var(--color-border); border-radius: var(--radius); padding: .75rem 1rem; margin: 0 0 1rem; }
.desk-confirm legend { padding: 0 .35rem; }
.desk-confirm .form-check { display: flex; gap: .6rem; align-items: flex-start; margin-bottom: .6rem; line-height: 1.45; }
.desk-confirm .form-check input { margin-top: .2rem; width: 1.1rem; height: 1.1rem; flex-shrink: 0; }
.required-mark { color: var(--color-danger-text); }

/* Visually hidden, still read by screen readers */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* "Hoppa till innehållet": first tab stop on every page, visible only when focused (WCAG 2.4.1) */
.skip-link { position: absolute; left: .75rem; top: -4rem; z-index: 1000; padding: .6rem 1rem; border-radius: var(--radius);
             background: var(--color-surface); color: var(--color-text); font-weight: 600; box-shadow: 0 2px 10px rgba(0,0,0,.25); }
.skip-link:focus { top: .75rem; outline: 3px solid var(--color-primary); outline-offset: 2px; }
main[tabindex="-1"]:focus { outline: none; }

/* Links inside coloured notices take the notice's text colour (blue on light blue was 4.2:1) */
.alert a { color: inherit; text-decoration: underline; font-weight: 600; }

/* 200 % zoom (WCAG 1.4.10): a wide table scrolls inside its .table-wrap, not the whole page */
.admin-content, .admin-inner { min-width: 0; }
.card { max-width: 100%; }

/* Keyboard focus (WCAG 2.4.7): a clear 3 px ring on everything you can tab to.
   Mouse clicks don't show it (:focus-visible). Light: dark blue, dark theme: light blue, sidebar: white. */
:root { --focus-outline: #1d4ed8; }
:root[data-theme="dark"] { --focus-outline: #93c5fd; }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] { --focus-outline: #93c5fd; } }
a:focus-visible, button:focus-visible, .btn:focus-visible, summary:focus-visible, select:focus-visible,
input:focus-visible, textarea:focus-visible, .form-control:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible { outline: 3px solid var(--focus-outline); outline-offset: 2px; }
.admin-sidebar :focus-visible { outline-color: #fff; outline-offset: -3px; }

/* Logout warning (assets/js/app.js initIdleWarning) */
.idle-warning { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 1000; max-width: min(92vw, 30rem);
                display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; padding: 1rem 1.25rem; border-radius: var(--radius-lg, 12px);
                background: var(--color-surface); color: var(--color-text); border: 2px solid var(--color-warning); box-shadow: 0 8px 30px rgba(0,0,0,.3); }
.idle-warning p { margin: 0; flex: 1 1 14rem; }
