:root {
    --sab-dark: #28292b;
    --sab-dark-2: #1f2022;
    --sab-green: #a6c532;
    --sab-green-bright: #b8d63a;
    --sab-green-dark: #78921c;
    --sab-white: #f2f2f2;
    --text: #f4f4f4;
    --muted: rgba(242, 242, 242, 0.70);
    --line: rgba(255, 255, 255, 0.16);
    --glass: rgba(255, 255, 255, 0.08);
    --glass-strong: rgba(255, 255, 255, 0.13);
    --glass-soft: rgba(255, 255, 255, 0.055);
    --danger: #d65353;
    --danger-dark: #b73d3d;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
    --shadow-soft: 0 16px 42px rgba(0, 0, 0, 0.24);
    --radius: 26px;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at 14% 8%, rgba(166, 197, 50, 0.22), transparent 31%),
        radial-gradient(circle at 88% 16%, rgba(242, 242, 242, 0.10), transparent 26%),
        radial-gradient(circle at 76% 92%, rgba(166, 197, 50, 0.16), transparent 30%),
        linear-gradient(135deg, var(--sab-dark-2) 0%, var(--sab-dark) 52%, #303133 100%);
    background-attachment: fixed;
}

body.app-body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: url('/static/sab-logo-bg.png');
    background-repeat: no-repeat;
    background-position: center 44%;
    background-size: 700px auto;
    opacity: 0.055;
    pointer-events: none;
    z-index: -1;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }

.glass-card {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.055));
    border: 1px solid var(--line);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(22px) saturate(135%);
    -webkit-backdrop-filter: blur(22px) saturate(135%);
}

.topbar {
    width: min(1180px, calc(100% - 32px));
    min-height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 14px 20px;
    margin: 16px auto 0;
    border-radius: 24px;
    position: sticky;
    top: 16px;
    z-index: 10;
    overflow: hidden;
    isolation: isolate;
    transform: translateZ(0);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    font-weight: 900;
    letter-spacing: -0.02em;
}

.brand-mark,
.login-logo-text {
    min-width: 62px;
    height: 42px;
    border-radius: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--sab-green-bright), var(--sab-green));
    color: var(--sab-dark-2);
    font-weight: 1000;
    box-shadow: 0 14px 28px rgba(166, 197, 50, 0.28);
}

.brand-text { font-size: 16px; color: var(--sab-white); }
.userbar { display: flex; align-items: center; gap: 18px; color: var(--muted); }
.userbar form { margin: 0; }

.container { width: min(1180px, calc(100% - 32px)); margin: 34px auto 56px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 24px; }
.hero-card { border-radius: 32px; padding: clamp(24px, 4vw, 42px); }

h1 { margin: 0; font-size: clamp(32px, 4vw, 52px); line-height: 1.04; letter-spacing: -0.045em; }
h2 { margin: 0; font-size: 24px; letter-spacing: -0.025em; }
.eyebrow { margin: 0 0 10px; color: var(--sab-green-bright); font-weight: 900; text-transform: uppercase; font-size: 12px; letter-spacing: 0.14em; }
.muted { color: var(--muted); line-height: 1.55; }
.head-actions { display: flex; gap: 10px; }

.btn {
    border: 1px solid transparent;
    border-radius: 16px;
    padding: 12px 18px;
    cursor: pointer;
    font-weight: 900;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform .14s ease, background .14s ease, box-shadow .14s ease, border-color .14s ease, opacity .14s ease;
    white-space: nowrap;
}
.btn:hover { transform: none; }
.btn-primary {
    background: linear-gradient(135deg, var(--sab-green-bright), var(--sab-green));
    color: var(--sab-dark-2);
    box-shadow: 0 14px 28px rgba(166, 197, 50, 0.24);
}
.btn-primary:hover { background: linear-gradient(135deg, #c3e248, var(--sab-green-bright)); }
.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--sab-white);
    border-color: rgba(255, 255, 255, 0.14);
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.13); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-dark); }
.btn-full { width: 100%; }
.btn-small { padding: 9px 12px; border-radius: 12px; font-size: 13px; }

.alert {
    padding: 14px 16px;
    border-radius: 18px;
    margin-bottom: 18px;
    color: var(--sab-white);
}
.alert-error {
    background: rgba(214, 83, 83, 0.15);
    color: #ffdede;
    border-color: rgba(214, 83, 83, 0.36);
}

.login-body {
    display: grid;
    place-items: center;
    padding: 24px;
    overflow: hidden;
    position: relative;
}
.login-body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: url('/static/sab-logo-bg.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: 700px auto;
    opacity: 0.34;
    filter: drop-shadow(0 24px 55px rgba(0, 0, 0, .36));
    pointer-events: none;
}
.login-body::after {
    content: "";
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at center, rgba(31, 32, 34, 0.10), rgba(31, 32, 34, 0.76) 68%);
    pointer-events: none;
}
.login-page {
    width: min(430px, 100%);
    position: relative;
    z-index: 1;
}
.login-card {
    border-radius: 34px;
    padding: clamp(26px, 5vw, 38px);
    box-shadow: var(--shadow);
}
.login-brand {
    display: flex;
    align-items: center;
    gap: 13px;
    margin-bottom: 28px;
    color: var(--sab-white);
    font-weight: 800;
    line-height: 1.2;
}
.login-card h1 { font-size: clamp(34px, 7vw, 46px); margin-bottom: 4px; }
.form-stack { display: grid; gap: 16px; margin-top: 28px; }
.form-stack label, .create-client-form label, .client-select {
    display: grid;
    gap: 8px;
    font-weight: 900;
    color: var(--sab-white);
}
input[type="text"], input[type="password"], select {
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.09);
    color: var(--sab-white);
    padding: 13px 15px;
    outline: none;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
}
select {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    padding-right: 44px;
}
input::placeholder { color: rgba(242, 242, 242, 0.45); }
select option { color: #1f2022; }
input[type="text"]:focus, input[type="password"]:focus, select:focus {
    border-color: rgba(166, 197, 50, 0.78);
    box-shadow: 0 0 0 4px rgba(166, 197, 50, 0.14);
}

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.folders-section { margin-top: 22px; }
.folder-card {
    min-height: 178px;
    border-radius: var(--radius);
    padding: 22px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
.folder-card:hover {
    transform: translateY(-4px);
    border-color: rgba(166, 197, 50, 0.50);
    box-shadow: var(--shadow);
    background: linear-gradient(135deg, rgba(166, 197, 50, 0.15), rgba(255, 255, 255, 0.075));
}
.folder-card strong { font-size: 19px; line-height: 1.25; }
.folder-card span:last-child { color: var(--muted); }
.folder-card-accent { background: linear-gradient(135deg, rgba(166, 197, 50, 0.18), rgba(255, 255, 255, 0.075)); }
.folder-card-muted { opacity: .86; }
.folder-icon { font-size: 40px; }

.panel {
    border-radius: var(--radius);
    padding: 22px;
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-note {
    color: var(--sab-white);
    background: rgba(166, 197, 50, 0.12);
    border: 1px solid rgba(166, 197, 50, 0.28);
    border-radius: 999px;
    padding: 8px 12px;
    font-weight: 800;
}
.admin-create-panel { margin-bottom: 22px; }
.create-client-form { display: grid; grid-template-columns: 1.1fr .8fr .8fr auto; gap: 12px; align-items: end; }
.upload-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.client-select { min-width: 280px; }
.select-wrap {
    position: relative;
    display: block;
}
.select-wrap::after {
    content: "";
    position: absolute;
    right: 16px;
    top: 50%;
    width: 9px;
    height: 9px;
    border-right: 2px solid var(--sab-green-bright);
    border-bottom: 2px solid var(--sab-green-bright);
    transform: translateY(-65%) rotate(45deg);
    pointer-events: none;
}
.custom-file-input {
    position: relative;
    min-width: 340px;
    min-height: 49px;
    border: 1px dashed rgba(166, 197, 50, 0.55);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.075);
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 6px;
    overflow: hidden;
    cursor: pointer;
}
.custom-file-input:hover {
    border-color: rgba(166, 197, 50, 0.85);
    background: rgba(166, 197, 50, 0.11);
}
.custom-file-input input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}
.file-input-label {
    border-radius: 12px;
    padding: 10px 14px;
    background: linear-gradient(135deg, var(--sab-green-bright), var(--sab-green));
    color: var(--sab-dark-2);
    font-weight: 1000;
    white-space: nowrap;
}
.file-input-name {
    color: var(--muted);
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.table-actions { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(0,0,0,0.10);
}
.data-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.data-table th, .data-table td { padding: 14px 15px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.data-table th {
    background: rgba(255, 255, 255, 0.08);
    color: var(--sab-white);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.data-table th[data-sort-dir="asc"]::after { content: " ↑"; color: var(--sab-green-bright); }
.data-table th[data-sort-dir="desc"]::after { content: " ↓"; color: var(--sab-green-bright); }
.data-table th.check-cell { cursor: default; width: 48px; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: rgba(255, 255, 255, 0.045); }
.check-cell { width: 48px; text-align: center !important; }
.actions-cell { cursor: default !important; }
.empty { text-align: center !important; color: var(--muted); padding: 32px !important; }
.delete-form { margin-top: 14px; }
.clients-table input { min-width: 180px; }
.client-row-form { margin: 0; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.clients-table .row-actions .btn { min-width: 108px; }
.clients-table .row-actions form .btn { width: 108px; }

.dialog {
    width: min(540px, calc(100% - 32px));
    border: 1px solid var(--line);
    border-radius: 26px;
    padding: 26px;
    color: var(--sab-white);
    background: rgba(40, 41, 43, 0.88);
    box-shadow: var(--shadow);
    backdrop-filter: blur(22px) saturate(135%);
    -webkit-backdrop-filter: blur(22px) saturate(135%);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.58); }
.dialog h2 { margin: 0 0 8px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }

@media (max-width: 980px) {
    .create-client-form { grid-template-columns: 1fr 1fr; }
    .create-client-form .btn { width: 100%; }
}

@media (max-width: 720px) {
    .topbar { padding: 14px 18px; align-items: flex-start; flex-direction: column; top: 8px; width: min(100% - 16px, 1180px); margin-top: 8px; }
    .brand-text { font-size: 14px; }
    .userbar { width: 100%; justify-content: space-between; gap: 10px; font-size: 14px; }
    .container { width: min(100% - 24px, 1180px); margin-top: 18px; }
    .page-head { align-items: flex-start; flex-direction: column; }
    .upload-form { align-items: stretch; flex-direction: column; }
    .custom-file-input, .client-select { min-width: 0; width: 100%; }
    .create-client-form { grid-template-columns: 1fr; }
    .login-card { padding: 24px; border-radius: 26px; }
    .login-body::before { background-size: 980px auto; opacity: 0.22; }
}

/* v3 refinements */
.topbar {
    overflow: visible;
    isolation: auto;
    transform: none;
}
.topbar .brand-mark,
.topbar .btn,
.topbar .btn:hover,
.topbar .btn:focus,
.topbar .btn:focus-visible {
    box-shadow: none;
}
a:hover,
a:focus,
button:hover,
button:focus {
    text-decoration: none;
}
.btn,
.btn:hover,
.btn:focus,
.btn:focus-visible,
.folder-card,
.folder-card:hover,
.glass-card,
.glass-card:hover {
    outline: none;
}
.btn-primary,
.btn-primary:hover,
.btn-primary:focus,
.btn-primary:focus-visible {
    box-shadow: none;
}

.upload-form {
    display: grid;
    grid-template-columns: minmax(280px, 340px) minmax(340px, 1fr) auto;
    align-items: end;
    gap: 12px;
}
.upload-form > .btn,
.custom-file-input,
.client-select select {
    height: 54px;
    min-height: 54px;
}
.client-select {
    min-width: 0;
    width: 100%;
}
.field-label {
    min-height: 17px;
    line-height: 17px;
}
.select-wrap,
.select-wrap select {
    width: 100%;
}
.custom-file-input {
    width: 100%;
    min-width: 0;
}
.file-input-label {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
}
.upload-form > .btn {
    padding-top: 0;
    padding-bottom: 0;
}

.dialog {
    position: relative;
    padding: 30px;
}
.dialog-form {
    position: relative;
}
.dialog-close {
    position: absolute;
    top: -14px;
    right: -14px;
    width: 38px;
    height: 38px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(255,255,255,0.10);
    color: var(--sab-white);
    font-size: 26px;
    line-height: 1;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .14s ease, border-color .14s ease;
}
.dialog-close:hover {
    background: rgba(255,255,255,0.16);
    border-color: rgba(255,255,255,0.30);
}
.dialog-actions .btn {
    flex: 1 1 190px;
    min-height: 52px;
}

@media (max-width: 980px) {
    .upload-form {
        grid-template-columns: 1fr 1fr;
    }
    .upload-form > .btn {
        grid-column: 1 / -1;
        width: 100%;
    }
}

@media (max-width: 720px) {
    .upload-form {
        grid-template-columns: 1fr;
        align-items: stretch;
    }
    .custom-file-input,
    .client-select,
    .upload-form > .btn {
        width: 100%;
    }
}


/* v4 refinements: compact upload button and remove hover stripes/shadows */
.btn,
.btn:hover,
.btn:focus,
.btn:focus-visible,
.btn:active,
.custom-file-input,
.custom-file-input:hover,
.brand-mark,
.login-logo-text,
.topbar .brand-mark,
.topbar .btn,
.folder-card,
.folder-card:hover {
    box-shadow: none !important;
    filter: none !important;
    text-shadow: none !important;
}

.btn,
.folder-card,
.custom-file-input {
    transform: none !important;
}

.btn::before,
.btn::after,
.folder-card::before,
.folder-card::after,
.custom-file-input::before,
.custom-file-input::after {
    content: none !important;
    display: none !important;
}

.topbar,
.hero-card,
.panel,
.folder-card {
    overflow: hidden;
}

.btn {
    transition: background .14s ease, border-color .14s ease, opacity .14s ease !important;
}

.custom-file-input:hover {
    background: rgba(255, 255, 255, 0.075) !important;
    border-color: rgba(166, 197, 50, 0.70) !important;
}

.folder-card:hover {
    background: linear-gradient(135deg, rgba(166, 197, 50, 0.11), rgba(255, 255, 255, 0.065)) !important;
    border-color: rgba(166, 197, 50, 0.40) !important;
}

.upload-form {
    display: grid !important;
    align-items: end;
    gap: 12px;
}

.upload-form-with-client {
    grid-template-columns: minmax(280px, 340px) minmax(340px, 1fr) max-content !important;
}

.upload-form-simple {
    grid-template-columns: minmax(340px, 1fr) max-content !important;
}

.upload-submit {
    width: auto !important;
    min-width: 178px;
    max-width: 220px;
    justify-self: start;
    padding-left: 22px !important;
    padding-right: 22px !important;
}

.custom-file-input,
.client-select select,
.upload-submit {
    height: 54px !important;
    min-height: 54px !important;
}

@media (max-width: 980px) {
    .upload-form-with-client,
    .upload-form-simple {
        grid-template-columns: 1fr !important;
    }
    .upload-submit {
        width: auto !important;
        max-width: 220px;
    }
}

@media (max-width: 720px) {
    .upload-submit {
        width: 100% !important;
        max-width: none;
        justify-self: stretch;
    }
}


/* v5: isolate logout button paint area and remove topbar hover compositing artifacts */
.topbar {
    contain: paint !important;
    overflow: hidden !important;
    isolation: isolate !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.145), rgba(255, 255, 255, 0.06)) !important;
}

.userbar,
.logout-form {
    position: relative;
    isolation: isolate !important;
    contain: paint !important;
}

.logout-form {
    margin: 0;
    border-radius: 18px;
    overflow: hidden;
}

.logout-btn,
.logout-btn:hover,
.logout-btn:focus,
.logout-btn:focus-visible,
.logout-btn:active {
    position: relative;
    z-index: 1;
    overflow: hidden !important;
    isolation: isolate !important;
    contain: paint !important;
    clip-path: inset(0 round 16px);
    background: rgba(255, 255, 255, 0.105) !important;
    border-color: rgba(255, 255, 255, 0.17) !important;
    box-shadow: none !important;
    filter: none !important;
    text-shadow: none !important;
    outline: none !important;
    transform: none !important;
    transition: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.135) !important;
    border-color: rgba(255, 255, 255, 0.22) !important;
}

.logout-btn::before,
.logout-btn::after,
.logout-form::before,
.logout-form::after,
.userbar::before,
.userbar::after,
.topbar::before,
.topbar::after {
    content: none !important;
    display: none !important;
    box-shadow: none !important;
    filter: none !important;
}

.hero-card,
.panel,
.folder-card,
.card-grid,
.container {
    background-clip: padding-box;
    isolation: isolate;
}
