:root {
    --red: #C0253A;
    --red-dark: #9B1C2D;
    --red-light: #F8E8EB;
    --slate: #1E293B;
    --slate-2: #334155;
    --muted: #64748B;
    --border: #E2E8F0;
    --bg: #F8FAFC;
    --white: #FFFFFF;
    --green: #16A34A;
    --amber: #D97706;
    --danger: #DC2626;
    --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--slate);
    font-size: 14px;
}

/* ── Layout ── */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 220px;
    background: var(--slate);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}

.sidebar-logo {
    padding: 1.1rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: .75rem;
}

.sidebar-logo img { width: 34px; height: 34px; object-fit: contain; }
.sidebar-logo-name { color: #fff; font-weight: 700; font-size: .9rem; line-height: 1.2; }
.sidebar-logo-sub  { display: block; font-size: .6rem; color: rgba(255,255,255,.4); text-transform: uppercase; letter-spacing: .05em; }

.sidebar-nav { flex: 1; padding: .5rem 0; overflow-y: auto; }
.nav-group-label { padding: .5rem 1rem .2rem; font-size: .6rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: rgba(255,255,255,.3); }

.nav-item {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .5rem 1rem;
    margin: 1px .5rem;
    border-radius: 6px;
    font-size: .8rem;
    color: rgba(255,255,255,.65);
    text-decoration: none;
    transition: background .12s, color .12s;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--red); color: #fff; }
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; }

.sidebar-footer {
    padding: .75rem 1rem;
    border-top: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: .6rem;
}
.avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--red);
    display: flex; align-items: center; justify-content: center;
    font-size: .68rem; font-weight: 700; color: #fff;
    flex-shrink: 0;
}
.user-name { font-size: .73rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .62rem; color: rgba(255,255,255,.4); }

.main-wrap { margin-left: 220px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    padding: .8rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-title { font-size: .95rem; font-weight: 700; }
.topbar-sub   { font-size: .72rem; color: var(--muted); }

.page-content { padding: 1.5rem; flex: 1; }

/* ── Cards ── */
.card { background: var(--white); border-radius: var(--radius); border: 1px solid var(--border); }
.card-header { padding: .75rem 1rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: .82rem; font-weight: 700; }
.card-body { padding: 1rem; }

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .4rem .85rem;
    border-radius: 6px;
    font-size: .78rem; font-weight: 600;
    cursor: pointer;
    border: none;
    transition: opacity .12s;
    text-decoration: none;
    line-height: 1.4;
}
.btn:hover { opacity: .88; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--red); color: #fff; }
.btn-secondary { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-danger    { background: #FEE2E2; color: var(--danger); }
.btn-success   { background: #DCFCE7; color: var(--green); }
.btn-sm { padding: .25rem .55rem; font-size: .72rem; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .8rem; }
thead th { padding: .45rem .75rem; text-align: left; font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--bg); border-bottom: 1px solid var(--border); }
tbody td { padding: .5rem .75rem; border-bottom: 1px solid var(--border); color: var(--slate-2); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f9fafb; }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: .25rem; padding: .15rem .5rem; border-radius: 20px; font-size: .67rem; font-weight: 700; }
.badge-green  { background: #DCFCE7; color: var(--green); }
.badge-amber  { background: #FEF3C7; color: var(--amber); }
.badge-red    { background: var(--red-light); color: var(--red); }
.badge-blue   { background: #DBEAFE; color: #2563EB; }
.badge-gray   { background: #F1F5F9; color: var(--muted); }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .75rem; font-weight: 600; margin-bottom: .35rem; color: var(--slate-2); }
.form-control {
    width: 100%;
    padding: .45rem .7rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .82rem;
    color: var(--slate);
    background: var(--white);
    transition: border-color .12s;
}
.form-control:focus { outline: none; border-color: var(--red); }
select.form-control { cursor: pointer; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* ── Alerts ── */
.alert { padding: .65rem 1rem; border-radius: 6px; font-size: .8rem; margin-bottom: 1rem; }
.alert-error   { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.alert-success { background: #DCFCE7; color: #166534; border: 1px solid #BBF7D0; }
.alert-info    { background: #DBEAFE; color: #1E40AF; border: 1px solid #BFDBFE; }

/* ── Modal ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--white); border-radius: 10px; width: 480px; max-width: 95vw; max-height: 90vh; overflow-y: auto; box-shadow: 0 8px 40px rgba(0,0,0,.18); }
.modal-header { padding: .85rem 1.1rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h4 { font-size: .9rem; font-weight: 700; }
.modal-body   { padding: 1.1rem; }
.modal-footer { padding: .75rem 1.1rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; }
.modal-close  { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--muted); line-height: 1; }

/* ── Notification toast ── */
#toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 999; display: flex; flex-direction: column; gap: .5rem; }
.toast { padding: .65rem 1rem; border-radius: 6px; font-size: .8rem; font-weight: 600; color: #fff; min-width: 220px; box-shadow: 0 4px 12px rgba(0,0,0,.15); animation: slideIn .18s ease; }
.toast-success { background: var(--green); }
.toast-error   { background: var(--danger); }
.toast-info    { background: #2563EB; }
@keyframes slideIn { from { transform: translateX(120%); opacity:0; } to { transform: translateX(0); opacity:1; } }

/* ── Impersonation banner ── */
.impersonate-bar { background: var(--amber); color: #fff; font-size: .75rem; font-weight: 700; padding: .4rem 1.5rem; display: flex; align-items: center; justify-content: space-between; }

/* ── Stat cards ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.stat-card { background: var(--white); border-radius: var(--radius); border: 1px solid var(--border); padding: 1rem; border-left: 3px solid var(--red); }
.stat-label { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stat-val   { font-size: 1.8rem; font-weight: 800; line-height: 1; margin: .2rem 0; }
.stat-sub   { font-size: .68rem; color: var(--muted); }

/* ── Utilities ── */
.text-muted   { color: var(--muted); }
.text-sm      { font-size: .75rem; }
.text-right   { text-align: right; }
.flex         { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2        { gap: .5rem; }
.gap-3        { gap: .75rem; }
.mt-1         { margin-top: .25rem; }
.mt-3         { margin-top: .75rem; }
.mb-3         { margin-bottom: .75rem; }
.hidden       { display: none !important; }

/* ── Scoring Builder ── */
.sb-row {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    padding: .5rem;
    border-radius: 6px;
    margin-bottom: .35rem;
    background: #f8fafc;
    border: 1px solid var(--border);
}
.sb-section { background: #f1f5f9; border-color: #cbd5e1; }
.sb-type-badge {
    font-size: .6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: .2rem .4rem;
    border-radius: 4px;
    background: var(--slate-2);
    color: #fff;
    white-space: nowrap;
    flex-shrink: 0;
    margin-top: .4rem;
}
.sb-lvl2 { background: var(--red); }
.sb-name { flex: 1; min-width: 0; }
.sb-points { display: flex; gap: .3rem; flex-shrink: 0; }
.sb-point-input {
    width: 44px;
    padding: .35rem .4rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: .75rem;
    text-align: center;
    background: var(--white);
}
.sb-point-input:focus { outline: none; border-color: var(--red); }
.sb-point-label {
    font-size: .6rem;
    color: var(--muted);
    text-align: center;
    width: 44px;
    flex-shrink: 0;
}
.sb-actions { display: flex; gap: .2rem; flex-shrink: 0; }
.sb-actions button {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    width: 26px;
    height: 26px;
    cursor: pointer;
    font-size: .75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    margin-top: .18rem;
}
.sb-actions button:hover { background: var(--border); color: var(--slate); }
.sb-del { color: var(--danger) !important; }
.sb-del:hover { background: #fee2e2 !important; }
.sb-toolbar { display: flex; gap: .5rem; margin-bottom: .75rem; }
.sb-point-headers { display: flex; gap: .3rem; justify-content: flex-end; margin-bottom: .2rem; padding-right: calc(26px*3 + .4rem*2 + .5rem); }

/* ── Scoring form ── */
.score-block {
    margin: .3rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    overflow: hidden;
    margin-bottom: .35rem;
}
.score-section {
    font-size: .6rem; font-weight: 800; text-transform: uppercase;
    letter-spacing: .08em; color: var(--red);
    padding: .35rem .75rem;
    background: #fff5f5;
    border-top: 2px solid #fecdd3;
    border-bottom: 1px solid #fecdd3;
}
.score-subsection {
    padding: .2rem .65rem;
    font-size: .65rem; color: var(--muted); font-style: italic;
    background: #fcfcfd; border-bottom: 1px solid #f8fafc;
}
.score-row {
    display: flex; flex-direction: column;
    padding: .22rem .65rem;
    border-bottom: 1px solid #f1f5f9;
}
.score-row:last-child { border-bottom: none; }
.score-row-top { display: flex; align-items: center; gap: .5rem; min-height: 30px; }
.score-row-neg { border-left: 3px solid var(--danger); padding-left: calc(.65rem - 3px); }
.score-row-name { flex: 1; font-size: .72rem; color: var(--slate-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score-btns { display: flex; flex-wrap: nowrap; gap: 3px; flex-shrink: 0; }
.score-btn {
    width: 28px; height: 24px; padding: 0;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--white);
    font-size: .74rem; font-weight: 700;
    cursor: pointer; transition: background .1s, color .1s;
}
.score-btn:hover { background: var(--bg); }
.score-btn.selected { background: var(--red); color: #fff; border-color: var(--red-dark); }
.score-btn-neg.selected { background: var(--danger); border-color: #b91c1c; }
.score-comment { margin-top: .25rem; }
.score-cmt-btn {
    background: none; border: none; cursor: pointer; flex-shrink: 0;
    font-size: .78rem; padding: 0 .15rem; line-height: 1;
    color: #fca5a5; transition: color .15s;
}
.score-cmt-btn:hover { color: #f87171; }
.score-cmt-btn.has-comment { color: #c0253a; }
.score-total-bar {
    display: flex; align-items: center; gap: 1rem;
    padding: .6rem 1rem; background: var(--slate); color: #fff;
    border-radius: var(--radius); font-size: .85rem; font-weight: 700;
    margin-bottom: 1rem;
}
.score-total-val { font-size: 1.4rem; font-weight: 800; }
.score-progress { height: 6px; background: rgba(255,255,255,.2); border-radius: 3px; flex: 1; }
.score-progress-bar { height: 100%; background: var(--green); border-radius: 3px; transition: width .3s; }

/* ── Score SPA (subuser tablica) ── */
.spa-shell { display: flex; flex-direction: column; min-height: 100vh; background: var(--bg); }
.spa-header {
    background: var(--slate); color: #fff; padding: .75rem 1rem;
    font-size: .9rem; font-weight: 700; display: flex; align-items: center;
    justify-content: space-between;
}
.spa-body { flex: 1; padding: 1rem; max-width: 700px; margin: 0 auto; width: 100%; }
.selector-card { background: var(--white); border-radius: var(--radius); border: 1px solid var(--border); padding: 1rem; margin-bottom: 1rem; }
.selector-card label { display: block; font-size: .72rem; font-weight: 700; margin-bottom: .4rem; color: var(--muted); text-transform: uppercase; }
.sync-badge { font-size: .65rem; padding: .15rem .4rem; border-radius: 10px; font-weight: 700; }
.sync-ok     { background: #dcfce7; color: var(--green); }
.sync-pending { background: #fef3c7; color: var(--amber); }
.sync-error  { background: #fee2e2; color: var(--danger); }
