/* DriverGrid PWA — UI mobile-first */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:        #f8fafc;
    --surface:   #ffffff;
    --surface2:  #f1f5f9;
    --border:    #e2e8f0;
    --text:      #1e293b;
    --text-muted:#64748b;
    --primary:   #2563eb;
    --primary-dk:#1d4ed8;
    --green:     #16a34a;
    --green-dk:  #15803d;
    --amber:     #d97706;
    --red:       #dc2626;
    --radius:    12px;
    --radius-sm: 8px;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */

#app {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

.header {
    background: var(--surface);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
}

.header-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 1px;
}

.header-back {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 0;
}

.header-action {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
    transition: color .15s;
}
.header-action:hover { color: var(--text); }

/* ── Login screen ────────────────────────────────────────────────────────── */

.login-screen {
    justify-content: center;
    align-items: center;
    padding: 24px 20px;
    background: var(--bg);
}

.login-logo {
    text-align: center;
    margin-bottom: 36px;
}

.login-logo-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    border-radius: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin-bottom: 14px;
    box-shadow: 0 8px 24px rgba(37,99,235,.4);
}

.login-logo h1 {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -.3px;
}

.login-logo p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 28px 24px;
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border);
}

/* ── Forms ───────────────────────────────────────────────────────────────── */

.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 7px;
}

.form-control {
    width: 100%;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 16px; /* 16px evita zoom su iOS */
    padding: 13px 14px;
    outline: none;
    transition: border-color .15s;
    -webkit-appearance: none;
}

.form-control:focus {
    border-color: var(--primary);
}

.form-control::placeholder {
    color: #94a3b8;
}

/* ── Bottoni ─────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    padding: 14px 20px;
    transition: opacity .15s, transform .1s;
    width: 100%;
    -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary   { background: var(--primary);  color: #fff; }
.btn-green     { background: var(--green);    color: #fff; }
.btn-amber     { background: var(--amber);    color: #fff; }
.btn-danger    { background: var(--red);      color: #fff; }
.btn-ghost     { background: var(--surface2); color: var(--text); }
.btn-sm        { padding: 9px 14px; font-size: 13px; border-radius: 7px; width: auto; }

/* ── Alert ───────────────────────────────────────────────────────────────── */

.alert {
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 16px;
}

.alert-error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.alert-info  { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

/* ── Content area ────────────────────────────────────────────────────────── */

.content {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
}

/* ── Tabs ────────────────────────────────────────────────────────────────── */

.tabs {
    display: flex;
    gap: 4px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 16px;
}

.tab {
    flex: 1;
    text-align: center;
    padding: 9px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    background: none;
    transition: background .15s, color .15s;
}

.tab.active {
    background: var(--primary);
    color: #fff;
}

/* ── Card corsa ──────────────────────────────────────────────────────────── */

.corsa-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: border-color .15s, transform .1s;
    -webkit-tap-highlight-color: transparent;
}

.corsa-card:active { transform: scale(.99); }

.corsa-card.urgente {
    border-left: 3px solid var(--red);
}

.corsa-time {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -.5px;
}

.corsa-date {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.corsa-route {
    font-size: 13px;
    color: var(--text);
    margin-bottom: 10px;
}

.corsa-route .from {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 4px;
}

.corsa-route .to {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding-left: 4px;
    border-left: 2px solid var(--border);
    margin-left: 7px;
    padding-top: 4px;
}

.dot-green { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex-shrink: 0; margin-top: 5px; }
.dot-red   { width: 8px; height: 8px; border-radius: 50%; background: var(--red);   flex-shrink: 0; margin-top: 5px; }

.corsa-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 10px;
}

.badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 20px;
}

/* Stato badge */
.stato-assegnato          { background: #eff6ff; color: #2563eb;  border: 1px solid #bfdbfe; }
.stato-autista_sul_posto  { background: #fff7ed; color: #c2410c;  border: 1px solid #fed7aa; }
.stato-in_corso           { background: #f0fdf4; color: #16a34a;  border: 1px solid #bbf7d0; }
.stato-completato         { background: #f0fdf4; color: #15803d;  border: 1px solid #86efac; }
.stato-confermato         { background: #eff6ff; color: #1d4ed8;  border: 1px solid #93c5fd; }
.stato-default            { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }

/* ── Dettaglio corsa ─────────────────────────────────────────────────────── */

.detail-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
}

.detail-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.detail-value {
    font-size: 15px;
    color: var(--text);
    font-weight: 500;
}

.detail-value.big {
    font-size: 19px;
    font-weight: 800;
}

.address-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.stato-action-area {
    padding: 16px;
    position: sticky;
    bottom: 0;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

/* ── Empty state ─────────────────────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: .4;
}

.empty-state p {
    font-size: 14px;
}

/* ── Spinner ─────────────────────────────────────────────────────────────── */

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--surface2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    margin: 40px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Bottom nav ──────────────────────────────────────────────────────────── */

.bottom-nav {
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    background: none;
    gap: 3px;
    -webkit-tap-highlight-color: transparent;
    transition: color .15s;
}

.nav-item.active { color: var(--primary); }

.nav-icon { font-size: 20px; }

/* ── Notifica offline ────────────────────────────────────────────────────── */

.offline-bar {
    background: var(--amber);
    color: #1c1200;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    padding: 6px;
    display: none;
}

.offline-bar.visible { display: block; }

/* ── Utils ───────────────────────────────────────────────────────────────── */

.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8  { margin-bottom: 8px; }
.text-muted { color: var(--text-muted); font-size: 13px; }
.fw-700 { font-weight: 700; }

/* ── Nuova corsa — form + AI panel ──────────────────────────────────────── */

/* ── Nuova corsa — layout ─────────────────────────────────────────────────── */

.nc-content {
    padding: 16px 16px 32px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.nc-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
}

.nc-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .7px;
    color: var(--text-muted);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.nc-row {
    display: flex;
    gap: 10px;
}
.nc-row .form-group { flex: 1; }

.nc-col-sm { flex: 0 0 88px !important; }

/* Route visual connector */
.nc-route-field {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}
.nc-route-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 32px;
}
.nc-route-dot--green { background: var(--green); box-shadow: 0 0 6px rgba(34,197,94,.5); }
.nc-route-dot--red   { background: var(--red);   box-shadow: 0 0 6px rgba(239,68,68,.5); }
.nc-route-line {
    width: 2px;
    height: 10px;
    background: var(--border);
    margin: 3px 0 3px 5px;
}

.nc-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 6px 0 14px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
}
.nc-divider::before, .nc-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ── Pannello AI ──────────────────────────────────────────────────────────── */

.ai-panel {
    background: #f5f3ff;
    border: 1px solid #ddd6fe;
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 10px;
    position: relative;
    overflow: hidden;
}
.ai-panel::before {
    content: '';
    position: absolute;
    top: -40px; right: -40px;
    width: 120px; height: 120px;
    background: radial-gradient(circle, rgba(124,58,237,.1) 0%, transparent 70%);
    pointer-events: none;
}

.ai-panel-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.ai-panel-badge {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #7c3aed, #4f46e5);
    color: #fff;
    font-size: 11px;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    letter-spacing: .5px;
    box-shadow: 0 4px 12px rgba(124,58,237,.4);
}

.ai-panel-title {
    font-size: 15px;
    font-weight: 700;
    color: #5b21b6;
    line-height: 1.2;
}

.ai-panel-sub {
    font-size: 12px;
    color: #7c3aed;
    opacity: .75;
    margin-top: 1px;
}

/* Bottone Esempi */
.ai-ex-btn {
    height: 28px;
    padding: 0 10px;
    border-radius: 6px;
    border: 1px solid #c4b5fd;
    background: #fff;
    color: #7c3aed;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    transition: background .15s;
}
.ai-ex-btn:hover { background: #ede9fe; }
#ai-ex-chev { transition: transform .2s; flex-shrink: 0; }

/* Pannello esempi */
.ai-examples-panel {
    display: none;
    margin-bottom: 12px;
    padding: 12px 14px;
    background: #fff;
    border-radius: 8px;
    border: 1px solid #e9d5ff;
}
.ai-examples-panel.open { display: block; }

.ai-ex-label {
    font-size: 11px;
    font-weight: 700;
    color: #7c3aed;
    text-transform: uppercase;
    letter-spacing: .4px;
    margin-bottom: 10px;
}

.ai-ex-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ai-ex {
    padding: 7px 10px;
    border-radius: 6px;
    background: #faf5ff;
    border: 1px solid #ede9fe;
    color: #374151;
    font-size: 12px;
    line-height: 1.5;
}

.ai-ex-tag {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    border-radius: 4px;
    padding: 1px 6px;
    margin-right: 5px;
    vertical-align: middle;
    white-space: nowrap;
}

.ai-ex-footer {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 10px;
    line-height: 1.8;
}
.ai-ex-footer strong { color: #dc2626; font-weight: 600; }

.ai-input-row { margin-bottom: 10px; }

.ai-textarea {
    width: 100%;
    background: #fff;
    border: 1.5px solid #c4b5fd;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    padding: 10px 12px;
    resize: none;
    outline: none;
    min-height: 56px;
    font-family: inherit;
    transition: border-color .15s;
    line-height: 1.5;
}
.ai-textarea:focus { border-color: #7c3aed; }
.ai-textarea::placeholder { color: #a78bfa; font-size: 13px; }

.ai-toolbar {
    display: flex;
    gap: 8px;
}

.ai-btn-mic {
    height: 40px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    border: 1.5px solid #c4b5fd;
    background: #fff;
    color: #7c3aed;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    transition: all .15s;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}
.ai-btn-mic:hover  { border-color: #7c3aed; background: #ede9fe; }
.ai-btn-mic.recording {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #dc2626;
}

.ai-btn-parse {
    flex: 1;
    height: 40px;
    padding: 0 16px;
    border-radius: var(--radius-sm);
    border: none;
    background: linear-gradient(135deg, #7c3aed, #4f46e5);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    transition: opacity .15s;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 2px 8px rgba(124,58,237,.35);
}
.ai-btn-parse:disabled { opacity: .4; }

.ai-result-ok {
    margin-top: 12px;
    padding: 10px 14px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: #15803d;
    line-height: 1.5;
    display: none;
}

.ai-result-err {
    margin-top: 12px;
    padding: 10px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: #dc2626;
    display: none;
}

.ai-rec-status {
    font-size: 12px;
    color: #dc2626;
    font-weight: 600;
    margin-top: 8px;
    display: none;
    align-items: center;
    gap: 6px;
}
.ai-rec-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #dc2626;
    animation: pulse-dot 1s ease-in-out infinite;
    flex-shrink: 0;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: .4; transform: scale(.7); }
}

.ai-actions {
    display: none;
    gap: 8px;
    margin-top: 12px;
}

.ai-btn-inserisci {
    height: 38px;
    padding: 0 18px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--green);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 8px rgba(34,197,94,.3);
    -webkit-tap-highlight-color: transparent;
}

.ai-btn-rifiuta {
    height: 38px;
    padding: 0 18px;
    border-radius: var(--radius-sm);
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: var(--red);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    -webkit-tap-highlight-color: transparent;
}

.ai-loading-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 10;
    background: rgba(245,243,255,.9);
    backdrop-filter: blur(6px);
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 10px;
    border-radius: var(--radius);
}

.ai-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #ddd6fe;
    border-top-color: #7c3aed;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

.ai-loading-lbl {
    font-size: 13px;
    font-weight: 700;
    color: #5b21b6;
    letter-spacing: .3px;
}

.ai-filled {
    border-color: var(--green) !important;
    background-color: #f0fdf4 !important;
}

/* ── Bottone "Nuova corsa" in header ─────────────────────────────────────── */

.btn-new-ride {
    height: 36px;
    padding: 0 14px;
    border-radius: 20px;
    border: none;
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    transition: opacity .15s;
    box-shadow: 0 2px 8px rgba(59,130,246,.35);
}
.btn-new-ride:active { opacity: .8; }

/* ── Btn salva corsa ─────────────────────────────────────────────────────── */

#btn-salva-corsa {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 6px;
    width: 100%;
}
