:root {
    --brand: #1D3151;
    --brand-light: #F2F2F2;
    --brand-hover: #16263F;
    --surface: #FFFFFF;
    --border: #D8DEE6;
    --text: #1D3151;
    --text-muted: #5A6B7F;
    --ok: #2f7d4a;
    --danger: #b42318;
    --radius: 8px;
    --font-display: "Outfit", "Montserrat", sans-serif;
    --font-body: "Source Sans 3", "Segoe UI", sans-serif;
    --sidebar-w: 260px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: var(--font-body);
    color: var(--text);
    background: var(--brand-light);
}

a { color: var(--brand); }
code { font-size: 0.9em; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: 0;
    border-radius: var(--radius);
    padding: 0.7rem 1.1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn-primary {
    background: var(--brand);
    color: var(--brand-light);
}
.btn-primary:hover { background: var(--brand-hover); }
.btn-secondary {
    background: #e8edf3;
    color: var(--brand);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: #dce4ee; }
.btn-block { width: 100%; }

.alert {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}
.alert-success { background: #e8f5ec; color: var(--ok); }
.alert-danger { background: #fdecea; color: var(--danger); }

/* Guest / login */
.guest-body {
    min-height: 100vh;
    background: #e8ecf1;
    color: var(--text);
}

.login-stage {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
    min-height: 100vh;
}

.login-visual {
    position: relative;
    display: grid;
    place-items: center;
    overflow: hidden;
    padding: clamp(2rem, 5vw, 3.5rem);
    background:
        radial-gradient(ellipse 70% 55% at 50% 42%, rgba(242, 242, 242, 0.08), transparent 60%),
        linear-gradient(165deg, #274062 0%, var(--brand) 48%, #101a2b 100%);
    color: var(--brand-light);
    animation: login-rise 0.8s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.visual-glow {
    position: absolute;
    inset: -20%;
    background:
        radial-gradient(circle at 30% 30%, rgba(188, 149, 102, 0.14), transparent 42%),
        radial-gradient(circle at 70% 70%, rgba(242, 242, 242, 0.06), transparent 45%);
    pointer-events: none;
    animation: login-bg-shift 16s ease-in-out infinite alternate;
}

.brand-stack {
    position: relative;
    z-index: 1;
    display: grid;
    justify-items: center;
    gap: 1.75rem;
    text-align: center;
    max-width: 28rem;
}

.brand-emblem {
    position: relative;
    width: min(72vw, 340px);
    aspect-ratio: 1;
    display: grid;
    place-items: center;
}

.brand-rings {
    position: absolute;
    inset: 0;
    animation: login-orbit-slow 48s linear infinite;
}

.brand-rings span {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px dotted rgba(242, 242, 242, 0.78);
}

.brand-rings span:nth-child(2) {
    inset: 9%;
    border-color: rgba(242, 242, 242, 0.62);
    animation: login-orbit-slow 56s linear infinite reverse;
}

.brand-rings span:nth-child(3) {
    inset: 18%;
    border-color: rgba(242, 242, 242, 0.48);
}

.brand-wordmark {
    position: relative;
    z-index: 1;
    display: grid;
    gap: 0.1rem;
    line-height: 0.95;
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: -0.03em;
    color: #fff;
    text-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
}

.bw-dot {
    font-size: clamp(2.8rem, 7vw, 3.6rem);
}

.bw-my {
    font-size: clamp(1.85rem, 4.6vw, 2.35rem);
    font-weight: 600;
}

.brand-chip {
    color: rgba(242, 242, 242, 0.92);
    opacity: 0.9;
    animation: login-rise 0.9s cubic-bezier(0.22, 1, 0.36, 1) 0.15s both;
}

.brand-tagline {
    margin: 0;
    max-width: 22rem;
    font-size: 1.05rem;
    line-height: 1.55;
    font-weight: 500;
    color: rgba(242, 242, 242, 0.84);
}

.login-panel {
    display: grid;
    place-items: center;
    padding: clamp(1.5rem, 4vw, 2.75rem);
    background: linear-gradient(180deg, #f5f7fa 0%, #e8ecf1 100%);
    animation: login-rise 0.85s cubic-bezier(0.22, 1, 0.36, 1) 0.1s both;
}

.access-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    color: var(--text);
    border-radius: 20px;
    padding: 2rem 1.85rem 1.9rem;
    border: 1px solid rgba(29, 49, 81, 0.08);
    box-shadow: 0 18px 40px rgba(29, 49, 81, 0.08);
}

.access-header { margin-bottom: 1.4rem; }

.access-kicker {
    margin: 0 0 0.45rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #8a7358;
}

.access-header h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(1.7rem, 3vw, 2rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--brand);
}

.access-header p {
    margin: 0.45rem 0 0;
    color: var(--text-muted);
    font-size: 0.98rem;
    line-height: 1.45;
}

.login-form { display: grid; gap: 1.05rem; }
.login-form .field { display: grid; gap: 0.4rem; }
.login-form label {
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--brand);
}
.login-form input {
    border: 1px solid #c9d2de;
    border-radius: 12px;
    padding: 0.85rem 0.95rem;
    font: inherit;
    width: 100%;
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.login-form input::placeholder { color: #9aa8b8; }
.login-form input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(29, 49, 81, 0.14);
}
.twofa-setup {
    display: grid;
    justify-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    padding: 1rem;
    background: #f4f6f9;
    border-radius: 12px;
    border: 1px solid var(--border);
}
.twofa-setup img {
    width: 200px;
    height: 200px;
    border-radius: 10px;
    background: #fff;
    border: 8px solid #fff;
    box-shadow: 0 4px 16px rgba(16, 24, 40, 0.12);
}
.twofa-setup code {
    font-size: 0.85rem;
    word-break: break-all;
}
#auth_code {
    letter-spacing: 0.35em;
    font-size: 1.25rem;
    text-align: center;
    font-weight: 600;
}
.login-submit {
    margin-top: 0.45rem;
    min-height: 3rem;
    font-size: 1.02rem;
    border-radius: 12px;
    gap: 0.55rem;
    transition: transform 0.15s ease, background 0.15s ease;
}
.login-submit:hover { transform: translateY(-1px); }
.login-submit i { font-size: 1.05rem; transition: transform 0.15s ease; }
.login-submit:hover i { transform: translateX(3px); }
.guest-body .alert { border-radius: 12px; }

@keyframes login-rise {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes login-bg-shift {
    from { transform: scale(1) translate(0, 0); }
    to { transform: scale(1.06) translate(2%, -1%); }
}
@keyframes login-orbit-slow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@media (max-width: 900px) {
    .login-stage { grid-template-columns: 1fr; }
    .login-visual {
        min-height: 42vh;
        padding: 2rem 1.25rem 1.5rem;
    }
    .brand-emblem { width: min(58vw, 240px); }
    .brand-chip svg { width: 44px; height: 44px; }
    .brand-tagline { font-size: 0.98rem; }
    .login-panel {
        padding: 1.25rem 1.15rem 2.25rem;
        align-content: start;
    }
    .access-card { max-width: 440px; }
}

@media (prefers-reduced-motion: reduce) {
    .login-visual,
    .login-panel,
    .visual-glow,
    .brand-rings,
    .brand-rings span,
    .brand-chip,
    .login-submit,
    .login-submit i {
        animation: none !important;
        transition: none !important;
    }
}

/* Admin shell */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100vh;
}
.sidebar {
    width: var(--sidebar-w);
    max-width: var(--sidebar-w);
    background: var(--brand);
    color: var(--brand-light);
    display: flex;
    flex-direction: column;
    padding: 1rem 0.85rem;
    box-sizing: border-box;
    overflow: hidden;
    position: sticky;
    top: 0;
    height: 100vh;
    max-height: 100vh;
    align-self: start;
}
.sidebar-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    flex-shrink: 0;
}
.sidebar-brand { display: flex; gap: 0.75rem; align-items: center; padding: 0.5rem; min-width: 0; flex: 1; }
.brand-logo {
    width: 72px;
    height: auto;
    aspect-ratio: 500 / 258;
    object-fit: contain;
    border-radius: 8px;
    background: rgba(242,242,242,0.08);
    flex-shrink: 0;
}
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; }
.brand-sub { opacity: 0.75; font-size: 0.8rem; }
.sidebar-nav {
    display: grid;
    gap: 0.25rem;
    margin-top: 1.25rem;
    flex: 1;
    align-content: start;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
}
.nav-section {
    margin: 0.85rem 0.5rem 0.35rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.55;
}
.nav-link {
    display: flex;
    gap: 0.65rem;
    align-items: center;
    color: var(--brand-light);
    text-decoration: none;
    padding: 0.65rem 0.75rem;
    border-radius: var(--radius);
    opacity: 0.88;
    min-width: 0;
}
.nav-link:hover, .nav-link.active { background: rgba(242,242,242,0.12); opacity: 1; }
.nav-link.disabled { opacity: 0.4; pointer-events: none; }
.sidebar-footer {
    border-top: 1px solid rgba(242,242,242,0.15);
    padding-top: 0.85rem;
    margin-top: auto;
    flex-shrink: 0;
}
.user-chip { display: grid; gap: 0.1rem; padding: 0.35rem 0.5rem 0.75rem; }
.user-chip span { opacity: 0.7; font-size: 0.85rem; }
.logout-link { color: var(--brand-light); text-decoration: none; padding: 0.45rem 0.5rem; display: inline-flex; gap: 0.4rem; }

.main-content { padding: 1.75rem 1.5rem 2.5rem; min-width: 0; }
.page-header h1 {
    font-family: var(--font-display);
    margin: 0 0 0.25rem;
    font-size: 1.85rem;
}
.page-header p { margin: 0 0 1.25rem; color: var(--text-muted); }
.page-header.row-between {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}
.page-header.row-between p { margin-bottom: 0; }
.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.stat-card, .panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.1rem 1.2rem;
}
.stat-label { display: block; color: var(--text-muted); font-size: 0.85rem; }
.stat-value { display: block; font-family: var(--font-display); font-size: 2rem; font-weight: 700; margin: 0.2rem 0; }
.stat-hint { color: var(--text-muted); font-size: 0.8rem; }
.dash-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 0.25rem;
}
.home-tiles {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    margin-top: 1.25rem;
}
.home-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.85rem;
    min-height: 11rem;
    padding: 1.5rem 1rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    text-decoration: none;
    color: var(--brand);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.home-tile:hover {
    border-color: var(--brand);
    box-shadow: 0 8px 24px rgba(29, 49, 81, 0.1);
    transform: translateY(-2px);
}
.home-tile i {
    font-size: 2.4rem;
    line-height: 1;
}
.home-tile span {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.04em;
}
.client-switch-panel {
    margin-bottom: 0.25rem;
}
.client-switch-panel .form-grid {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
}
.stats-front-grid {
    margin-top: 0.25rem;
}
.panel h2 { margin: 0 0 0.5rem; font-family: var(--font-display); font-size: 1.2rem; }
.panel h2 i { margin-right: 0.35rem; }
.panel-warning { border-color: #e0c48a; }
.panel-warning h2 { color: #8a6d1d; }
.panel-danger { border-color: #e5b4af; }
.panel-danger h2 { color: var(--danger); }
.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 600;
}
.badge-warn { background: #fff3cd; color: #856404; }
.badge-danger { background: #fdecea; color: var(--danger); }
.muted { color: var(--text-muted); }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-bottom: 1rem;
}
.toolbar input,
.toolbar select {
    flex: 1;
    min-width: 180px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.65rem 0.8rem;
    font: inherit;
    background: #fff;
}

.dropzone {
    display: grid;
    place-items: center;
    gap: 0.35rem;
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 2rem 1.25rem;
    text-align: center;
    background: #fafbfc;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover,
.dropzone.is-dragover {
    border-color: var(--brand);
    background: #f0f4f8;
}
.dropzone-icon {
    font-size: 2rem;
    color: var(--brand);
    line-height: 1;
}
.upload-file-list {
    margin-top: 0.85rem;
}
.upload-file-list ul {
    margin: 0.4rem 0 0;
    padding-left: 1.1rem;
}

.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}
.data-table th,
.data-table td {
    text-align: left;
    padding: 0.7rem 0.55rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.data-table th {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}
.data-table code { font-size: 0.85em; word-break: break-all; }
.tag-inizio-way {
    margin-left: 0.35rem;
    font-size: 0.85rem;
    color: var(--brand);
    vertical-align: middle;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem 1rem;
}
.form-grid .field { display: grid; gap: 0.35rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { font-weight: 600; font-size: 0.88rem; }
.form-grid .field-caption {
    font-weight: 600;
    font-size: 0.88rem;
}
.form-grid input,
.form-grid select,
.form-grid textarea {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.65rem 0.8rem;
    font: inherit;
    width: 100%;
    background: #fff;
}
.checks {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem 1.25rem;
    align-items: center;
}
.checks label { font-weight: 500; display: inline-flex; gap: 0.4rem; align-items: center; }
.form-actions { display: flex; gap: 0.75rem; }
.section-title {
    margin: 1.25rem 0 0.65rem;
    font-family: var(--font-display);
    font-size: 1.15rem;
}
.form-grid .section-title:first-child { margin-top: 0; }
.qr-actions .btn { width: 100%; }
.inline-check {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-weight: 500;
    min-height: 2.6rem;
}
.inline-check code {
    font-size: 0.9em;
}
.menu-row { margin-bottom: 0.85rem; }

.lang-tabs,
.media-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0.75rem 0 1rem;
}
.lang-tab,
.media-tab {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 8px;
    padding: 0.45rem 0.8rem;
    font: inherit;
    cursor: pointer;
    color: var(--text);
}
.lang-tab.active,
.media-tab.active {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--brand-light);
}
.lang-panel,
.media-panel { display: none; }
.lang-panel.active,
.media-panel.active { display: block; }
.field-with-action {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.35rem;
}
.media-input-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.5rem;
}
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.85rem; }
.media-dialog {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    width: min(900px, 94vw);
    max-height: 85vh;
}
.media-dialog::backdrop { background: rgba(16, 24, 40, 0.45); }
.media-dialog-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.media-filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.75rem; }
.media-list { overflow: auto; max-height: 60vh; }
.tag-form .tox-tinymce { border-radius: 8px; }

.tag-meta-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 1.25rem;
    align-items: start;
    margin-bottom: 1.25rem;
}
.tag-marker-preview {
    width: 200px;
    text-align: center;
}
.tag-marker-preview img {
    width: 200px;
    height: 200px;
    object-fit: contain;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px;
}
.tag-accordion {
    display: grid;
    gap: 0.55rem;
}
.tag-acc-item {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
}
.tag-acc-item summary {
    list-style: none;
    cursor: pointer;
    padding: 0.85rem 1rem;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.98rem;
    color: var(--brand);
    background: #f4f6f9;
    border-bottom: 1px solid transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}
.tag-acc-item summary::-webkit-details-marker { display: none; }
.tag-acc-item summary::after {
    content: "";
    width: 0.55rem;
    height: 0.55rem;
    border-right: 2px solid var(--brand);
    border-bottom: 2px solid var(--brand);
    transform: rotate(45deg);
    transition: transform 0.15s ease;
    flex: 0 0 auto;
}
.tag-acc-item[open] summary {
    border-bottom-color: var(--border);
}
.tag-acc-item[open] summary::after {
    transform: rotate(-135deg);
}
.tag-acc-body {
    padding: 1rem;
}
.lang-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem 1.15rem;
}
.lang-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.lang-field {
    display: grid;
    gap: 0.4rem;
    align-content: start;
    min-width: 0;
}
.field-label-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 0.5rem;
    min-height: 2rem;
}
.field-label-row label {
    margin: 0;
    font-weight: 600;
    font-size: 0.88rem;
}
.field-label-spacer {
    display: inline-block;
    min-height: 1.85rem;
    min-width: 1px;
}
.lang-field .translate-btn {
    white-space: nowrap;
    justify-self: end;
}
.lang-field input,
.lang-field textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.65rem 0.8rem;
    font: inherit;
    background: #fff;
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    color: var(--brand);
}
.switch input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}
.switch-ui {
    position: relative;
    width: 2.75rem;
    height: 1.55rem;
    border-radius: 999px;
    background: #c5ced8;
    border: 1px solid #b4bfcb;
    transition: background 0.18s ease, border-color 0.18s ease;
    flex: 0 0 auto;
}
.switch-ui::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 1.15rem;
    height: 1.15rem;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(16, 24, 40, 0.28);
    transition: transform 0.18s ease;
}
.switch input:checked + .switch-ui {
    background: var(--brand);
    border-color: var(--brand);
}
.switch input:checked + .switch-ui::after {
    transform: translateX(1.15rem);
}
.switch input:focus-visible + .switch-ui {
    outline: 2px solid rgba(29, 49, 81, 0.3);
    outline-offset: 2px;
}
.switch-text {
    font-size: 0.95rem;
}

@media (max-width: 900px) {
    .tag-meta-row { grid-template-columns: 1fr; }
    .tag-marker-preview { width: 160px; }
    .tag-marker-preview img { width: 160px; height: 160px; }
    .lang-grid,
    .lang-grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 800px) {
    .form-grid { grid-template-columns: 1fr; }
    .dash-grid { grid-template-columns: 1fr; }
    .home-tiles { grid-template-columns: 1fr; }
    .client-switch-panel .form-grid { grid-template-columns: 1fr; }
}

.mobile-bar { display: none; }
.sidebar-close { display: none; background: transparent; border: 0; color: var(--brand-light); }

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .mobile-bar {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        background: var(--brand);
        color: var(--brand-light);
        padding: 0.75rem 1rem;
    }
    .menu-toggle {
        background: transparent;
        border: 0;
        color: inherit;
        font-size: 1.4rem;
    }
    .mobile-bar-brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; }
    .stat-grid { grid-template-columns: 1fr; }
}
