/* N3 Control Panel — tema in stile Apple sopra DevExtreme Fluent.
   Font di sistema, superfici traslucide, angoli morbidi, accento iOS blue. */

:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --surface-2: #fbfbfd;
    --sidebar: rgba(246, 246, 248, 0.78);
    --text: #1d1d1f;
    --text-2: #6e6e73;
    --text-3: #86868b;
    --separator: rgba(60, 60, 67, 0.12);
    --accent: #0071e3;
    --accent-hover: #0077ed;
    --green: #34c759;
    --orange: #ff9500;
    --red: #ff3b30;
    --gray: #8e8e93;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI Variable Text", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Struttura ---------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    width: 232px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 18px 12px;
    background: var(--sidebar);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-right: 1px solid var(--separator);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px 18px;
    color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-mark {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, #0a84ff, #5e5ce6);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: -0.02em;
}
.brand-text { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }

.nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav-section {
    padding: 14px 10px 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 8px;
    color: var(--text);
    font-size: 13.5px;
}
.nav-item i { font-size: 17px; color: var(--accent); }
.nav-item:hover { background: rgba(0, 0, 0, 0.05); text-decoration: none; }
.nav-item.active { background: rgba(0, 113, 227, 0.12); font-weight: 600; }

.sidebar-footer {
    border-top: 1px solid var(--separator);
    padding: 12px 10px 0;
    font-size: 12px;
    color: var(--text-2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.sidebar-footer .user { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content { flex: 1; min-width: 0; padding: 28px 36px 48px; max-width: 1440px; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 24px;
}
.page-header h1 {
    margin: 0;
    font-size: 30px;
    font-weight: 700;
    letter-spacing: -0.025em;
}
.breadcrumb { font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Superfici ---------- */

.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 22px;
    margin-bottom: 20px;
}
.card-title {
    margin: 0 0 14px;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.01em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-subtitle { font-size: 13px; color: var(--text-2); font-weight: 400; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1280px) { .grid-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 1100px) { .grid-3, .grid-4, .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) {
    .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .content { padding: 20px 16px; }
}

/* KPI */
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.kpi-label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.kpi-value { font-size: 32px; font-weight: 700; letter-spacing: -0.03em; margin-top: 4px; }
.kpi-value small { font-size: 16px; color: var(--text-3); font-weight: 500; letter-spacing: 0; }
.kpi-foot { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* Liste raggruppate stile Impostazioni iOS */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 11px 0;
    border-bottom: 1px solid var(--separator);
}
.list li:last-child { border-bottom: 0; }
.list .label { color: var(--text-2); }
.list .value { font-weight: 500; text-align: right; }
.empty { color: var(--text-3); padding: 8px 0; }

/* Badge di stato */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: rgba(142, 142, 147, 0.14);
    color: var(--text-2);
    white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.green { background: rgba(52, 199, 89, 0.14); color: #248a3d; }
.pill.orange { background: rgba(255, 149, 0, 0.14); color: #c93400; }
.pill.red { background: rgba(255, 59, 48, 0.12); color: #d70015; }
.pill.blue { background: rgba(0, 113, 227, 0.12); color: var(--accent); }
.pill.plain::before { display: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 3px 10px; border-radius: 999px; background: var(--bg); font-size: 12px; font-weight: 500; }

.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-2); }
.danger { color: var(--red); }

pre.code {
    background: #1d1d1f;
    color: #f5f5f7;
    font-family: var(--mono);
    font-size: 12.5px;
    padding: 16px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 0;
}

.callout {
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 20px;
    background: rgba(255, 149, 0, 0.1);
    border: 1px solid rgba(255, 149, 0, 0.3);
}
.callout.blue { background: rgba(0, 113, 227, 0.07); border-color: rgba(0, 113, 227, 0.25); }
.callout strong { display: block; margin-bottom: 6px; }

/* ---------- Bottoni ---------- */

.btn, .link-button {
    font-family: var(--font);
    cursor: pointer;
}
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 16px;
    border-radius: 999px;
    border: 0;
    font-size: 13.5px;
    font-weight: 500;
    background: rgba(0, 0, 0, 0.06);
    color: var(--text);
    transition: background 0.15s ease;
}
.btn:hover { background: rgba(0, 0, 0, 0.1); text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.destructive { background: rgba(255, 59, 48, 0.1); color: var(--red); }
.btn.destructive:hover { background: rgba(255, 59, 48, 0.18); }
.btn.small { height: 28px; padding: 0 12px; font-size: 12.5px; }
.link-button { background: none; border: 0; padding: 0; color: var(--accent); font-size: 12px; }

/* ---------- Form ---------- */

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 760px) { .form-grid { grid-template-columns: 1fr; } }
.field label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.field-validation-error, .validation-summary-errors { color: var(--red); font-size: 12.5px; }
.validation-summary-errors ul { margin: 0 0 12px; padding-left: 18px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.module {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--separator);
}
.module-name { font-weight: 600; }
.module-desc { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.module.core { opacity: 0.75; }

/* ---------- Ritocchi DevExtreme ---------- */

.dx-widget, .dx-widget input, .dx-widget textarea { font-family: var(--font) !important; }
.dx-texteditor.dx-editor-outlined, .dx-texteditor.dx-editor-filled { border-radius: var(--radius-sm); }
.dx-datagrid { border-radius: var(--radius); overflow: hidden; }
.dx-datagrid-headers { color: var(--text-2); font-weight: 600; font-size: 12.5px; }
.dx-datagrid .dx-row > td { padding-top: 11px; padding-bottom: 11px; }
.dx-datagrid-borders > .dx-datagrid-headers,
.dx-datagrid-borders > .dx-datagrid-rowsview,
.dx-datagrid-borders > .dx-datagrid-total-footer { border-color: var(--separator); }
.dx-datagrid .dx-data-row:hover > td { background: rgba(0, 113, 227, 0.04); cursor: pointer; }
.dx-switch.dx-switch-on-value .dx-switch-container::before { background-color: var(--green); border-color: var(--green); }
.dx-switch.dx-switch-on-value .dx-switch-handle::before { background-color: #fff; }

/* ---------- Login ---------- */

.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: radial-gradient(1200px 600px at 20% 0%, #e8f0ff 0%, transparent 60%),
                radial-gradient(1000px 600px at 100% 100%, #f1e9ff 0%, transparent 60%),
                var(--bg);
    padding: 16px;
}
.auth-card {
    width: 100%;
    max-width: 380px;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
    padding: 36px 32px 28px;
}
.auth-card .brand-mark { width: 52px; height: 52px; border-radius: 14px; font-size: 20px; margin: 0 auto 16px; }
.auth-card h1 { text-align: center; font-size: 24px; margin: 0 0 6px; letter-spacing: -0.02em; }
.auth-card p { text-align: center; color: var(--text-2); margin: 0 0 24px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .btn { width: 100%; justify-content: center; height: 40px; margin-top: 8px; }

/* ---------- Assistente AI: avanzamento rispetto al tetto mensile ---------- */
.ai-meter-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.ai-meter-value { font-size: 28px; font-weight: 700; letter-spacing: -0.03em; }
.ai-bar { position: relative; height: 10px; border-radius: 999px; background: var(--bg); overflow: visible; }
.ai-bar-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }
.ai-bar-fill.green { background: var(--green); }
.ai-bar-fill.orange { background: var(--orange); }
.ai-bar-fill.red { background: var(--red); }
.ai-bar-mark { position: absolute; top: -3px; width: 2px; height: 16px; border-radius: 1px; background: var(--text-3); }

/* ---------- Impostazioni AI ---------- */
.ai-setting { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--separator); }
.ai-setting:last-of-type { border-bottom: 0; }
.ai-setting-label label { font-weight: 600; margin-right: 6px; }
.ai-setting-label .hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.ai-setting-input { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.ai-inline-form { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.ai-inline-form.grow { flex: 1; }
.ai-input { width: 100%; max-width: 360px; height: 34px; padding: 0 12px; border: 1px solid var(--separator); border-radius: var(--radius-sm); background: var(--surface); font: inherit; color: var(--text); }
input[type=file].ai-input { padding: 5px 8px; }
.ai-input:focus { outline: 2px solid rgba(0, 113, 227, 0.35); border-color: var(--accent); }
.ai-ok { color: #248a3d; }
.ai-test-result { font-size: 12.5px; max-width: 520px; }
@media (max-width: 900px) { .ai-setting { grid-template-columns: 1fr; } .ai-setting-input { justify-content: flex-start; } }
.ai-status { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 14px; margin-bottom: 8px; border-radius: var(--radius-sm); background: var(--bg); font-size: 13px; }

/* ---------- Registro chiamate ---------- */
.ai-calls-filter { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; }
.ai-calls-filter .field { margin: 0; min-width: 160px; }
.ai-calls-quick { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ai-question { font-family: var(--mono); font-size: 12px; padding: 1px 8px; border-radius: 999px; background: color-mix(in srgb, var(--q) 14%, transparent); color: color-mix(in srgb, var(--q) 80%, black); }
.dx-datagrid .ai-call-row > td:first-child { box-shadow: inset 3px 0 0 var(--q); }
#callsGrid { max-width: 100%; }
