/*
 * PBX Manager — Foglio di stile principale
 * =========================================
 * Struttura:
 *   1. Variabili CSS
 *   2. Reset / Base
 *   3. Sidebar
 *   4. Main content & top bar
 *   5. Cards & stat cards
 *   6. Tabelle
 *   7. Bottoni
 *   8. Form
 *   9. Badge & Alert
 *  10. Componenti UI (empty state, no-client banner, ecc.)
 *  11. Login page
 *  12. Wizard percorso chiamata
 *  13. Time conditions
 *  14. Utility
 *  15. Responsive
 */

/* ============================================================================
   1. VARIABILI CSS
   ========================================================================== */
:root {
    --sidebar-w:           240px;
    --sidebar-bg:          #0f1521;
    --sidebar-border:      rgba(255,255,255,.06);
    --sidebar-text:        rgba(255,255,255,.55);
    --sidebar-text-hover:  #ffffff;
    --sidebar-active-bg:   rgba(99,102,241,.18);
    --sidebar-active-text: #818cf8;

    --accent:       #6366f1;
    --accent-hover: #4f46e5;
    --surface:      #ffffff;
    --surface-2:    #f8fafc;
    --border:       #e2e8f0;
    --text:         #0f172a;
    --text-muted:   #64748b;
    --danger:       #ef4444;
    --success:      #10b981;
    --warning:      #f59e0b;

    --radius:    10px;
    --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -1px rgba(0,0,0,.04);
}

/* ============================================================================
   2. RESET / BASE
   ========================================================================== */
* { box-sizing: border-box; }

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--surface-2);
    color: var(--text);
    margin: 0;
    min-height: 100vh;
}

code, .mono {
    font-family: 'DM Mono', monospace;
    font-size: 12px;
}

/* ============================================================================
   3. SIDEBAR
   ========================================================================== */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 100;
    border-right: 1px solid var(--sidebar-border);
}

/* Brand */
.sidebar-brand {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-brand .logo-text {
    font-size: 17px;
    font-weight: 600;
    color: #ffffff;
    letter-spacing: -.3px;
}

.sidebar-brand .logo-sub {
    font-size: 11px;
    color: var(--sidebar-text);
    font-family: 'DM Mono', monospace;
    margin-top: 2px;
}

/* Client switcher */
.client-switcher {
    margin: 12px 12px 4px;
}

.client-switcher select {
    width: 100%;
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.1);
    color: #fff;
    font-size: 13px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3e%3cpath fill='rgba(255,255,255,.5)' d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.client-switcher select option {
    background: #1e293b;
    color: #fff;
}

.client-switcher select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Nav */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.sidebar-nav-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,.25);
    padding: 12px 20px 4px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 400;
    transition: all .15s;
    position: relative;
}

.sidebar-nav a:hover {
    color: var(--sidebar-text-hover);
    background: rgba(255,255,255,.05);
}

.sidebar-nav a.active {
    color: var(--sidebar-active-text);
    background: var(--sidebar-active-bg);
    font-weight: 500;
}

.sidebar-nav a.active::before {
    content: '';
    position: absolute;
    left: 0; top: 4px; bottom: 4px;
    width: 3px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

.sidebar-nav a i {
    font-size: 16px;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

/* Footer */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--sidebar-border);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-user .avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-user .user-info {
    flex: 1;
    overflow: hidden;
}

.sidebar-user .user-name {
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user .user-role {
    font-size: 11px;
    color: var(--sidebar-text);
    font-family: 'DM Mono', monospace;
}

.sidebar-user .logout-btn {
    color: rgba(255,255,255,.3);
    text-decoration: none;
    font-size: 16px;
    transition: color .15s;
}

.sidebar-user .logout-btn:hover {
    color: var(--danger);
}

/* ============================================================================
   4. MAIN CONTENT & TOP BAR
   ========================================================================== */
.main-content {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

.page-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.content-area {
    padding: 28px;
    flex: 1;
}

/* ============================================================================
   5. CARDS & STAT CARDS
   ========================================================================== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h5 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.stat-card .stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-bottom: 14px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 600;
    font-family: 'DM Mono', monospace;
    line-height: 1;
}

.stat-card .stat-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ============================================================================
   6. TABELLE
   ========================================================================== */
.table {
    font-size: 14px;
    margin: 0;
}

.table thead th {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    padding: 10px 16px;
    background: var(--surface-2);
}

.table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover td {
    background: #f8fafc;
}

/* ============================================================================
   7. BOTTONI
   ========================================================================== */
.btn {
    font-size: 13px;
    font-weight: 500;
    border-radius: 8px;
    padding: 7px 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all .15s;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 6px;
}

/* ============================================================================
   8. FORM
   ========================================================================== */
.form-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 5px;
}

.form-control,
.form-select {
    font-size: 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    padding: 8px 12px;
    color: var(--text);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.form-text {
    font-size: 12px;
}

/* Titolo sezione nei form */
.section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    margin-bottom: 0;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

/* ============================================================================
   9. BADGE & ALERT
   ========================================================================== */
.badge {
    font-size: 11px;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 6px;
    font-family: 'DM Mono', monospace;
}

.alert {
    font-size: 14px;
    border-radius: var(--radius);
    border: none;
    padding: 12px 16px;
}

/* ============================================================================
   10. COMPONENTI UI
   ========================================================================== */

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 40px;
    display: block;
    margin-bottom: 12px;
    opacity: .3;
}

/* Banner nessun cliente selezionato */
.no-client-banner {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: #92400e;
}

/* ============================================================================
   11. LOGIN PAGE
   ========================================================================== */
.login-page {
    background: #0f1521;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-box {
    background: #ffffff;
    border-radius: 16px;
    padding: 40px 36px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 25px 50px rgba(0,0,0,.35);
}

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

.login-logo .icon-wrap {
    width: 56px;
    height: 56px;
    background: #6366f1;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    color: #fff;
    margin-bottom: 14px;
}

.login-logo h1 {
    font-size: 22px;
    font-weight: 600;
    color: #0f172a;
    margin: 0;
}

.login-logo p {
    font-size: 14px;
    color: #64748b;
    margin: 4px 0 0;
}

.btn-login {
    width: 100%;
    background: #6366f1;
    border-color: #6366f1;
    color: #fff;
    font-weight: 500;
    padding: 10px;
    border-radius: 8px;
    font-size: 15px;
    margin-top: 8px;
    transition: background .15s;
}

.btn-login:hover {
    background: #4f46e5;
    border-color: #4f46e5;
    color: #fff;
}

.default-creds {
    margin-top: 20px;
    padding: 10px 14px;
    background: #f8fafc;
    border-radius: 8px;
    font-size: 12px;
    color: #64748b;
    font-family: 'DM Mono', monospace;
    text-align: center;
}

/* ============================================================================
   12. WIZARD PERCORSO CHIAMATA
   ========================================================================== */
.flow-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    max-width: 720px;
    margin: 0 auto;
}

.flow-node {
    width: 100%;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 18px 22px;
    position: relative;
    transition: border-color .2s;
}

.flow-node.active  { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
.flow-node.success { border-color: #10b981; }
.flow-node.warning { border-color: #f59e0b; }
.flow-node.danger  { border-color: #ef4444; }
.flow-node.muted   { border-color: #e2e8f0; opacity: .55; }

.flow-node-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.flow-node-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.flow-node-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.flow-node-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0;
}

/* Connettore verticale */
.flow-arrow {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 40px;
    position: relative;
    z-index: 1;
}

.flow-arrow .line {
    width: 2px;
    flex: 1;
    background: var(--border);
}

.flow-arrow .arrowhead {
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 8px solid var(--border);
}

.flow-arrow.green .line     { background: #10b981; }
.flow-arrow.green .arrowhead { border-top-color: #10b981; }
.flow-arrow.red .line       { background: #ef4444; }
.flow-arrow.red .arrowhead  { border-top-color: #ef4444; }

/* Split vero/falso */
.flow-split {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.flow-split-label {
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 6px;
}

/* Step badge */
.step-badge {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #6366f1;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Toggle section */
.tc-toggle-section {
    background: #f8fafc;
    border-radius: 8px;
    padding: 12px 16px;
    border: 1px solid var(--border);
}

/* Preview label */
.dest-preview {
    font-size: 12px;
    font-family: 'DM Mono', monospace;
    color: #6366f1;
    background: #eef2ff;
    border-radius: 4px;
    padding: 2px 8px;
    display: inline-block;
    margin-top: 4px;
}

/* ============================================================================
   13. TIME CONDITIONS
   ========================================================================== */
.nav-tabs .nav-link {
    font-size: 14px;
}

/* ============================================================================
   14. UTILITY
   ========================================================================== */
.text-accent { color: var(--accent); }
.bg-accent   { background: var(--accent); }

/* ============================================================================
   15. RESPONSIVE
   ========================================================================== */
@media (max-width: 768px) {
    .sidebar       { transform: translateX(-100%); }
    .main-content  { margin-left: 0; }
    .content-area  { padding: 16px; }
    .flow-split    { grid-template-columns: 1fr; }
}

/* ============================================================================
   16. CLASSI UTILITY AGGIUNTIVE
   ========================================================================== */

/* Titolo sottosezione nei form (h6 con separatore) */
.form-section-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    margin-bottom: 0;
    padding-bottom: 0;
}

/* Testo piccolo generico */
.text-xs  { font-size: 11px; }
.text-sm  { font-size: 12px; }
.text-md  { font-size: 13px; }

/* Font monospace inline */
.font-mono { font-family: 'DM Mono', monospace; }

/* Altezza minima per card preview */
.min-h-80  { min-height: 80px; }
.min-h-120 { min-height: 120px; }

/* Tabella compatta con font ridotto */
.table-compact { font-size: 13px; }

/* Nav tabs con bordo coordinato */
.nav-tabs-app {
    border-color: var(--border);
}
.nav-tabs-app .nav-link {
    font-size: 14px;
}

/* Badge orario nei time groups */
.badge-time {
    font-family: 'DM Mono', monospace;
    font-size: 11px;
}

/* Icone colorate nei flow node del wizard */
.flow-icon-purple { background: #eef2ff; color: #6366f1; }
.flow-icon-yellow { background: #fef3c7; color: #d97706; }
.flow-icon-green  { background: #d1fae5; color: #065f46; }
.flow-icon-red    { background: #fee2e2; color: #991b1b; }

/* Destination boxes nel wizard */
.dest-box-true {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 12px 16px;
}

.dest-box-false {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 12px 16px;
}

.dest-box-label-true {
    font-weight: 600;
    color: #166534;
}

.dest-box-label-false {
    font-weight: 600;
    color: #991b1b;
}

/* ============================================================================
   17. LARGHEZZE COLONNE TABELLA
   ========================================================================== */
.col-w-40  { width: 40px;  min-width: 40px; }
.col-w-50  { width: 50px;  min-width: 50px; }
.col-w-90  { width: 90px;  min-width: 90px; }
.col-w-100 { width: 100px; min-width: 100px; }
.col-w-120 { width: 120px; min-width: 120px; }
.col-w-140 { width: 140px; min-width: 140px; }
.col-w-160 { width: 160px; min-width: 160px; }
.col-w-200 { width: 200px; min-width: 200px; }

/* ============================================================================
   18. COLORI LABEL FORM (destinazioni wizard/timeconditions)
   ========================================================================== */
.label-true  { color: #166534; }
.label-false { color: #991b1b; }

/* ============================================================================
   19. WIZARD — STEP BADGE COLORATI
   ========================================================================== */
.step-badge-yellow { background: #d97706; }
.step-badge-green  { background: #10b981; width: 20px; height: 20px; font-size: 10px; }
.step-badge-red    { background: #ef4444; width: 20px; height: 20px; font-size: 10px; }

/* Nodo finale wizard (azioni save) */
.flow-node-footer {
    text-align: center;
    background: var(--surface-2);
}

/* Card body compatta (tabella inbound routes) */
.card-body-compact {
    padding: 8px 12px;
    border-top: 1px solid var(--border);
}
