/* Contratti Facili — stile interfaccia (il foglio A4 ha stili propri nel template) */
:root {
    --bg: #0f172a;
    --bg-soft: #1e293b;
    --panel: #ffffff;
    --line: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --ok: #16a34a;
    --warn: #b45309;
    --err: #dc2626;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f1f5f9;
    color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ------------------------------------------------------------- topbar */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--bg); color: #fff; padding: 10px 20px;
    position: sticky; top: 0; z-index: 50;
}
.brand { font-weight: 800; font-size: 18px; color: #fff !important; text-decoration: none !important; }
.brand span { color: #60a5fa; }
.topbar-links { display: flex; align-items: center; gap: 16px; }
.topbar-links a { color: #cbd5e1; font-weight: 600; font-size: 14px; }
.topbar-links a:hover { color: #fff; text-decoration: none; }
.topbar-links a.btn { color: #fff; }
.user-chip {
    background: var(--bg-soft); border-radius: 999px; padding: 4px 12px;
    font-size: 12px; color: #94a3b8; max-width: 200px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ------------------------------------------------------------ buttons */
.btn {
    display: inline-block; border: 1px solid var(--line); background: #fff;
    color: var(--text); padding: 8px 16px; border-radius: 8px; cursor: pointer;
    font-size: 14px; font-weight: 600; text-decoration: none !important;
    transition: background .15s, transform .05s;
}
.btn:hover { background: #f8fafc; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--err); }
.btn-danger:hover { background: #fef2f2; }
.btn-block { display: block; width: 100%; margin-bottom: 8px; text-align: center; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }

/* --------------------------------------------------------- containers */
.container { max-width: 1080px; margin: 0 auto; padding: 28px 20px; }
.container-narrow { max-width: 860px; }
.page-head {
    display: flex; justify-content: space-between; align-items: flex-end;
    gap: 20px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-head h1 { margin: 0 0 4px 0; font-size: 26px; }
.page-head p { margin: 0; }

/* ---------------------------------------------------------------- auth */
.auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(150deg, var(--bg) 0%, #1e3a8a 100%); padding: 20px;
}
.auth-card {
    background: #fff; border-radius: 16px; padding: 36px;
    width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.auth-logo { font-size: 26px; font-weight: 800; text-align: center; }
.auth-logo span { color: var(--primary); }
.auth-sub { text-align: center; color: var(--muted); font-size: 14px; margin: 8px 0 20px; }
.auth-card label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 4px; }
.auth-card input {
    width: 100%; padding: 10px 12px; border: 1px solid var(--line);
    border-radius: 8px; font-size: 15px;
}
.auth-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.auth-card .btn-block { margin-top: 22px; padding: 12px; font-size: 15px; }
.auth-alt { text-align: center; font-size: 13px; color: var(--muted); margin-top: 18px; }
.auth-card-wide { max-width: 560px; }
.auth-grid { display: grid; gap: 0 12px; }
.auth-section {
    margin: 22px 0 2px; padding-bottom: 6px; font-size: 14px;
    border-bottom: 1px solid var(--line); color: var(--text);
}

.alert { padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; }
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: var(--err); }
.alert-warn { background: #fffbeb; border: 1px solid #fde68a; color: var(--warn); }
.alert-ok { background: #f0fdf4; border: 1px solid #bbf7d0; color: var(--ok); }

/* -------------------------------------------------------------- tables */
.search-form { display: flex; gap: 8px; }
.search-form input {
    padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
    font-size: 14px; width: 260px;
}
.data-table {
    width: 100%; border-collapse: collapse; background: #fff;
    border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.data-table th {
    text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
    color: var(--muted); padding: 12px 14px; background: #f8fafc; border-bottom: 1px solid var(--line);
}
.data-table td { padding: 12px 14px; border-bottom: 1px solid #f1f5f9; font-size: 14px; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8fafc; }
.data-table .num { text-align: right; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions .btn { margin-left: 6px; }

.empty-state {
    text-align: center; background: #fff; border-radius: 16px; padding: 60px 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.empty-state h2 { margin: 10px 0 6px; }

/* ---------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 0; flex-wrap: wrap; }
.tab {
    border: 1px solid var(--line); border-bottom: none; background: #e2e8f0;
    padding: 10px 18px; border-radius: 10px 10px 0 0; cursor: pointer;
    font-size: 14px; font-weight: 600; color: var(--muted);
}
.tab.active { background: #fff; color: var(--text); }
.tab-panel {
    display: none; background: #fff; border: 1px solid var(--line);
    border-radius: 0 12px 12px 12px; padding: 24px;
}
.tab-panel.active { display: block; }
.tab-panel label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 4px; }
.tab-panel input, .tab-panel textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--line);
    border-radius: 8px; font-size: 14px; font-family: inherit;
}
.tab-panel input:focus, .tab-panel textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.tab-panel textarea { resize: vertical; min-height: 90px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
.settings-h3 {
    margin: 26px 0 2px; font-size: 15px; border-bottom: 1px solid var(--line); padding-bottom: 6px;
}
.settings-footer {
    margin-top: 18px; display: flex; align-items: center; gap: 14px;
}
code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ----------------------------------------------------------- workspace */
.workspace-body { background: #475569; }
.workspace { display: flex; align-items: flex-start; gap: 0; }
.sidebar {
    width: 320px; flex-shrink: 0; padding: 16px;
    position: sticky; top: 54px; height: calc(100vh - 54px); overflow-y: auto;
}
.sheet-area { flex: 1; padding: 20px; overflow-x: auto; }

.panel {
    background: #fff; border-radius: 12px; padding: 14px 16px; margin-bottom: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.panel h3 { margin: 0 0 8px; font-size: 14px; }
.panel p { margin: 0 0 10px; }
.panel select {
    width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
}

.switch-row {
    display: flex; align-items: center; gap: 10px; padding: 6px 0;
    font-size: 14px; font-weight: 600; cursor: pointer;
}
.switch-row input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }

.dropzone {
    border: 2px dashed #cbd5e1; border-radius: 10px; padding: 10px 12px;
    margin-bottom: 8px; cursor: pointer; transition: border-color .15s, background .15s;
    display: flex; flex-direction: column; gap: 2px; position: relative;
}
.dropzone b { font-size: 13px; }
.dropzone span { font-size: 11px; color: var(--muted); }
.dropzone:hover, .dropzone.dz-over { border-color: var(--primary); background: #eff6ff; }
.dropzone.dz-loading { border-color: var(--warn); background: #fffbeb; pointer-events: none; }
.dropzone.dz-loading::after {
    content: '⏳ analisi…'; position: absolute; right: 10px; top: 50%;
    transform: translateY(-50%); font-size: 11px; color: var(--warn);
}
.dropzone.dz-done { border-color: var(--ok); background: #f0fdf4; }
.dropzone.dz-done::after {
    content: '✓'; position: absolute; right: 12px; top: 50%;
    transform: translateY(-50%); color: var(--ok); font-weight: 800;
}
.dropzone.dz-disabled { opacity: .45; }

.status-line { font-size: 12px; min-height: 16px; margin-top: 6px; color: #334155; }
.status-ok { color: var(--ok); }
.status-err { color: var(--err); }
.status-warn { color: var(--warn); }

.permuta-off { opacity: .35; }
.permuta-off input { pointer-events: none; }

/* -------------------------------------------------------- dati manuali */
.manual-label {
    display: block; font-size: 11px; font-weight: 700; text-transform: uppercase;
    color: var(--muted); margin: 8px 0 3px;
}
.manual-field {
    width: 100%; padding: 8px 10px; border: 1px solid var(--line);
    border-radius: 8px; font-size: 15px;
}
.manual-field:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* --------------------------------------------------------- abbonamento */
.chip-piano {
    border-radius: 999px; padding: 5px 12px; font-size: 12px; font-weight: 700;
    text-decoration: none !important; white-space: nowrap;
}
.chip-trial { background: #fbbf24; color: #451a03 !important; }
.chip-trial:hover { background: #f59e0b; }
.chip-scaduto { background: var(--err); color: #fff !important; }
.chip-attivo { background: #166534; color: #dcfce7 !important; }

.billing-card {
    background: #fff; border-radius: 16px; padding: 28px 32px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08); max-width: 560px;
}
.billing-badge {
    display: inline-block; border-radius: 999px; padding: 6px 16px;
    font-weight: 800; font-size: 14px; margin-bottom: 12px;
}
.badge-ok { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.badge-trial { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.badge-scaduto { background: #fef2f2; color: var(--err); border: 1px solid #fecaca; }
.billing-price { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 18px; }
.price-row { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.price-big { font-size: 40px; font-weight: 800; }
.price-features { list-style: none; padding: 0; margin: 0 0 18px; }
.price-features li { padding: 4px 0; font-size: 14px; }

/* -------------------------------------------------------- pagine legali */
.legal-page { background: #fff; border-radius: 12px; padding: 30px 34px; margin-top: 24px;
    margin-bottom: 40px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.legal-page h1 { font-size: 26px; margin: 6px 0 4px; }
.legal-page h2 { font-size: 17px; margin: 26px 0 8px; border-bottom: 1px solid var(--line); padding-bottom: 5px; }
.legal-page p, .legal-page li { font-size: 14px; line-height: 1.65; }
.legal-page .data-table { margin: 10px 0; }
.legal-page .data-table td, .legal-page .data-table th { font-size: 13px; }

.site-footer {
    text-align: center; padding: 18px 10px 26px; font-size: 12px; color: var(--muted);
}
.site-footer a { color: var(--muted); text-decoration: underline; }
.auth-wrap + .site-footer, .workspace + .site-footer { margin-top: -10px; }
.auth-wrap { min-height: calc(100vh - 70px); }

/* ---------------------------------------------------------- responsive */
@media (max-width: 1120px) {
    .workspace { flex-direction: column; }
    .sidebar { width: 100%; position: static; height: auto; display: grid;
        grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
    .panel { margin-bottom: 0; }
    .sheet-area { width: 100%; }
}
@media (max-width: 860px) {
    .sheet-area { padding: 8px 6px 30px 6px; }
    .sidebar { padding: 10px; grid-template-columns: 1fr; }
    /* 16px: sotto questa soglia iOS forza uno zoom automatico sul focus */
    .page input, .page textarea { font-size: 16px; }
    .page .row { flex-wrap: wrap; }
    .dropzone { padding: 14px 12px; }
}
@media (max-width: 640px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
    .topbar-links { gap: 10px; flex-wrap: wrap; }
    .user-chip { display: none; }
}

@media print {
    .no-print { display: none !important; }
    body, .workspace-body { background: #fff; }
    .sheet-area { padding: 0; }
    .page { box-shadow: none; margin: 0; }
}
