* {
    box-sizing: border-box;
}

:root {
    --bg: #f4f6fb;
    --bg-strong: #e9eefb;
    --panel: #ffffff;
    --text: #1a2030;
    --muted: #6b7280;
    --line: rgba(123, 140, 181, 0.18);
    --primary: #405cf5;
    --primary-strong: #2f45d8;
    --success: #0f9f6e;
    --warning: #b7791f;
    --danger: #d6474b;
    --shadow: 0 18px 45px rgba(31, 45, 81, 0.10);
    --radius: 20px;
    --radius-sm: 14px;
    --sidebar-width: 290px;
}

html, body {
    margin: 0;
    min-height: 100%;
    background:
        radial-gradient(circle at top left, rgba(64, 92, 245, .12), transparent 32%),
        radial-gradient(circle at bottom right, rgba(15, 159, 110, .12), transparent 28%),
        var(--bg);
    color: var(--text);
    font: 16px/1.5 "Inter", "Segoe UI", Arial, sans-serif;
}

body.auth-shell {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

body.app-shell {
    padding: 0;
}

a {
    color: var(--primary);
    text-decoration: none;
}

code {
    display: inline-block;
    padding: .15rem .45rem;
    border-radius: 10px;
    background: #f2f5ff;
    color: #2f45d8;
    font-size: .92rem;
}

.auth-card {
    width: min(1120px, 100%);
    display: grid;
    grid-template-columns: minmax(320px, 1fr) minmax(320px, 430px);
    gap: 1.5rem;
    align-items: stretch;
}

.auth-hero,
.panel {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(161, 175, 214, .16);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
}

.auth-hero {
    padding: 2.4rem;
    position: relative;
    overflow: hidden;
}

.auth-hero::after {
    content: "";
    position: absolute;
    width: 240px;
    height: 240px;
    right: -60px;
    bottom: -60px;
    border-radius: 999px;
    background: radial-gradient(circle, rgba(64, 92, 245, .25), rgba(64, 92, 245, 0));
    pointer-events: none;
}

.hero-badge,
.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    background: rgba(64, 92, 245, .12);
    color: var(--primary-strong);
    border-radius: 999px;
    padding: .35rem .8rem;
    font-size: .88rem;
    font-weight: 700;
    letter-spacing: .02em;
}

.auth-hero h1,
.content-header h1 {
    margin: .9rem 0 .5rem;
    font-size: clamp(2rem, 3vw, 2.8rem);
    line-height: 1.08;
}

.auth-hero p,
.content-header p,
.muted {
    color: var(--muted);
}

.hero-list {
    margin: 1.5rem 0 0;
    padding-left: 1.2rem;
    color: var(--muted);
}

.hero-list li + li {
    margin-top: .55rem;
}

.hero-note,
.note-box {
    margin-top: 1.35rem;
    background: linear-gradient(135deg, rgba(64, 92, 245, .08), rgba(15, 159, 110, .07));
    border: 1px solid rgba(64, 92, 245, .10);
    border-radius: var(--radius-sm);
    padding: 1rem 1.1rem;
    color: #314166;
}

.login-powered-by {
    margin-top: .85rem;
    text-align: center;
    color: var(--muted);
    font-size: .84rem;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: uppercase;
}

.app-footer {
    position: fixed;
    left: 50%;
    bottom: .7rem;
    transform: translateX(-50%);
    z-index: 60;
    padding: .36rem .85rem;
    border-radius: 999px;
    border: 1px solid rgba(132, 148, 190, .28);
    background: rgba(255, 255, 255, .85);
    color: #5f6e8b;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: uppercase;
    backdrop-filter: blur(4px);
}

.auth-panel,
.panel {
    padding: 1.45rem;
}

.auth-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.panel-head h2,
.panel h2,
.panel h3 {
    margin: 0;
    font-size: 1.1rem;
}

.text-link {
    align-self: center;
    font-weight: 600;
}

.stack {
    display: grid;
    gap: 1rem;
}

.field {
    display: grid;
    gap: .45rem;
}

.field span {
    font-size: .93rem;
    font-weight: 700;
    color: #38445c;
}

.password-input-row {
    position: relative;
}

.password-input-row input {
    padding-right: 3.2rem;
}

.password-toggle {
    position: absolute;
    right: .5rem;
    top: 50%;
    transform: translateY(-50%);
    border: 1px solid rgba(64, 92, 245, .2);
    background: #eef2ff;
    color: #3248cc;
    border-radius: 10px;
    width: 2.2rem;
    height: 2.2rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    cursor: pointer;
}

.password-toggle:hover {
    background: #e3e9ff;
}

.password-toggle.is-visible {
    background: #dfe7ff;
    border-color: rgba(64, 92, 245, .35);
}

.password-toggle svg {
    width: 1.1rem;
    height: 1.1rem;
    fill: currentColor;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
select,
textarea {
    width: 100%;
    border: 1px solid rgba(132, 148, 190, .35);
    background: #fff;
    border-radius: 14px;
    padding: .9rem 1rem;
    font: inherit;
    color: var(--text);
    outline: none;
    transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}

input:focus,
textarea:focus {
    border-color: rgba(64, 92, 245, .55);
    box-shadow: 0 0 0 4px rgba(64, 92, 245, .12);
}

button {
    font: inherit;
}

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: .45rem;
    border: none;
    border-radius: 14px;
    padding: .84rem 1.15rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
    text-decoration: none;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:disabled {
    cursor: not-allowed;
    opacity: .58;
    transform: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #5670ff);
    color: #fff;
    box-shadow: 0 10px 26px rgba(64, 92, 245, .22);
}

.btn-secondary {
    background: #eef2ff;
    color: #3248cc;
}

.btn-danger {
    background: #fff1f2;
    color: #c4374d;
}

.flash {
    border-radius: 14px;
    padding: .9rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.flash-success {
    background: rgba(15, 159, 110, .11);
    border-color: rgba(15, 159, 110, .16);
    color: #0b7a54;
}

.flash-warning {
    background: rgba(183, 121, 31, .12);
    border-color: rgba(183, 121, 31, .18);
    color: #8d611e;
}

.flash-info {
    background: rgba(64, 92, 245, .08);
    border-color: rgba(64, 92, 245, .15);
    color: #3148cc;
}

.dashboard-layout {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    min-height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
    padding: 1.6rem;
    background: rgba(248, 250, 255, .94);
    border-right: 1px solid rgba(155, 170, 210, .18);
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: .85rem;
}

.brand-mark {
    width: 52px;
    height: 52px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--primary), #5b73ff);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 800;
    box-shadow: 0 12px 28px rgba(64, 92, 245, .25);
}

.nav {
    display: grid;
    gap: .35rem;
}

.nav-link,
.nav-link-button {
    display: flex;
    width: 100%;
    border-radius: 14px;
    padding: .85rem 1rem;
    font-weight: 700;
    color: #334155;
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
}

.nav-link:hover,
.nav-link-button:hover {
    background: rgba(64, 92, 245, .08);
}

.nav-link.active {
    background: linear-gradient(135deg, rgba(64, 92, 245, .12), rgba(64, 92, 245, .07));
    color: #273bba;
}

.nav-logout {
    margin: 0;
}

.side-card {
    background: #fff;
    border: 1px solid rgba(155, 170, 210, .18);
    border-radius: 18px;
    padding: 1rem 1.05rem;
    box-shadow: 0 12px 25px rgba(15, 23, 42, .04);
}

.side-card h3 {
    margin-bottom: .35rem;
}

.side-card p {
    margin: 0 0 .8rem;
    color: var(--muted);
    font-size: .95rem;
}

.side-card code {
    display: block;
    width: 100%;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.45;
    font-size: .88rem;
}

.side-link-list {
    display: grid;
    gap: .55rem;
}

.side-link {
    display: block;
    border-radius: 12px;
    padding: .75rem .9rem;
    background: #f5f8ff;
    color: #3248cc;
    font-weight: 700;
    border: 1px solid rgba(155, 170, 210, .16);
}

.side-link:hover {
    background: #eef3ff;
}

.content {
    padding: 1.8rem;
    display: grid;
    align-content: start;
    gap: 1.25rem;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 1rem;
}

.bucket-label {
    margin: .45rem 0 0;
    color: #334268;
    font-weight: 700;
}

.bucket-tabs {
    display: inline-flex;
    flex-wrap: wrap;
    gap: .55rem;
}

.bucket-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    border: 1px solid rgba(122, 142, 190, .35);
    background: #fff;
    color: #40516f;
    padding: .5rem .95rem;
    font-weight: 700;
    font-size: .93rem;
    transition: background-color .18s ease, color .18s ease, border-color .18s ease, transform .18s ease;
}

.bucket-tab:hover {
    border-color: rgba(64, 92, 245, .45);
    color: #2d49cf;
    transform: translateY(-1px);
}

.bucket-tab.is-active {
    background: linear-gradient(135deg, #405cf5, #5571ff);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 10px 22px rgba(64, 92, 245, .28);
}

.gear-link {
    width: 54px;
    height: 54px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, .9);
    border: 1px solid rgba(155, 170, 210, .18);
    box-shadow: 0 12px 24px rgba(15, 23, 42, .06);
    font-size: 1.35rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

.stat-card {
    background: linear-gradient(180deg, rgba(255, 255, 255, .95), rgba(250, 252, 255, .82));
    border: 1px solid rgba(155, 170, 210, .18);
    box-shadow: var(--shadow);
    border-radius: 18px;
    padding: 1.25rem;
}

.stat-label {
    color: var(--muted);
    font-size: .95rem;
}

.stat-value {
    margin-top: .45rem;
    font-size: clamp(1.8rem, 2vw, 2.4rem);
    font-weight: 800;
    color: #263247;
}

.upload-limits {
    display: flex;
    flex-wrap: wrap;
    gap: .8rem 1rem;
    margin-bottom: 1rem;
    color: #42516b;
    font-size: .95rem;
}

.upload-target-controls {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .8rem 1rem;
    margin-bottom: .75rem;
}

.upload-target-controls .compact-field {
    width: 100%;
}

.upload-target-hint {
    margin: 0 0 .2rem;
    font-size: .92rem;
}

.upload-form {
    display: grid;
    gap: 1rem;
}

.group-create-form {
    margin-top: .8rem;
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: .8rem;
}

.group-create-form .compact-field {
    width: min(320px, 100%);
    margin: 0;
}

.group-visible-toggle {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    color: #42516b;
    font-size: .92rem;
}

.group-visible-toggle input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary);
}

.upload-lock-note {
    margin: 0;
}

.drop-zone {
    border: 2px dashed rgba(64, 92, 245, .28);
    border-radius: 22px;
    background:
        linear-gradient(180deg, rgba(255,255,255,.9), rgba(244,247,255,.95)),
        rgba(64, 92, 245, .04);
    padding: 2.1rem 1.25rem;
    min-height: 220px;
    display: grid;
    place-items: center;
    text-align: center;
    cursor: pointer;
    transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}

.drop-zone.is-disabled {
    cursor: not-allowed;
    border-color: rgba(155, 170, 210, .3);
    background:
        linear-gradient(180deg, rgba(252,253,255,.95), rgba(246,248,252,.97)),
        rgba(145, 158, 190, .08);
    box-shadow: none;
}

.drop-zone:hover,
.drop-zone:focus {
    transform: translateY(-1px);
    border-color: rgba(64, 92, 245, .45);
    box-shadow: 0 12px 30px rgba(64, 92, 245, .12);
}

.drop-zone.is-disabled:hover,
.drop-zone.is-disabled:focus {
    transform: none;
    border-color: rgba(155, 170, 210, .3);
    box-shadow: none;
}

.drop-zone.dragover {
    background: linear-gradient(180deg, rgba(229, 237, 255, .95), rgba(245, 248, 255, .96));
    border-color: rgba(64, 92, 245, .6);
}

.drop-zone-icon {
    width: 72px;
    height: 72px;
    border-radius: 20px;
    display: grid;
    place-items: center;
    font-size: 1.8rem;
    background: linear-gradient(135deg, rgba(64, 92, 245, .14), rgba(15, 159, 110, .12));
    color: #2940ca;
    margin-bottom: 1rem;
}

.drop-zone-title {
    font-size: 1.16rem;
    font-weight: 800;
}

.drop-zone-subtitle {
    max-width: 560px;
    color: var(--muted);
    margin-top: .45rem;
}

.upload-file-list {
    display: grid;
    gap: .55rem;
}

.upload-file-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    background: #f7f9ff;
    border: 1px solid rgba(155, 170, 210, .18);
    border-radius: 14px;
    padding: .8rem .95rem;
}

.upload-file-meta {
    color: var(--muted);
    font-size: .93rem;
}

.upload-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
}

.progress-wrap {
    display: flex;
    align-items: center;
    gap: .7rem;
}

.progress-bar {
    width: 220px;
    height: 11px;
    background: #e8edfb;
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--primary), #5b73ff);
    transition: width .2s ease;
}

.progress-text {
    color: var(--muted);
    font-weight: 700;
    min-width: 44px;
}

.upload-result {
    background: #f7f9ff;
    border: 1px solid rgba(155, 170, 210, .18);
    border-radius: 18px;
    padding: 1rem;
}

.upload-result-summary {
    display: flex;
    flex-wrap: wrap;
    gap: .7rem 1rem;
    margin-bottom: .8rem;
}

.upload-result-summary span {
    background: #fff;
    border: 1px solid rgba(155, 170, 210, .18);
    border-radius: 999px;
    padding: .45rem .8rem;
    font-weight: 700;
}

.upload-result-list {
    margin: 0;
    padding-left: 1.15rem;
    color: #445067;
}

.table-search {
    max-width: 320px;
}

.table-actions,
.inline-form {
    margin-bottom: 1rem;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: .8rem;
}

.view-all-toggle {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    color: #42516b;
    font-size: .92rem;
    font-weight: 600;
    margin-left: auto;
}

.view-all-toggle input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary);
}

.compact-field {
    width: min(280px, 100%);
    margin: 0;
}

.folder-filter-caption {
    margin: -.12rem 0 .55rem;
    font-size: .91rem;
}

.folder-filter-caption strong {
    color: #2b3a56;
}

.table-hint {
    margin-top: -0.35rem;
    margin-bottom: 1rem;
    padding: .8rem .95rem;
    font-size: .92rem;
}

.download-mode-hint {
    margin: -0.2rem 0 .65rem;
    font-size: .9rem;
}

.inline-form {
    margin-top: 1rem;
}

.table-wrap {
    overflow: auto;
    border: 1px solid rgba(155, 170, 210, .18);
    border-radius: 18px;
    background: #fff;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.data-table th,
.data-table td {
    padding: .95rem 1rem;
    border-bottom: 1px solid rgba(155, 170, 210, .14);
    text-align: left;
    vertical-align: top;
}

.data-table th {
      background: #f8faff;
      color: #42516b;
      font-size: .93rem;
      position: sticky;
      top: 0;
      z-index: 1;
  }

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.data-table th.sortable::after {
    content: ' ↕';
    font-weight: 700;
    color: #94a3b8;
}

.data-table th.sortable.sort-asc::after {
    content: ' ↑';
    color: #334155;
}

.data-table th.sortable.sort-desc::after {
    content: ' ↓';
    color: #334155;
}

.data-table tbody tr:hover {
    background: #fcfdff;
}

.table-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.table-pagination .page-size label {
    display: inline-flex;
    align-items: center;
    gap: .6rem;
    color: #55607a;
    font-size: .92rem;
}

.table-pagination select {
    padding: .4rem .6rem;
    border-radius: 10px;
    border: 1px solid rgba(155, 170, 210, .28);
    background: #fff;
}

.table-pagination .page-controls {
    display: inline-flex;
    align-items: center;
    gap: .6rem;
}

.table-pagination .page-info {
    min-width: 80px;
    text-align: center;
    font-weight: 700;
    color: #42516b;
}

.header-actions {
    display: inline-flex;
    align-items: center;
    gap: .6rem;
}

.file-name {
    font-weight: 700;
    word-break: break-word;
}

.file-download-link {
    color: #1d4ed8;
    text-decoration: none;
    border-bottom: 1px dashed rgba(29, 78, 216, .45);
}

.file-download-link:hover {
    color: #1e40af;
    border-bottom-color: rgba(30, 64, 175, .65);
}

.file-sub {
    margin-top: .2rem;
    color: var(--muted);
    font-size: .84rem;
}

.group-cell {
    min-width: 200px;
}

.row-group-select {
    min-width: 180px;
    max-width: 260px;
    padding: .5rem .65rem;
    border-radius: 10px;
    font-size: .9rem;
}

.row-group-select.is-saving {
    opacity: .72;
    cursor: wait;
}

.number-badge,
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .34rem .68rem;
    border-radius: 999px;
    font-size: .85rem;
    font-weight: 700;
}

.number-badge {
    background: #eef2ff;
    color: #3248cc;
}

.status-new {
    background: rgba(15, 159, 110, .10);
    color: #0b7a54;
}

.status-downloaded {
    background: rgba(64, 92, 245, .10);
    color: #3248cc;
}

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 2rem 1rem !important;
}

.panel-narrow {
    max-width: 520px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.panel-wide {
    grid-column: 1 / -1;
}

.group-admin-list {
    display: grid;
    gap: .8rem;
}

.group-admin-row {
    display: grid;
    gap: .6rem;
    border: 1px solid rgba(155, 170, 210, .18);
    border-radius: 14px;
    padding: .8rem .9rem;
    background: #f7f9ff;
}

.setting-value {
    display: grid;
    gap: .45rem;
}

.setting-label {
    color: var(--muted);
    font-size: .92rem;
}

.setting-main {
    font-size: 1.2rem;
    font-weight: 800;
}

.diagnostics-box {
    min-height: 60px;
}

.diagnostics-actions {
    margin: .8rem 0;
}

.diagnostics-textarea {
    min-height: 260px;
    resize: vertical;
    background: #0f172a;
    color: #d5def5;
    font: 14px/1.45 Consolas, Monaco, monospace;
}

.hidden-row {
    display: none;
}

.hidden-page {
    display: none;
}

@media (max-width: 1140px) {
    .auth-card {
        grid-template-columns: 1fr;
    }

    .dashboard-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        min-height: auto;
        max-height: none;
        overflow: visible;
        border-right: none;
        border-bottom: 1px solid rgba(155, 170, 210, .18);
    }

    .stats-grid,
    .settings-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .upload-target-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    body.auth-shell {
        padding: 1rem;
    }

    .content {
        padding: 1rem;
    }

    .stats-grid,
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .panel,
    .auth-hero,
    .auth-panel {
        padding: 1.1rem;
    }

    .content-header {
        flex-direction: column;
    }

    .table-search {
        max-width: none;
        width: 100%;
    }

    .drop-zone {
        min-height: 180px;
        padding: 1.35rem 1rem;
    }

    .upload-target-controls {
        grid-template-columns: 1fr;
    }

    .group-create-form {
        flex-direction: column;
        align-items: stretch;
    }

    .view-all-toggle {
        margin-left: 0;
        width: 100%;
    }

    .upload-actions,
    .upload-result-summary {
        flex-direction: column;
        align-items: stretch;
    }

    .progress-bar {
        width: 100%;
    }
}
