/* ================================================================
   Intelligent Invoices Hub — Main Stylesheet
   Clean financial SaaS aesthetic: dark sidebar, crisp data tables
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --sidebar-w: 260px;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #334155;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #f8fafc;

    --bg-primary: #f8fafc;
    --bg-card: #ffffff;
    --bg-input: #f1f5f9;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-light: #eff6ff;

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;

    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.04);
    --radius: 8px;
    --radius-lg: 12px;
}

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

body {
    font-family: 'DM Sans', -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 14px;
}

/* ---- Sidebar ---- */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: transform .3s ease;
}
.sidebar-brand {
    padding: 24px 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-brand h1 {
    font-size: 16px;
    font-weight: 700;
    color: #f8fafc;
    letter-spacing: -.02em;
}
.sidebar-brand span {
    font-size: 11px;
    color: var(--sidebar-text);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .08em;
}
.sidebar-nav { flex: 1; padding: 12px 10px; }
.sidebar-section {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: #475569;
    padding: 16px 12px 6px;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 6px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: all .15s;
}
.sidebar-nav a:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}
.sidebar-nav a.active {
    background: var(--accent);
    color: #fff;
}
.sidebar-nav a .icon { width: 18px; text-align: center; font-size: 15px; }
.sidebar-user {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,.06);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-user .avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
}
.sidebar-user .info { flex: 1; }
.sidebar-user .info .name { color: #f8fafc; font-size: 13px; font-weight: 600; }
.sidebar-user .info .role { color: var(--sidebar-text); font-size: 11px; }

/* ---- Main content ---- */
.main-content {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
}
.page-header {
    padding: 24px 32px 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header h2 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -.02em;
}
.page-header .subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}
.page-body { padding: 24px 32px; }

/* ---- Cards ---- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }
.card-body.no-pad { padding: 0; }

/* ---- Stat cards (dashboard) ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}
.stat-card .label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.stat-card .value {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -.03em;
    line-height: 1.1;
}
.stat-card .value.success { color: var(--success); }
.stat-card .value.danger { color: var(--danger); }
.stat-card .value.accent { color: var(--accent); }
.stat-card .sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ---- Tables ---- */
.table-wrapper { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
}
table thead th {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    padding: 10px 16px;
    text-align: left;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 13.5px;
}
table tbody tr:hover { background: #f8fafc; }
table tbody tr:last-child td { border-bottom: none; }
td .mono {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12.5px;
}
td .amount {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 13px;
}

/* ---- Badges / Status ---- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .02em;
    white-space: nowrap;
}
.badge-blue    { background: #eff6ff; color: #2563eb; }
.badge-green   { background: #ecfdf5; color: #059669; }
.badge-yellow  { background: #fffbeb; color: #d97706; }
.badge-red     { background: #fef2f2; color: #dc2626; }
.badge-gray    { background: #f1f5f9; color: #475569; }
.badge-purple  { background: #f5f3ff; color: #7c3aed; }
.badge-cyan    { background: #ecfeff; color: #0891b2; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all .15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary   { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success   { background: var(--success); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-outline   { background: transparent; color: var(--text-primary); border-color: var(--border); }
.btn-outline:hover { background: #f1f5f9; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost { background: transparent; border: none; color: var(--accent); padding: 4px 8px; }
.btn-ghost:hover { background: var(--accent-light); }

/* ---- Forms ---- */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 5px;
}
.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13.5px;
    font-family: inherit;
    background: var(--bg-card);
    color: var(--text-primary);
    transition: border-color .15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}
select.form-control { appearance: auto; }
textarea.form-control { min-height: 80px; resize: vertical; }
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ---- Alerts ---- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ---- Timeline ---- */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
    content: '';
    position: absolute;
    left: 9px; top: 0; bottom: 0;
    width: 2px;
    background: var(--border);
}
.timeline-item {
    position: relative;
    padding-bottom: 24px;
}
.timeline-item::before {
    content: '';
    position: absolute;
    left: -23px; top: 4px;
    width: 12px; height: 12px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-card);
    box-shadow: 0 0 0 2px var(--accent);
}
.timeline-item.completed::before { background: var(--success); box-shadow: 0 0 0 2px var(--success); }
.timeline-item .tl-title { font-weight: 600; font-size: 14px; }
.timeline-item .tl-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.timeline-item .tl-body { margin-top: 8px; }

/* ---- Chat / AI ---- */
.chat-container {
    height: 500px;
    display: flex;
    flex-direction: column;
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}
.chat-message {
    margin-bottom: 16px;
    display: flex;
    gap: 10px;
}
.chat-message.user { flex-direction: row-reverse; }
.chat-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1.5;
}
.chat-message.assistant .chat-bubble {
    background: #f1f5f9;
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}
.chat-message.user .chat-bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-input-area {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}
.chat-input-area input { flex: 1; }

/* ---- Empty state ---- */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}
.empty-state .icon { font-size: 36px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ---- Pagination ---- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-secondary);
}
.pagination .pages { display: flex; gap: 4px; }
.pagination .pages a, .pagination .pages span {
    padding: 4px 10px;
    border-radius: 4px;
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
}
.pagination .pages a:hover { background: #f1f5f9; }
.pagination .pages span.current {
    background: var(--accent);
    color: #fff;
}

/* ---- Login page ---- */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}
.auth-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    padding: 40px;
}
.auth-card h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}
.auth-card .subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 28px;
}
.auth-card .btn-primary {
    width: 100%;
    padding: 11px;
    font-size: 14px;
    justify-content: center;
}
.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 13px;
    color: var(--text-secondary);
}
.auth-footer a { color: var(--accent); text-decoration: none; font-weight: 600; }

/* ---- Utilities ---- */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.font-mono { font-family: 'JetBrains Mono', monospace; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.hidden { display: none; }

/* ---- AI Insight Bar ---- */
.ai-bar {
    margin: 0 32px 12px;
    background: linear-gradient(135deg, #eff6ff 0%, #f0fdf4 100%);
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
    overflow: hidden;
}
.ai-bar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px; cursor: pointer;
    transition: background .15s;
}
.ai-bar-header:hover { background: rgba(59,130,246,.04); }
.ai-bar-left { display: flex; align-items: center; gap: 10px; }
.ai-bar-right { display: flex; align-items: center; gap: 10px; }
.ai-pulse {
    width: 8px; height: 8px; border-radius: 50%;
    background: #3b82f6;
    animation: ai-pulse 2s ease-in-out infinite;
}
@keyframes ai-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(59,130,246,.4); }
    50% { box-shadow: 0 0 0 6px rgba(59,130,246,0); }
}
.ai-bar-title { font-weight: 700; font-size: 13px; color: #1e40af; }
.ai-bar-subtitle { font-size: 12px; color: #64748b; }
.ai-bar-toggle { font-size: 11px; color: #64748b; transition: transform .2s; user-select: none; }
.ai-bar-chat-btn {
    background: #2563eb; color: white; border: none; border-radius: 6px;
    padding: 5px 12px; font-size: 12px; font-weight: 600; cursor: pointer;
    font-family: inherit; transition: background .15s;
}
.ai-bar-chat-btn:hover { background: #1d4ed8; }
.ai-bar-body {
    max-height: 0; overflow: hidden; transition: max-height .3s ease;
}
.ai-bar-body.expanded { max-height: 400px; }
.ai-synthesis {
    padding: 12px 16px 14px;
    font-size: 13.5px; line-height: 1.65; color: #334155;
    border-top: 1px solid #bfdbfe;
}
.ai-synthesis p { margin: 0; }
.ai-loading { display: flex; gap: 4px; padding: 8px 0; }
.ai-dot {
    width: 6px; height: 6px; border-radius: 50%; background: #3b82f6;
    animation: ai-bounce .6s infinite alternate;
}
.ai-dot:nth-child(2) { animation-delay: .2s; }
.ai-dot:nth-child(3) { animation-delay: .4s; }
@keyframes ai-bounce {
    to { transform: translateY(-6px); opacity: .4; }
}

/* ---- AI Chat Drawer ---- */
.ai-chat-drawer {
    position: fixed; right: -420px; top: 0; bottom: 0;
    width: 400px; background: #fff;
    box-shadow: -4px 0 24px rgba(0,0,0,.12);
    z-index: 200;
    display: flex; flex-direction: column;
    transition: right .3s cubic-bezier(.4,0,.2,1);
}
.ai-chat-drawer.open { right: 0; }
.ai-chat-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px;
    background: #0f172a; color: #f8fafc;
    font-size: 14px; font-weight: 600;
}
.ai-chat-close {
    background: none; border: none; color: #94a3b8; font-size: 18px;
    cursor: pointer; padding: 0 4px;
}
.ai-chat-close:hover { color: #fff; }
.ai-chat-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 10px;
}
.ai-chat-msg { display: flex; }
.ai-chat-msg.user { justify-content: flex-end; }
.ai-chat-bubble {
    max-width: 85%; padding: 10px 14px;
    border-radius: 12px; font-size: 13.5px; line-height: 1.55;
}
.ai-chat-msg.assistant .ai-chat-bubble {
    background: #f1f5f9; color: #334155;
    border-bottom-left-radius: 4px;
}
.ai-chat-msg.user .ai-chat-bubble {
    background: #2563eb; color: white;
    border-bottom-right-radius: 4px;
}
.ai-chat-input-row {
    display: flex; gap: 8px; padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: #f8fafc;
}
.ai-chat-input-row .form-control { flex: 1; font-size: 13.5px; }

/* ---- Chat container (AI assistant page) ---- */
.chat-container { display: flex; flex-direction: column; height: 420px; }
.chat-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 10px;
}
.chat-message { display: flex; }
.chat-message.user { justify-content: flex-end; }
.chat-bubble {
    max-width: 80%; padding: 10px 14px;
    border-radius: 12px; font-size: 13.5px; line-height: 1.55;
}
.chat-message.assistant .chat-bubble {
    background: #f1f5f9; color: #334155;
    border-bottom-left-radius: 4px;
}
.chat-message.user .chat-bubble {
    background: #2563eb; color: white;
    border-bottom-right-radius: 4px;
}
.chat-input-area {
    display: flex; gap: 8px; padding: 12px 16px;
    border-top: 1px solid var(--border);
}
.chat-input-area .form-control { flex: 1; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .page-header, .page-body { padding-left: 16px; padding-right: 16px; }
    .form-row { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .ai-bar { margin: 0 16px 12px; }
    .ai-chat-drawer { width: 100%; right: -100%; }
}
