/* DCSY Intelligence Platform — Global Styles */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --sidebar-width: 240px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--gray-900);
    background: var(--gray-50);
    line-height: 1.5;
}

/* ─── Layout ─── */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
}
.sidebar-header img { height: 28px; width: auto; object-fit: contain; }
.sidebar-logo { font-size: 1.5rem; font-weight: 800; letter-spacing: 2px; }
.sidebar-subtitle { font-size: 0.65rem; color: var(--gray-500); text-transform: uppercase; letter-spacing: 1.5px; }

.sidebar-nav { flex: 1; padding: 1rem 0; overflow-y: auto; }
.sidebar-footer { padding: 1rem 0; border-top: 1px solid rgba(255,255,255,0.1); }

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.5rem;
    color: var(--gray-300);
    text-decoration: none;
    font-size: 0.875rem;
    transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: white; }
.nav-item.active { background: var(--primary); color: white; }
.nav-item.disabled { opacity: 0.4; pointer-events: none; }
.nav-icon { font-size: 1.1rem; width: 1.25rem; text-align: center; }
.nav-section-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255,255,255,0.35);
    padding: 1rem 1.5rem 0.3rem;
    font-weight: 600;
}
.nav-sub-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.25);
    padding: 0.75rem 1.5rem 0.2rem;
    font-weight: 600;
    border-top: 1px solid rgba(255,255,255,0.06);
    margin-top: 0.25rem;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: white;
    border-bottom: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
    gap: 0.75rem;
    flex-wrap: wrap;
}
.page-title { font-size: 1.25rem; font-weight: 600; white-space: nowrap; }
.top-bar-actions { display: flex; flex-wrap: wrap; gap: 0.25rem; }

.content-body { padding: 1.5rem 2rem; flex: 1; }

/* ─── Cards ─── */
.card {
    background: white;
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

/* ─── Grid ─── */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ─── Stat cards ─── */
.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    text-align: center;
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.8rem; color: var(--gray-500); text-transform: uppercase; margin-top: 0.25rem; }
.stat-danger .stat-value { color: var(--danger); }

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: white; color: var(--gray-700); border-color: var(--gray-300); }
.btn-secondary:hover { background: var(--gray-100); }
.btn-danger { background: var(--danger); color: white; }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-google { width: 100%; justify-content: center; padding: 0.75rem; font-size: 1rem; }

/* ─── Forms ─── */
.field-row {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
}
.field-row label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-700);
}
.field-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
    width: 100%;
}
.field-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* ─── Tables ─── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--gray-500);
    padding: 0.75rem;
    border-bottom: 2px solid var(--gray-200);
}
.data-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.875rem;
}
.data-table tr:hover td { background: var(--gray-50); }

/* ─── Badges ─── */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}
/* ── Status badges ── */
.badge-active { background: #dcfce7; color: #166534; }
.badge-prospect { background: #dbeafe; color: #1e40af; }
.badge-onboarding { background: #fef3c7; color: #92400e; }
.badge-churned { background: #fee2e2; color: #991b1b; }
.badge-archived { background: #e5e7eb; color: #6b7280; }
.badge-overdue { background: #fee2e2; color: #991b1b; }
.badge-filed { background: #dcfce7; color: #166534; }
.badge-upcoming { background: #dbeafe; color: #1e40af; }
.badge-na { background: #f3f4f6; color: #9ca3af; text-decoration: line-through; }
.badge-in-progress, .badge-on_hold, .badge-paused { background: #fef3c7; color: #92400e; }
.badge-completed { background: #dcfce7; color: #166534; }
.badge-cancelled, .badge-rejected { background: #fee2e2; color: #991b1b; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-gray { background: #f3f4f6; color: #6b7280; }
.badge-draft { background: #fef3c7; color: #92400e; }
.badge-approved { background: #dbeafe; color: #1e40af; }

/* ── Service type badges (engagement & project) ── */
.badge-bookkeeping, .badge-monthly, .badge-annual { background: #dbeafe; color: #1e40af; }
.badge-payroll { background: #dcfce7; color: #166534; }
.badge-financial_planning { background: #faf5ff; color: #6b21a8; }
.badge-consulting, .badge-advisory { background: #e0e7ff; color: #3730a3; }
.badge-tax_advisory, .badge-tax_filing { background: #fef3c7; color: #92400e; }
.badge-training { background: #ecfdf5; color: #065f46; }
.badge-audit { background: #fee2e2; color: #991b1b; }
.badge-other, .badge-secretarial, .badge-einvoice,
.badge-recurring, .badge-one_off, .badge-fixed_term { background: #f3f4f6; color: #374151; }
.badge-posted { background: #dcfce7; color: #166534; }
.badge-sent { background: #dcfce7; color: #166534; }
.badge-failed { background: #fee2e2; color: #991b1b; }
.badge-archived { background: #f3f4f6; color: #6b7280; font-style: italic; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-on_hold { background: #fef3c7; color: #92400e; }
.badge-monthly { background: #dbeafe; color: #1e40af; }
.badge-annual { background: #fef3c7; color: #92400e; }
.badge-consulting { background: #e0e7ff; color: #3730a3; }

/* ─── Icon buttons (archive, delete, etc.) ─── */
.btn-icon { border: none; background: none; cursor: pointer; font-size: 1rem; padding: 2px 6px; border-radius: 4px; opacity: 0.6; transition: opacity 0.15s; }
.btn-icon:hover { opacity: 1; }

/* ─── Filter bar ─── */
.filter-bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* ─── Modal ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.modal-content {
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

/* ─── Login page ─── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--gray-900);
}
.login-card {
    background: white;
    border-radius: var(--radius);
    padding: 3rem;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-md);
}
.login-card h1 { font-size: 2rem; letter-spacing: 3px; margin-bottom: 0.25rem; }
.login-card .subtitle { color: var(--gray-500); margin-bottom: 2rem; }

/* ─── Toasts ─── */
.toast {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: white;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Utilities ─── */
.muted { color: var(--gray-500); font-size: 0.85rem; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }

/* ─── Responsive ─── */
@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .sidebar { width: 60px; }
    .sidebar-header, .sidebar-subtitle, .nav-item span:not(.nav-icon) { display: none; }
    .main-content { margin-left: 60px; }
}

/* ─── Dashboard: grid-5 ─── */
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1rem; }

/* ─── Health status dots ─── */
.health-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.health-dot.green { background: var(--success); }
.health-dot.gray { background: #d1d5db; }
.health-dot.red { background: var(--danger); }

/* ─── Activity feed ─── */
.activity-feed { max-height: 400px; overflow-y: auto; }
.activity-item { padding: 0.5rem 0; border-bottom: 1px solid #f3f4f6; display: flex; gap: 0.5rem; align-items: flex-start; font-size: 0.85rem; }
.activity-item:last-child { border-bottom: none; }
.activity-icon { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; flex-shrink: 0; }
.activity-icon.scan { background: #dbeafe; color: #2563eb; }
.activity-icon.push { background: #dcfce7; color: #16a34a; }
.activity-icon.alert { background: #fef3c7; color: #f59e0b; }
.activity-time { color: #9ca3af; font-size: 0.75rem; white-space: nowrap; }

/* ─── Dashboard responsive ─── */
@media (max-width: 768px) {
    .grid-5 { grid-template-columns: repeat(2, 1fr); }
}

/* ═══════════════════════════════════════════════════════════════
   AI Chat Widget
   ═══════════════════════════════════════════════════════════════ */
.ai-chat-trigger {
    position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 900;
    width: 48px; height: 48px; border-radius: 50%;
    background: var(--primary); color: white; border: none;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    transition: transform 0.15s, box-shadow 0.15s;
}
.ai-chat-trigger:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(37, 99, 235, 0.5); }

.ai-chat-panel {
    position: fixed; top: 0; right: -420px; width: 400px; height: 100vh; z-index: 950;
    background: white; border-left: 1px solid var(--gray-200);
    display: flex; flex-direction: column;
    box-shadow: -4px 0 24px rgba(0,0,0,0.08);
    transition: right 0.25s ease;
}
.ai-chat-panel.open { right: 0; }

.ai-chat-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.75rem 1rem; border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
}
.ai-chat-header strong { font-size: 0.9rem; }
.ai-chat-model {
    font-size: 0.65rem; background: var(--gray-200); color: var(--gray-500);
    padding: 1px 6px; border-radius: 4px; margin-left: 0.5rem;
}
.ai-chat-close {
    background: none; border: none; font-size: 1.2rem; cursor: pointer;
    color: var(--gray-400); padding: 4px 8px; border-radius: 4px;
}
.ai-chat-close:hover { background: var(--gray-100); color: var(--gray-600); }

.ai-chat-messages {
    flex: 1; overflow-y: auto; padding: 1rem;
    display: flex; flex-direction: column; gap: 0.75rem;
}

.ai-msg { display: flex; }
.ai-msg-user { justify-content: flex-end; }
.ai-msg-assistant { justify-content: flex-start; }

.ai-msg-content {
    max-width: 85%; padding: 0.6rem 0.9rem; border-radius: 12px;
    font-size: 0.85rem; line-height: 1.5; word-wrap: break-word;
}
.ai-msg-user .ai-msg-content {
    background: var(--primary); color: white; border-bottom-right-radius: 4px;
}
.ai-msg-assistant .ai-msg-content {
    background: var(--gray-100); color: var(--gray-800); border-bottom-left-radius: 4px;
}
.ai-msg-content strong { font-weight: 600; }
.ai-msg-content ul, .ai-msg-content ol { margin: 0.25rem 0; padding-left: 1.25rem; }
.ai-msg-content li { margin-bottom: 0.15rem; }
.ai-msg-content code { background: rgba(0,0,0,0.06); padding: 1px 4px; border-radius: 3px; font-size: 0.8rem; }
.ai-msg-content pre.ai-code {
    background: #1e293b; color: #e2e8f0; padding: 0.5rem; border-radius: 6px;
    font-size: 0.75rem; overflow-x: auto; margin: 0.5rem 0;
}

.ai-chat-typing {
    display: flex; gap: 4px; padding: 0.5rem 1.25rem; align-items: center;
}
.ai-typing-dot {
    width: 6px; height: 6px; background: var(--gray-400); border-radius: 50%;
    animation: ai-typing 1.2s infinite;
}
.ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-typing { 0%,80%,100% { opacity: 0.3; } 40% { opacity: 1; } }

.ai-chat-input {
    display: flex; gap: 0.5rem; padding: 0.75rem; border-top: 1px solid var(--gray-200);
    background: white;
}
.ai-chat-input textarea {
    flex: 1; border: 1px solid var(--gray-300); border-radius: 8px;
    padding: 0.5rem 0.75rem; font-size: 0.85rem; resize: none;
    font-family: inherit; outline: none; max-height: 120px;
}
.ai-chat-input textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,0.1); }
.ai-chat-send {
    background: var(--primary); color: white; border: none; border-radius: 8px;
    width: 36px; height: 36px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s;
}
.ai-chat-send:hover { background: var(--primary-hover); }
.ai-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Tabs ─── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--gray-200); }
.tab-btn {
    padding: 0.6rem 1.25rem; background: none; border: none;
    border-bottom: 2px solid transparent; margin-bottom: -2px;
    cursor: pointer; font-size: 0.875rem; font-weight: 500;
    color: var(--gray-500); transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--gray-700); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ─── Checkbox labels ─── */
.checkbox-label {
    display: flex; align-items: center; gap: 0.4rem;
    font-size: 0.85rem; cursor: pointer; user-select: none;
}
.checkbox-label input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; }
