:root {
    color-scheme: light;
    --bg: #fff9e6;
    --bg-accent: #fff4cc;
    --card: #ffffff;
    --text: #111111;
    --muted: #667085;
    --border: #e4e7ec;
    --accent: #f4b400;
    --accent-dark: #c28f00;
    --danger: #c81e1e;
    --success: #1e7a3c;
    --radius: 16px;
    --shadow: 0 20px 40px rgba(15, 23, 42, 0.08);
    --focus: 0 0 0 3px rgba(15, 118, 110, 0.2);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background: #e3e3e3;
}

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

a:hover {
    text-decoration: underline;
}

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

.sidebar {
    width: 240px;
    background: #ffffff;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 24px 18px;
}

.sidebar-brand {
    margin-bottom: 24px;
    width: 100%;
}

.sidebar-logo {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nav-item {
    display: block;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text);
    font-weight: 500;
}

.nav-item.active,
.nav-item:hover {
    background: #f2f4f7;
    text-decoration: none;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid rgba(17, 17, 17, 0.08);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.content {
    flex: 1;
    padding: 32px 30px;
}

.content-inner {
    width: 100%;
    max-width: none;
    margin: 0;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.page-title {
    font-size: 1.6rem;
    margin: 0;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

body > main.card {
    width: 100%;
    max-width: none;
    margin: 32px 0;
    padding: 24px 30px;
}

body > main.card.login-card {
    width: clamp(320px, 25vw, 480px);
    margin: 32px auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}

.logo {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, #0f766e, #22c1a6);
}

h1 {
    margin: 0;
    font-size: 1.5rem;
}

.muted {
    color: var(--muted);
    margin: 6px 0 0;
}

.table-wrapper {
    width: 100%;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
}

.table th {
    color: var(--muted);
    font-weight: 600;
}

.table-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.table td .table-actions {
    flex-wrap: nowrap;
    align-items: center;
}

.table td .table-actions form {
    margin: 0;
}

.btn,
button,
.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: var(--accent);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s ease, background 0.2s ease, border 0.2s ease;
    text-decoration: none;
}

.btn:hover,
button:hover,
.button-link:hover {
    background: var(--accent-dark);
    text-decoration: none;
}

.btn:active,
button:active,
.button-link:active {
    transform: translateY(1px);
}

.btn.secondary {
    background: #ffffff;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn.secondary:hover {
    background: #f2f4f7;
}

.btn.success {
    background: var(--success);
    color: #fff;
    border: 1px solid transparent;
}

.btn.success:hover {
    background: #166534;
}

.btn.danger,
button.danger {
    background: #b42318;
}

.btn.danger:hover,
button.danger:hover {
    background: #8f1c13;
}

.form-group {
    margin-top: 16px;
}

label {
    display: block;
    font-size: 0.9rem;
    color: var(--muted);
    margin-bottom: 6px;
}

input,
select,
textarea {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    font-size: 1rem;
    background: #fff;
    color: var(--text);
    transition: border 0.2s ease, box-shadow 0.2s ease;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

form {
    width: 100%;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus);
}

.flash {
    margin-bottom: 18px;
    padding: 12px 14px;
    border-radius: 12px;
    font-weight: 500;
}

.flash-success,
.success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #15803d;
}

.flash-error,
.error {
    background: #fff1f2;
    border: 1px solid #fecdd3;
    color: #be123c;
}

.flash-warning {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
}

.error,
.success {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 0.95rem;
}

.link-muted {
    color: var(--muted);
    font-size: 0.9rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid transparent;
}

.badge-yes {
    background: #f0fdf4;
    color: #15803d;
    border-color: #bbf7d0;
}

.badge-no {
    background: #fff1f2;
    color: #be123c;
    border-color: #fecdd3;
}

.badge-status {
    text-transform: capitalize;
}

.badge-status-bozza {
    background: #f8fafc;
    color: #475467;
    border-color: #e4e7ec;
}

.badge-status-presentato {
    background: #ecfdf3;
    color: #027a48;
    border-color: #abefc6;
}

.badge-status-vinto {
    background: #f0fdf4;
    color: #15803d;
    border-color: #bbf7d0;
}

.badge-status-perso {
    background: #fef2f2;
    color: #b42318;
    border-color: #fecaca;
}

.badge-status-archiviato {
    background: #f4f4f5;
    color: #52525b;
    border-color: #e4e4e7;
}

.footer-links {
    margin-top: 16px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.9rem;
}

.footer-links a {
    color: var(--muted);
}

.footer-links a:hover {
    color: var(--accent);
}

.card-list {
    display: none;
    gap: 16px;
}

.card-item {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
}

.card-item .table-actions {
    flex-wrap: nowrap;
    align-items: center;
}

.card-item .table-actions form {
    margin: 0;
}

.card-item h4 {
    margin: 0 0 6px;
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.is-open {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
}

.modal-card {
    position: relative;
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    width: min(420px, 92vw);
    box-shadow: var(--shadow);
    z-index: 1;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dashboard-page .content {
    background: #ffffff;
}

.dashboard-page .content-inner {
    max-width: none;
}

@media (max-width: 900px) {
    .sidebar {
        width: 200px;
    }
}

@media (max-width: 720px) {
    .app {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 14px 18px;
    }

    .sidebar-brand {
        margin-bottom: 0;
        margin-right: 12px;
        flex: 0 0 auto;
    }

    .sidebar-logo {
        width: 110px;
    }

    .sidebar-nav {
        flex-direction: row;
        gap: 8px;
    }

    .sidebar-footer {
        margin-top: 0;
    }

    .content {
        padding: 20px 30px;
    }

    .table {
        display: none;
    }

    .card-list {
        display: grid;
    }

    body > main.card {
        margin: 20px auto;
    }

    body > main.card.login-card {
        width: min(92vw, 420px);
    }
}

.regenerate-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.6);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.regenerate-overlay.is-visible {
    display: flex;
}

.regenerate-overlay .overlay-card {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px 24px;
    max-width: 520px;
    width: 100%;
    text-align: center;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
}

.regenerate-overlay .countdown {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    margin: 8px 0 0;
}

.regenerate-overlay .subtitle {
    margin-top: 8px;
    color: var(--muted);
}

.regenerate-overlay .watermark {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(32px, 6vw, 64px);
    font-weight: 700;
    letter-spacing: 0.08em;
    color: rgba(15, 23, 42, 0.25);
    text-transform: uppercase;
    pointer-events: none;
    user-select: none;
}

.debug-accordion {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    background: #fff;
}

.debug-accordion summary {
    cursor: pointer;
    font-weight: 600;
    list-style: none;
    outline: none;
}

.debug-accordion summary::-webkit-details-marker {
    display: none;
}

.debug-accordion summary::after {
    content: '▸';
    float: right;
    transition: transform 0.2s ease;
}

.debug-accordion[open] summary::after {
    transform: rotate(90deg);
}

.debug-pre {
    margin-top: 12px;
    white-space: pre-wrap;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.9rem;
    line-height: 1.45;
}





