:root {
    --blue: #3b82f6;
    --blue-dark: #2563eb;
    --bg: #f4f5f7;
    --card: #ffffff;
    --border: #e5e7eb;
    --text: #111827;
    --hint: #6b7280;
    --danger: #ef4444;
    --danger-dark: #dc2626;
    --warn-bg: #fff7f7;
    --warn-border: #fecaca;
    --analyze-bg: #eff6ff;
    --analyze-border: #bfdbfe;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: "Segoe UI", -apple-system, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
}
a { color: var(--blue-dark); }
.topbar {
    background: #1f2937;
    color: #d1d5db;
    display: flex;
    align-items: center;
    padding: 0 12px;
    position: sticky;
    top: 0;
    z-index: 20;
    flex-wrap: wrap;
}
.topbar .brand {
    color: white;
    font-weight: 700;
    padding: 12px 12px 12px 0;
    font-size: 17px;
    white-space: nowrap;
}
.topbar nav {
    display: flex;
    flex-wrap: wrap;
    flex: 1;
}
.topbar nav a {
    color: #d1d5db;
    text-decoration: none;
    padding: 14px 12px;
    font-size: 14px;
    border-bottom: 3px solid transparent;
}
.topbar nav a.active, .topbar nav a:hover {
    color: white;
    border-bottom-color: var(--blue);
}
.topbar .user {
    color: #9ca3af;
    font-size: 13px;
    padding: 8px 0 8px 8px;
    white-space: nowrap;
}
.topbar form.logout { display: inline; margin-left: 8px; }
.topbar button.link-btn {
    background: none; border: none; color: #9ca3af; cursor: pointer; font-size: 13px; padding: 0;
    text-decoration: underline;
}
.container {
    max-width: 980px;
    margin: 0 auto;
    padding: 18px 14px 60px;
}
h1.page-title { font-size: 22px; margin: 4px 0 4px; }
p.hint, .hint { color: var(--hint); font-size: 13px; }
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 16px;
}
.card h2 { font-size: 16px; margin: 0 0 10px; }
.section-title { font-weight: 700; font-size: 14px; color: #374151; margin: 14px 0 6px; }
label { display: block; font-size: 13px; margin: 10px 0 4px; color: #374151; }
input[type=text], input[type=password], input[type=date], input[type=email],
input[type=tel], input[type=file], select, textarea {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 15px;
    font-family: inherit;
    background: white;
}
textarea { min-height: 80px; resize: vertical; }
.btn {
    display: inline-block;
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 9px 16px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    margin: 2px 4px 2px 0;
}
.btn:hover { background: var(--blue-dark); }
.btn.secondary { background: #e5e7eb; color: #1f2937; }
.btn.secondary:hover { background: #d1d5db; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: var(--danger-dark); }
.btn:disabled { background: #9ca3af; cursor: not-allowed; }
.btn-row { margin-top: 10px; }
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: #e5e7eb;
    color: #374151;
}
.badge.draft { background: #fef3c7; color: #92400e; }
.badge.approved { background: #dcfce7; color: #15803d; }
.badge.superseded { background: #e5e7eb; color: #6b7280; }
.task-row {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: white;
}
.task-row .desc { font-weight: 600; }
.task-row .meta { color: var(--hint); font-size: 13px; margin: 2px 0 8px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: #374151; font-size: 13px; }
tr:hover td { background: #f9fafb; }
.empty { color: var(--hint); font-style: italic; padding: 10px 0; }
.flash {
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: 14px;
}
.flash.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.flash.success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.analyze-bar {
    background: var(--analyze-bg);
    border: 1px solid var(--analyze-border);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
}
.danger-zone {
    border: 1px solid var(--warn-border);
    background: var(--warn-bg);
    border-radius: 8px;
    padding: 12px 14px;
    margin-top: 20px;
}
.danger-zone h3 { color: #b91c1c; margin: 0 0 6px; font-size: 14px; }
.tabs { display: flex; gap: 4px; margin: 14px 0 0; flex-wrap: wrap; }
.tabs a {
    padding: 8px 14px;
    text-decoration: none;
    color: #374151;
    background: #e5e7eb;
    border-radius: 6px 6px 0 0;
    font-size: 14px;
}
.tabs a.active { background: white; font-weight: 700; border: 1px solid var(--border); border-bottom: none; }
.tab-panel { background: white; border: 1px solid var(--border); border-radius: 0 8px 8px 8px; padding: 16px; }
.login-wrap { max-width: 360px; margin: 60px auto; padding: 0 16px; }
.login-wrap .card { text-align: center; }
.doc-list li, .verify-list li { margin-bottom: 6px; }
ul.plain { list-style: none; padding: 0; margin: 0; }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.field-row > div { flex: 1; min-width: 140px; }
/* ==================================================================
   FASE 5 — mobile operativo: bottom nav, FAB, comando vocale/rapido
   ================================================================== */
.quick-bar {
    display: flex;
    gap: 8px;
    margin: 10px 0 16px;
    flex-wrap: wrap;
}
.quick-bar .btn { flex: 1; min-width: 140px; text-align: center; }
.mic-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 999px;
    padding: 12px 20px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}
.mic-btn.listening { background: #b91c1c; animation: pulse 1s infinite; }
.mic-btn:disabled { background: #9ca3af; cursor: not-allowed; }
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(185,28,28,0.5); }
    70% { box-shadow: 0 0 0 12px rgba(185,28,28,0); }
    100% { box-shadow: 0 0 0 0 rgba(185,28,28,0); }
}
.quick-text-row { display: flex; gap: 8px; margin-top: 8px; }
.quick-text-row input { flex: 1; }
.voice-status { font-size: 13px; color: var(--hint); margin: 6px 0; min-height: 18px; }
.confirm-card {
    border: 2px solid var(--blue);
    background: var(--analyze-bg);
    border-radius: 10px;
    padding: 14px;
    margin: 10px 0 16px;
}
.confirm-card h3 { margin: 0 0 8px; font-size: 15px; color: #1e3a8a; }
.confirm-card dl { margin: 0; }
.confirm-card dt { font-size: 12px; color: var(--hint); margin-top: 8px; }
.confirm-card dd { margin: 0; font-size: 15px; font-weight: 600; }
.confirm-card .verify { color: #b45309; }
.confirm-card .btn-row { margin-top: 12px; }
.case-search-wrap { position: relative; }
.case-search-results {
    position: absolute;
    left: 0; right: 0; top: 100%;
    background: white;
    border: 1px solid var(--border);
    border-radius: 0 0 8px 8px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
    z-index: 30;
    max-height: 240px;
    overflow-y: auto;
}
.case-search-results button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border: none;
    background: white;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid #f3f4f6;
}
.case-search-results button:hover { background: #f3f4f6; }
.case-selected {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    margin-top: 6px;
}
.case-selected.empty { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.google-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
}
.google-status.connected { background: #dcfce7; color: #15803d; }
.google-status.disconnected { background: #f3f4f6; color: #6b7280; }
.fab-sheet {
    position: fixed;
    left: 12px; right: 12px; bottom: 76px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 -6px 24px rgba(0,0,0,0.18);
    padding: 8px;
    z-index: 50;
}
.fab-sheet a {
    display: block;
    padding: 14px 12px;
    text-decoration: none;
    color: #111827;
    font-weight: 600;
    border-bottom: 1px solid #f3f4f6;
}
.fab-sheet a:last-child { border-bottom: none; }
.bottom-nav {
    display: none;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: white;
    border-top: 1px solid var(--border);
    padding: 6px 0 max(6px, env(safe-area-inset-bottom));
    z-index: 40;
}
.bottom-nav ul {
    list-style: none;
    display: flex;
    margin: 0; padding: 0;
}
.bottom-nav li { flex: 1; text-align: center; }
.bottom-nav a, .bottom-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: #6b7280;
    text-decoration: none;
    font-size: 11px;
    width: 100%;
    padding: 4px 0;
    cursor: pointer;
}
.bottom-nav .icon { font-size: 20px; }
.bottom-nav a.active, .bottom-nav button.active { color: var(--blue-dark); }
.bottom-nav .fab-btn .icon {
    background: var(--blue);
    color: white;
    border-radius: 50%;
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
    margin: -14px auto 0;
    box-shadow: 0 2px 8px rgba(59,130,246,0.5);
}

/* ==================================================================
   Documenti: card mobile-friendly (Parte 2 — separazione automatica)
   ================================================================== */
.doc-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 10px;
    background: white;
}
.doc-card-title { font-weight: 600; margin-bottom: 2px; }
.doc-children {
    border-top: 1px dashed var(--border);
    margin-top: 10px;
    padding-top: 4px;
}
.doc-card-child {
    margin-left: 14px;
    background: #fafafa;
    border-style: dashed;
}
.split-doc-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 10px;
    background: white;
}
.split-doc-card .field-row { margin-top: 8px; }
.split-doc-card .confidence-bar {
    height: 6px;
    border-radius: 3px;
    background: #e5e7eb;
    overflow: hidden;
    margin: 6px 0;
}
.split-doc-card .confidence-fill { height: 100%; background: var(--blue); }
.uncertain-boundary {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
    color: #9a3412;
    font-size: 14px;
}

@media (max-width: 640px) {
    .topbar { flex-direction: column; align-items: stretch; }
    .topbar .brand { padding: 10px 0; }
    .topbar nav a { padding: 10px 8px; }
    .container { padding: 12px 10px 82px; }

    body.has-bottom-nav .topbar nav,
    body.has-bottom-nav .topbar .user { display: none; }
    body.has-bottom-nav .bottom-nav { display: block; }
}
