/* Portale Agenti - microapp esposta. Stile mobile-first con il brand
   Raffaele (stessi token del tema principale, layout semplificato). */

:root {
    --brand-primary: #e5142c;
    --brand-primary-hover: #be1629;
    --brand-dark: #890c1a;
    --app-bg: #f1f4f6;
    --surface-bg: #ffffff;
    --border-color: #dee2e6;
    --border-soft: #e9ecef;
    --text-main: #495057;
    --text-muted: #6c757d;
    --panel-title-color: rgba(137, 12, 26, 0.75);
    --row-hover-bg: #fdf2f3;
    --surface-shadow: 0 0.46875rem 2.1875rem rgba(115, 10, 22, 0.03), 0 0.9375rem 1.40625rem rgba(115, 10, 22, 0.03), 0 0.25rem 0.53125rem rgba(115, 10, 22, 0.05), 0 0.125rem 0.1875rem rgba(115, 10, 22, 0.03);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--app-bg);
    color: var(--text-main);
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--brand-primary); text-decoration: none; }

/* ---- Struttura ---- */

.agenti-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.agenti-topbar {
    align-items: center;
    background: var(--surface-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 10px 16px;
}

.agenti-logo { height: 34px; }

.agenti-topbar-right {
    align-items: center;
    display: flex;
    gap: 10px;
}

.agenti-topbar-right form { margin: 0; }

.agenti-user {
    color: var(--text-muted);
    font-size: 13px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agenti-nav {
    background: var(--surface-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 6px;
    padding: 6px 12px;
}

.agenti-nav a {
    border-radius: 999px;
    color: var(--text-main);
    font-size: 14px;
    font-weight: 600;
    padding: 7px 14px;
}

.agenti-nav a:hover { background: var(--row-hover-bg); }

.agenti-nav a.active {
    background: #fff1f2;
    color: var(--brand-primary);
}

.agenti-main {
    flex: 1;
    margin: 0 auto;
    max-width: 860px;
    padding: 18px 14px 30px;
    width: 100%;
}

.agenti-footer {
    color: var(--text-muted);
    font-size: 12px;
    padding: 14px 16px 20px;
    text-align: center;
}

/* ---- Intestazione pagina ---- */

.page-header {
    align-items: flex-start;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: space-between;
    margin-bottom: 16px;
}

.page-header h1 {
    color: #343a40;
    font-size: 22px;
    margin: 0 0 4px;
}

.page-header p {
    color: var(--text-muted);
    font-size: 13px;
    margin: 0;
}

.header-actions {
    align-items: center;
    display: flex;
    gap: 10px;
}

/* ---- Pannelli ---- */

.panel {
    background: var(--surface-bg);
    border-radius: 8px;
    box-shadow: var(--surface-shadow);
    margin-bottom: 18px;
    /* NIENTE overflow:hidden: taglierebbe il dropdown della ricerca
       cliente, che e' posizionato assoluto e sborda sotto il pannello. */
    padding-bottom: 14px;
}

.panel-header {
    align-items: center;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    gap: 10px;
    justify-content: space-between;
    margin-bottom: 14px;
    padding: 12px 18px;
}

.panel-header h2 {
    color: var(--panel-title-color);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
    margin: 0;
    text-transform: uppercase;
}

.panel-header span {
    color: var(--text-muted);
    font-size: 12px;
    text-align: right;
}

/* ---- Form ---- */

.form-field { margin: 0 18px 14px; }

.form-field label {
    color: var(--text-main);
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
}

.form-control {
    background: #ffffff;
    border: 1px solid #b9c2d0;
    border-radius: 6px;
    color: var(--text-main);
    font-family: inherit;
    /* 16px: sotto questa soglia iOS zooma la pagina al focus del campo. */
    font-size: 16px;
    padding: 9px 12px;
    width: 100%;
}

.form-control:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(229, 20, 44, 0.15);
    outline: none;
}

.form-control-inline {
    font-size: 13px;
    padding: 5px 8px;
    min-width: 150px;
}

.textarea-control { resize: vertical; }

.checkbox-label {
    align-items: center;
    display: inline-flex;
    gap: 8px;
    font-weight: 600;
}

.validation-message {
    color: var(--brand-primary);
    display: block;
    font-size: 12px;
    margin-top: 4px;
}

.filter-actions {
    display: flex;
    gap: 10px;
    margin: 0 18px 6px;
}

.hint-text {
    color: var(--text-muted);
    font-size: 12px;
    margin: 6px 18px 4px;
}

/* ---- Bottoni ---- */

.btn {
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    display: inline-block;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 8px 16px;
    text-align: center;
}

.btn:disabled { cursor: not-allowed; opacity: 0.55; }

.btn-primary {
    background: var(--brand-primary);
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) { background: var(--brand-primary-hover); }

.btn-ghost {
    background: #ffffff;
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-ghost:hover:not(:disabled) { background: var(--row-hover-bg); }

.btn-block { display: block; width: 100%; }

/* ---- Avvisi ---- */

.notice {
    background: #fff8e6;
    border: 1px solid #f0dfae;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 14px;
    padding: 10px 14px;
}

.notice-error {
    background: #fdeef0;
    border-color: #f3c2c9;
    color: #a1101f;
}

.empty-state {
    background: #fafbfc;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    color: var(--text-muted);
    margin: 0 18px 8px;
    padding: 22px 16px;
    text-align: center;
}

.panel > .empty-state { margin: 0 18px 8px; }

/* ---- Typeahead (stesse classi delle pagine interne) ---- */

.mention-box { position: relative; }

.mention-dropdown {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 14px 34px rgba(16, 24, 40, 0.16);
    left: 0;
    max-height: 280px;
    overflow-y: auto;
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 30;
}

.mention-dropdown button {
    background: none;
    border: none;
    border-bottom: 1px solid var(--border-soft);
    cursor: pointer;
    display: block;
    font-family: inherit;
    font-size: 14px;
    padding: 10px 14px;
    text-align: left;
    width: 100%;
}

.mention-dropdown button:hover { background: var(--row-hover-bg); }

.mention-dropdown button small {
    color: var(--text-muted);
    margin-left: 6px;
}

.typeahead-empty {
    color: var(--text-muted);
    font-size: 13px;
    padding: 12px 14px;
}

.typeahead-chip {
    align-items: center;
    background: #fff1f2;
    border: 1px solid #fecdd3;
    border-radius: 8px;
    display: flex;
    gap: 10px;
    justify-content: space-between;
    margin: 0 18px 10px;
    padding: 10px 14px;
}

.typeahead-chip small { color: var(--text-muted); }

/* ---- Tabelle ---- */

.table-wrap {
    margin: 0 18px 8px;
    overflow-x: auto;
    scrollbar-width: thin;
}

.data-table {
    border-collapse: collapse;
    font-size: 14px;
    width: 100%;
}

.data-table th {
    border-bottom: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 8px 10px;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}

.data-table td {
    border-bottom: 1px solid var(--border-soft);
    padding: 9px 10px;
    vertical-align: middle;
}

.data-table td small {
    color: var(--text-muted);
    display: block;
    font-size: 12px;
}

.data-table .numeric { text-align: right; white-space: nowrap; }

.nowrap { white-space: nowrap; }

/* ---- Badge stato ---- */

.status-badge {
    border-radius: 999px;
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 12px;
    white-space: nowrap;
}

.status-warning { background: #fff4d6; color: #8a6100; }
.status-info { background: #e3edff; color: #1f4fa3; }
.status-danger { background: #fdeef0; color: #a1101f; }
.status-success { background: #e2f6e9; color: #1c7c3d; }
.status-muted { background: #eef1f5; color: #52637a; }

/* ---- Dettaglio ---- */

.definition-grid {
    display: grid;
    gap: 12px 18px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin: 0 18px 14px;
}

.definition-grid dt {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.definition-grid dd { margin: 3px 0 0; }

.mail-body-preview {
    background: #fafbfc;
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    padding: 10px 12px;
    white-space: pre-line;
}

.timeline { margin: 0 18px; }

.timeline-item {
    border-left: 2px solid #fecdd3;
    margin-bottom: 4px;
    padding: 0 0 12px 14px;
    position: relative;
}

.timeline-item::before {
    background: var(--brand-primary);
    border-radius: 50%;
    content: "";
    height: 8px;
    left: -5px;
    position: absolute;
    top: 6px;
    width: 8px;
}

.timeline-item strong { font-size: 13px; }

.timeline-item p { margin: 2px 0 4px; }

.timeline-item small { color: var(--text-muted); font-size: 12px; }

.preline { white-space: pre-line; }

/* ---- Elenco pratiche a card ---- */

.pratiche-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pratica-card {
    background: var(--surface-bg);
    border-radius: 8px;
    box-shadow: var(--surface-shadow);
    color: var(--text-main);
    display: block;
    padding: 14px 16px;
}

.pratica-card:hover { background: var(--row-hover-bg); }

.pratica-card-top {
    align-items: center;
    display: flex;
    gap: 10px;
    justify-content: space-between;
    margin-bottom: 4px;
}

.pratica-card-top strong { color: var(--brand-dark); font-size: 16px; }

.pratica-card-cliente { font-weight: 600; }

.pratica-card-cliente small { color: var(--text-muted); font-weight: 400; margin-left: 6px; }

.pratica-card-meta {
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    font-size: 12px;
    gap: 4px 14px;
    margin-top: 4px;
}

.pratica-card-esito {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 4px;
}

/* ---- Modale anteprima allegati ---- */

.modal-overlay {
    align-items: center;
    background: rgba(28, 28, 27, 0.55);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 14px;
    position: fixed;
    z-index: 100;
}

.modal-window {
    background: var(--surface-bg);
    border-radius: 10px;
    box-shadow: 0 14px 34px rgba(16, 24, 40, 0.3);
    display: flex;
    flex-direction: column;
    height: min(92vh, 900px);
    max-width: 980px;
    overflow: hidden;
    width: 100%;
}

.modal-header {
    align-items: center;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    gap: 10px;
    justify-content: space-between;
    padding: 10px 14px;
}

.modal-header h3 {
    font-size: 15px;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.modal-header > div { display: flex; flex-shrink: 0; gap: 8px; }

.modal-body { flex: 1; }

.modal-body iframe {
    border: none;
    display: block;
    height: 100%;
    width: 100%;
}

/* ---- Login ---- */

.auth-panel {
    background: var(--surface-bg);
    border-radius: 10px;
    box-shadow: var(--surface-shadow);
    margin: 40px auto 0;
    max-width: 420px;
    padding: 22px 22px 18px;
}

.auth-panel .form-field,
.auth-panel .hint-text,
.auth-panel .notice { margin-left: 0; margin-right: 0; }

.auth-panel-header { margin-bottom: 16px; }

.auth-panel-header h1 {
    color: #343a40;
    font-size: 22px;
    margin: 0;
}

.auth-panel-header span {
    color: var(--text-muted);
    font-size: 13px;
}

/* ---- Touch: bersagli comodi su tablet e telefono ---- */

@media (pointer: coarse) {
    .btn { min-height: 44px; padding: 10px 18px; }
    .agenti-nav a { padding: 10px 16px; }
    input[type="checkbox"] { height: 20px; width: 20px; }
    .mention-dropdown button { padding: 13px 14px; }
    .data-table td { padding-bottom: 11px; padding-top: 11px; }
}

/* ---- Tablet ---- */

@media (max-width: 900px) {
    .agenti-main { max-width: 100%; }
}

/* ---- Telefono: le tabelle diventano card impilate ---- */

@media (max-width: 640px) {
    .agenti-main { padding: 14px 10px 24px; }
    .page-header { flex-direction: column; }
    .page-header h1 { font-size: 19px; }
    .page-header > .btn, .header-actions { align-self: stretch; }
    .header-actions { justify-content: space-between; }
    .form-field, .table-wrap, .filter-actions, .hint-text, .definition-grid, .timeline, .typeahead-chip, .empty-state, .panel > .empty-state { margin-left: 12px; margin-right: 12px; }
    .panel-header { padding: 10px 12px; }
    .filter-actions { flex-direction: column; }
    .filter-actions .btn { width: 100%; }
    .typeahead-chip { align-items: flex-start; flex-direction: column; }
    .typeahead-chip .btn { align-self: stretch; }
    .agenti-user { max-width: 120px; }

    /* Tabelle -> card: niente scroll orizzontale su telefono. */
    .table-wrap { overflow-x: visible; }
    .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
    .data-table thead { display: none; }
    .data-table tr {
        border: 1px solid var(--border-soft);
        border-radius: 8px;
        margin-bottom: 10px;
        padding: 6px 12px;
    }
    .data-table tr.row-selected {
        background: #fff1f2;
        border-color: #fecdd3;
    }
    .data-table td {
        align-items: center;
        border-bottom: none;
        display: flex;
        gap: 12px;
        justify-content: space-between;
        padding: 6px 0;
        text-align: right;
    }
    .data-table td::before {
        color: var(--text-muted);
        content: attr(data-label);
        flex-shrink: 0;
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.04em;
        text-align: left;
        text-transform: uppercase;
    }
    .data-table td:not([data-label])::before { content: none; }
    .data-table td small { display: inline; }
    .data-table .numeric { text-align: right; }
    .data-table .cell-azione {
        border-top: 1px solid var(--border-soft);
        justify-content: flex-end;
        margin-top: 4px;
        padding-top: 10px;
    }
    .data-table .cell-azione .btn { flex: 1; }
    .data-table .cell-nota { flex-wrap: wrap; }
    .data-table .cell-nota .form-control-inline { flex: 1 1 100%; font-size: 16px; min-width: 0; }
}
