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

:root {
    --bg: #0a0a0f;
    --card: #12121a;
    --border: #1e1e2e;
    --text: #e0e0e0;
    --text-muted: #888;
    --accent: #f0b429;
    --green: #22c55e;
    --orange: #f59e0b;
    --red: #ef4444;
    --blue: #3b82f6;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    min-height: 100vh;
}

/* Login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 48px;
    text-align: center;
    width: 380px;
}

.login-card h1 {
    color: var(--accent);
    font-size: 1.8rem;
    margin-bottom: 4px;
}

.login-card .subtitle {
    color: var(--text-muted);
    margin-bottom: 32px;
}

.login-card input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    margin-bottom: 16px;
}

.login-card button {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.error { color: var(--red); margin-top: 12px; font-size: 0.9rem; }
.hidden { display: none !important; }

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 32px;
    border-bottom: 1px solid var(--border);
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-left h1 { font-size: 1.4rem; color: var(--accent); }

.badge {
    background: var(--accent);
    color: #000;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
}

.header-right { display: flex; gap: 8px; }

.btn-icon {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 1.2rem;
    cursor: pointer;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

/* Stats */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    padding: 24px 32px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
}

.stat-value { font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: 0.85rem; margin-top: 4px; }
.stat-green .stat-value { color: var(--green); }
.stat-orange .stat-value { color: var(--orange); }
.stat-red .stat-value { color: var(--red); }

/* Filters */
.filters-bar {
    display: flex;
    gap: 12px;
    padding: 0 32px 16px;
}

.filters-bar input,
.filters-bar select {
    padding: 10px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
}

.filters-bar input { flex: 1; }
.filters-bar select { min-width: 180px; }

/* Table */
.table-container {
    padding: 0 32px 32px;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

thead th {
    background: var(--card);
    padding: 12px 10px;
    text-align: left;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
}

tbody td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr:hover { background: rgba(240, 180, 41, 0.04); }

.loading { text-align: center; padding: 40px; color: var(--text-muted); }

/* Status badges */
.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-attesa { background: rgba(245, 158, 11, 0.15); color: var(--orange); }
.status-consegnato { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.status-annullato { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.status-transito { background: rgba(59, 130, 246, 0.15); color: var(--blue); }

/* Action button */
.btn-edit {
    background: var(--accent);
    color: #000;
    border: none;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal h2 { color: var(--accent); margin-bottom: 16px; }

.modal-info {
    background: var(--bg);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    line-height: 1.6;
}

.modal label {
    display: block;
    margin-bottom: 14px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.modal input,
.modal select,
.modal textarea {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.btn-cancel {
    flex: 1;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
}

.btn-save {
    flex: 1;
    padding: 10px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.95rem;
}

/* Notifiche button */
.btn-notifiche {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: #3b82f6;
    padding: 6px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}
.btn-notifiche:hover { background: rgba(59, 130, 246, 0.2); border-color: #3b82f6; }
.notif-badge {
    background: #ef4444;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* Notifiche panel */
.notifiche-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 400px;
    height: 100vh;
    background: var(--card);
    border-left: 1px solid var(--border);
    z-index: 200;
    display: flex;
    flex-direction: column;
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}
.notifiche-panel.hidden { display: none !important; }
.notif-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}
.notif-panel-header h2 { color: #3b82f6; font-size: 1.1rem; }
.notif-panel-header .chat-close {
    background: none;
    border: none;
    color: #888;
    font-size: 1.5rem;
    cursor: pointer;
}
.notif-panel-header .chat-close:hover { color: #fff; }

.notif-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}
.notif-empty, .notif-loading {
    text-align: center;
    color: #666;
    padding: 40px 20px;
    font-size: 0.9rem;
}

.notif-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s;
}
.notif-item:hover { border-color: #3b82f6; background: rgba(59, 130, 246, 0.05); }
.notif-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.notif-consulente { color: #3b82f6; font-weight: 600; font-size: 0.85rem; }
.notif-time { color: #666; font-size: 0.75rem; }
.notif-cliente { color: var(--text); font-size: 0.85rem; font-weight: 500; margin-bottom: 6px; }
.notif-preview { color: #aaa; font-size: 0.82rem; line-height: 1.4; margin-bottom: 6px; }
.notif-count { color: #666; font-size: 0.72rem; }

/* Modal chat section */
.modal-chat-section { margin-top: 16px; }
.modal-chat-title {
    color: #3b82f6;
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 10px;
}
.modal-chat-messages {
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.chat-loading-small, .chat-empty-small {
    text-align: center;
    color: #666;
    padding: 16px;
    font-size: 0.82rem;
}

.mchat-msg {
    max-width: 90%;
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 0.82rem;
    line-height: 1.4;
}
.mchat-cs {
    align-self: flex-end;
    background: rgba(240, 180, 41, 0.1);
    border: 1px solid rgba(240, 180, 41, 0.2);
}
.mchat-consulente {
    align-self: flex-start;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
}
.mchat-name { font-size: 0.7rem; font-weight: 600; margin-bottom: 2px; }
.mchat-cs .mchat-name { color: #f0b429; }
.mchat-consulente .mchat-name { color: #3b82f6; }
.mchat-text { color: var(--text); word-break: break-word; }
.mchat-time { font-size: 0.65rem; color: #666; margin-top: 3px; text-align: right; }

.modal-chat-input {
    display: flex;
    gap: 8px;
}
.modal-chat-input textarea {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 8px;
    font-family: inherit;
    font-size: 0.85rem;
    resize: none;
}
.modal-chat-input textarea:focus { border-color: #3b82f6; outline: none; }
.btn-chat-send {
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    align-self: flex-end;
}
.btn-chat-send:hover { background: #2563eb; }

@media (max-width: 768px) {
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .filters-bar { flex-direction: column; }
    header { padding: 16px; }
    .table-container { padding: 0 16px 16px; }
    .notifiche-panel { width: 100%; }
}
