/* X-TTS — Stile ispirato a comestai.io / X-OMS */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary-green:  #8BC53F;
    --primary-blue:   #0D4F7C;
    --text-dark:      #2d3748;
    --text-gray:      #718096;
    --bg-light:       #f5f5f5;
    --bg-white:       #ffffff;
    --border-color:   #e2e8f0;
    --error-color:    #e53e3e;
    --success-color:  #38a169;
    --warning-color:  #dd6b20;
    --hover-green:    #f0f9e8;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background-color: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== HEADER ===== */
.header {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-green) 100%);
    color: white;
    padding: 1.5rem 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.header-content {
    max-width: 1920px;
    margin: 0 auto;
    padding: 0 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}
.header-logo {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
}
.header-logo img { height: 44px; width: auto; }
.header h1 { font-size: 1.6rem; font-weight: 600; }
.header-user { display: flex; align-items: center; gap: 1rem; }
.user-info { text-align: right; font-size: 0.9rem; }

/* ===== BADGE ===== */
.badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-admin-cs    { background: #9b59b6; color: white; }
.badge-admin       { background: var(--warning-color); color: white; }
.badge-editor      { background: var(--primary-green); color: white; }

/* ===== STATUS BADGES ===== */
.status-badge { display: inline-block; padding: 0.3rem 0.75rem; border-radius: 20px; font-size: 0.82rem; font-weight: 600; }
.status-nuovo          { background: #dbeafe; color: #1e3a8a; }
.status-in-lavorazione { background: #fef3c7; color: #78350f; }
.status-chiuso         { background: #d1fae5; color: #065f46; }

/* ===== CONTAINER / CARD ===== */
.container { max-width: 1920px; margin: 2rem auto; padding: 0 12px; }
.card {
    background: var(--bg-white);
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    padding: 2rem;
    margin-bottom: 2rem;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}
.card-title { font-size: 1.4rem; font-weight: 600; color: var(--primary-blue); }

/* ===== FORM ===== */
.form-group { margin-bottom: 1.5rem; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1.5rem; }
.form-label { display: block; margin-bottom: 0.5rem; font-weight: 500; color: var(--text-dark); font-size: 0.95rem; }
.form-label.required::after { content: " *"; color: var(--error-color); }
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
    font-family: inherit;
    background: white;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary-green);
    box-shadow: 0 0 0 3px rgba(139,197,63,0.1);
}
.form-input.error, .form-select.error, .form-textarea.error { border-color: var(--error-color); }
.form-textarea { resize: vertical; min-height: 100px; }
.form-help { font-size: 0.85rem; color: var(--text-gray); margin-top: 0.25rem; }
.form-error { color: var(--error-color); font-size: 0.85rem; margin-top: 0.25rem; display: none; }
.form-error.show { display: block; }

/* ===== BUTTONS ===== */
.btn {
    display: inline-block;
    padding: 0.7rem 1.4rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    text-align: center;
    line-height: 1.4;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.btn:active { transform: translateY(0); }
.btn-primary { background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-green) 100%); color: white; }
.btn-secondary { background-color: var(--text-gray); color: white; }
.btn-success  { background-color: var(--success-color); color: white; }
.btn-warning  { background-color: var(--warning-color); color: white; }
.btn-danger   { background-color: var(--error-color); color: white; }
.btn-info     { background-color: #3b82f6; color: white; }
.btn-outline  { background: transparent; border: 2px solid var(--primary-blue); color: var(--primary-blue); }
.btn-outline:hover { background: var(--primary-blue); color: white; }
.btn-sm       { padding: 0.4rem 0.85rem; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-group    { display: flex; gap: 1rem; flex-wrap: wrap; }

/* ===== TABLE ===== */
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.table th, .table td { padding: 0.9rem 1rem; text-align: left; border-bottom: 1px solid var(--border-color); }
.table th { background: var(--bg-light); font-weight: 600; color: var(--primary-blue); text-transform: uppercase; font-size: 0.82rem; letter-spacing: 0.5px; }
.table tbody tr:hover { background: var(--hover-green); }
.table-actions { display: flex; gap: 0.4rem; flex-wrap: nowrap; white-space: nowrap; align-items: center; }
.table-actions .btn { padding: 0.35rem 0.7rem; font-size: 0.82rem; }

/* ===== ALERT ===== */
.alert { padding: 1rem 1.5rem; border-radius: 8px; margin-bottom: 1.5rem; border-left: 4px solid; }
.alert-success { background: #d1fae5; border-color: var(--success-color); color: #065f46; }
.alert-error   { background: #fee2e2; border-color: var(--error-color); color: #7f1d1d; }
.alert-info    { background: #dbeafe; border-color: #3b82f6; color: #1e3a8a; }
.alert-warning { background: #fef3c7; border-color: var(--warning-color); color: #78350f; }

/* ===== MODAL ===== */
.modal { display: none; position: fixed; z-index: 1000; inset: 0; background: rgba(0,0,0,0.5); animation: fadeIn 0.3s ease; }
.modal.show { display: flex; align-items: center; justify-content: center; }
.modal-content { background: var(--bg-white); padding: 2rem; border-radius: 10px; max-width: 520px; width: 90%; box-shadow: 0 10px 40px rgba(0,0,0,0.2); animation: slideUp 0.3s ease; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.modal-title { font-size: 1.3rem; font-weight: 600; color: var(--primary-blue); }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-gray); line-height: 1; }
.modal-close:hover { color: var(--text-dark); }
.modal-body  { margin-bottom: 1.5rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 1rem; }

/* ===== LOGIN ===== */
.login-container { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { max-width: 420px; width: 100%; }
.login-header { text-align: center; margin-bottom: 2rem; }
.login-header p { color: var(--text-gray); margin-top: 0.5rem; }

/* ===== STATISTICHE ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 0.5rem; margin-bottom: 1rem; }
.stat-card { background: white; border-radius: 6px; padding: 0.4rem 0.6rem; text-align: center; box-shadow: 0 1px 4px rgba(0,0,0,0.07); border-top: 3px solid var(--border-color); }
.stat-value { font-size: 1.1rem; font-weight: 700; margin-bottom: 0.1rem; }
.stat-label { font-size: 0.65rem; color: var(--text-gray); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card.blue   .stat-value { color: var(--primary-blue); }
.stat-card.green  .stat-value { color: var(--success-color); }
.stat-card.orange .stat-value { color: var(--warning-color); }
.stat-card.gray   .stat-value { color: var(--text-gray); }
.stat-card.blue   { border-top-color: var(--primary-blue); }
.stat-card.green  { border-top-color: var(--success-color); }
.stat-card.orange { border-top-color: var(--warning-color); }

/* ===== NOTE TIMELINE ===== */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 0; bottom: 0; width: 2px; background: var(--border-color); }
.timeline-item { position: relative; margin-bottom: 1.5rem; }
.timeline-item::before { content: ''; position: absolute; left: -20px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary-blue); border: 2px solid white; box-shadow: 0 0 0 2px var(--primary-blue); }
.timeline-item.stato::before   { background: var(--warning-color); box-shadow: 0 0 0 2px var(--warning-color); }
.timeline-item.sistema::before { background: var(--text-gray);     box-shadow: 0 0 0 2px var(--text-gray); }

/* Colori dot per categoria nota */
.timeline-item.cat-mail_in::before,
.timeline-item.cat-mail_out::before   { background: #3b82f6; box-shadow: 0 0 0 2px #3b82f6; }
.timeline-item.cat-tel_in::before,
.timeline-item.cat-tel_ok_out::before { background: #059669; box-shadow: 0 0 0 2px #059669; }
.timeline-item.cat-tel_ko_out::before { background: #dc2626; box-shadow: 0 0 0 2px #dc2626; }
.timeline-item.cat-wa_in::before,
.timeline-item.cat-wa_out::before     { background: #25d366; box-shadow: 0 0 0 2px #25d366; }
.timeline-item.cat-info::before       { background: #6b7280; box-shadow: 0 0 0 2px #6b7280; }

.timeline-card { background: white; border-radius: 8px; padding: 1rem 1.2rem; box-shadow: 0 1px 4px rgba(0,0,0,0.08); border-left: 3px solid var(--primary-blue); }
.timeline-card.stato   { border-left-color: var(--warning-color); }
.timeline-card.sistema { border-left-color: var(--text-gray); }

/* Colori bordo sinistro per categoria nota */
.timeline-card.cat-mail_in,
.timeline-card.cat-mail_out   { border-left-color: #3b82f6; }
.timeline-card.cat-tel_in,
.timeline-card.cat-tel_ok_out { border-left-color: #059669; }
.timeline-card.cat-tel_ko_out { border-left-color: #dc2626; }
.timeline-card.cat-wa_in,
.timeline-card.cat-wa_out     { border-left-color: #25d366; }
.timeline-card.cat-info       { border-left-color: #6b7280; }

.timeline-meta  { font-size: 0.82rem; color: var(--text-gray); margin-bottom: 0.4rem; }
.timeline-testo { color: var(--text-dark); }

/* Allegato nella nota */
.timeline-allegato {
    margin-top: 0.6rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
}
.timeline-allegato a {
    color: var(--primary-blue);
    text-decoration: none;
    font-weight: 500;
}
.timeline-allegato a:hover { text-decoration: underline; }

/* ===== BADGE CATEGORIA NOTA ===== */
.nota-cat-badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-left: 0.35rem;
    vertical-align: middle;
}
.nota-cat-mail   { background: #dbeafe; color: #1d4ed8; }
.nota-cat-tel-ok { background: #d1fae5; color: #065f46; }
.nota-cat-tel-ko { background: #fee2e2; color: #991b1b; }
.nota-cat-wa     { background: #dcfce7; color: #166534; }
.nota-cat-info   { background: #f3f4f6; color: #374151; }

/* ===== PREVIEW / DETTAGLIO ===== */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.detail-item { background: var(--bg-light); border-radius: 8px; padding: 0.8rem 1rem; }
.detail-label { font-size: 0.8rem; font-weight: 600; color: var(--text-gray); text-transform: uppercase; margin-bottom: 0.25rem; }
.detail-value { color: var(--text-dark); font-size: 0.95rem; }
.detail-value.big { font-size: 1.2rem; font-weight: 700; color: var(--primary-blue); }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-gray); }
.empty-state-icon { font-size: 3.5rem; margin-bottom: 1rem; opacity: 0.5; }
.empty-state-title { font-size: 1.3rem; margin-bottom: 0.5rem; color: var(--text-dark); }

/* ===== NAV BREADCRUMB ===== */
.nav-workflow { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; padding: 0.6rem 1rem; background: white; border-radius: 8px; margin-bottom: 1.5rem; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.nav-workflow a { font-size: 0.85rem; color: var(--text-gray); text-decoration: none; padding: 0.2rem 0.6rem; border-radius: 4px; }
.nav-workflow a:hover { background: var(--hover-green); color: var(--primary-blue); }
.nav-workflow a.active { background: linear-gradient(135deg, var(--primary-blue), var(--primary-green)); color: white; }
.nav-workflow .sep { color: var(--border-color); }

/* ===== FILTRI ===== */
.filter-bar { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1.5rem; }
.filter-bar .form-group { margin-bottom: 0; flex: 1; min-width: 160px; }
.filter-bar .form-label { font-size: 0.82rem; }

/* ===== FORM PUBBLICO ===== */
.public-header {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-green) 100%);
    color: white;
    padding: 3rem 1.5rem;
    text-align: center;
}
.public-header img  { height: 54px; margin-bottom: 1rem; }
.public-header h1   { font-size: 1.8rem; margin-bottom: 0.5rem; }
.public-header p    { opacity: 0.9; font-size: 1.05rem; }
.public-container   { max-width: 720px; margin: 2rem auto; padding: 0 20px; }

/* ===== ANIMATIONS ===== */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes shake   { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.shake { animation: shake 0.4s ease; }

/* ===== UTILITY ===== */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.hidden      { display: none !important; }
.loading     { pointer-events: none; opacity: 0.6; }
.mt-1 { margin-top: 0.5rem; }  .mt-2 { margin-top: 1rem; }   .mt-3 { margin-top: 1.5rem; } .mt-4 { margin-top: 2rem; }
.mb-1 { margin-bottom: 0.5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; } .mb-4 { margin-bottom: 2rem; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .container { padding: 0 12px; }
    .card { padding: 1.2rem; }
    .card-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
    .form-row { grid-template-columns: 1fr; }
    .header h1 { font-size: 1.1rem; }
    .header-content { flex-direction: column; gap: 0.75rem; text-align: center; }
    .header-logo { position: static; transform: none; order: -1; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .btn-group { flex-direction: column; }
    .table { font-size: 0.85rem; }
    .table th, .table td { padding: 0.6rem 0.5rem; }
    .filter-bar { flex-direction: column; }
    .filter-bar .form-group { width: 100%; }
}
