:root {
    --sidebar-bg: #0f172a;
    --sidebar-text: #cbd5e1;
    --sidebar-active: #1e293b;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
}

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

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

h1 { font-size: 1.5rem; margin-bottom: 1.25rem; }
h2 { font-size: 1.05rem; margin-bottom: 0.75rem; }
a { color: var(--accent); }
code { background: var(--bg); padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.9em; }
.muted { color: var(--muted); }

/* ---------- Auth ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.auth-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}
.auth-card h1 { font-size: 1.25rem; }
.auth-logo, .sidebar-logo {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.auth-logo { margin-bottom: 1.5rem; color: var(--text); }
.auth-logo span, .sidebar-logo span { color: var(--accent); }
.auth-links { margin-top: 1.25rem; display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.9rem; }

/* ---------- Forms ---------- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 0.3rem; }
.field input {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.errorlist { color: var(--danger); font-size: 0.85rem; list-style: none; margin-top: 0.3rem; }

.btn {
    display: inline-block;
    border: none;
    border-radius: 8px;
    padding: 0.6rem 1.1rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.btn-link { background: none; border: none; color: var(--sidebar-text); cursor: pointer; font-size: 0.85rem; padding: 0; text-decoration: underline; }

.alert { border-radius: 8px; padding: 0.7rem 1rem; margin-bottom: 1rem; font-size: 0.9rem; }
.alert-success { background: #ecfdf5; color: var(--success); }
.alert-info { background: #eff6ff; color: var(--accent); }
.alert-error, .alert-warning { background: #fef2f2; color: var(--danger); }

/* ---------- App shell ---------- */
.app-body { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1.25rem 0.9rem;
}
.sidebar-logo { color: #fff; padding: 0 0.6rem 1rem; }
.org-switcher { margin-bottom: 1rem; }
.org-current {
    background: var(--sidebar-active);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
}
.org-option {
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    width: 100%;
    text-align: left;
    border-radius: 8px;
}
.org-option:hover { background: var(--sidebar-active); }
.sidebar-nav { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; }
.sidebar-nav a {
    color: var(--sidebar-text);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.92rem;
}
.sidebar-nav a:hover { background: var(--sidebar-active); color: #fff; }
.sidebar-nav a.active { background: var(--accent); color: #fff; }
.nav-badge {
    background: var(--danger);
    color: #fff;
    border-radius: 999px;
    padding: 0.05rem 0.45rem;
    font-size: 0.72rem;
    font-weight: 700;
}
.nav-section {
    margin-top: 1rem;
    padding: 0.4rem 0.75rem 0.2rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
}
.sidebar-footer { padding: 0.75rem 0.75rem 0; border-top: 1px solid var(--sidebar-active); }
.sidebar-user { font-size: 0.85rem; color: #fff; margin-bottom: 0.35rem; word-break: break-all; }

.content { flex: 1; padding: 2rem; max-width: 1200px; }

/* ---------- Components ---------- */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}
.widget-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}
.widget { margin-bottom: 0; }
.empty-state { color: var(--muted); font-size: 0.9rem; }

.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }

.detail-list { display: grid; grid-template-columns: 180px 1fr; row-gap: 0.6rem; font-size: 0.92rem; }
.detail-list dt { color: var(--muted); }
.detail-list dd { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.badge {
    display: inline-block;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.1rem 0.6rem;
    font-size: 0.8rem;
    margin-right: 0.3rem;
}
.badge-success { background: #ecfdf5; color: var(--success); border-color: #bbf7d0; }
.badge-warning { background: #fffbeb; color: var(--warning); border-color: #fde68a; }

.inline-form { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.inline-form select,
.inline-form input {
    flex: 1;
    padding: 0.45rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-bottom: 1.25rem; }
@media (max-width: 900px) { .form-grid { grid-template-columns: 1fr; } }
.field-compact { margin-bottom: 0.5rem; }
.field-compact label { display: inline-block; margin-right: 0.4rem; }
.field select, .field-compact select, .field textarea, .field-compact textarea, .field-compact input[type="number"], .field-compact input[type="text"] {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    max-width: 100%;
}
.field select, .field textarea { width: 100%; }
.action-cell { display: flex; gap: 0.4rem; }

.stat { font-size: 1.8rem; font-weight: 700; }
.stat-err { color: var(--danger); }
.row-overdue td { background: #fef2f2; }
.pipeline-row { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.pipeline-stage {
    flex: 1;
    min-width: 90px;
    text-align: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.6rem 0.4rem;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    color: var(--text);
}
.pipeline-stage:hover { border-color: var(--accent); }
.pipeline-stage .muted { font-size: 0.75rem; }
.integration-row { font-size: 0.88rem; padding: 0.1rem 0; }
.pagination { display: flex; gap: 1rem; margin-top: 0.75rem; font-size: 0.9rem; align-items: center; }

.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 0.4rem; }
.status-ok { background: var(--success); }
.status-sync { background: var(--accent); }
.status-warn { background: var(--warning); }
.status-err { background: var(--danger); }
.status-idle { background: var(--muted); }

.chat-box { max-height: 60vh; overflow-y: auto; display: flex; flex-direction: column; gap: 0.75rem; }
.chat-message { max-width: 85%; padding: 0.6rem 0.9rem; border-radius: 12px; }
.chat-user { align-self: flex-end; background: var(--accent); color: #fff; }
.chat-user .chat-author { color: #dbeafe; }
.chat-assistant { align-self: flex-start; background: var(--bg); }
.chat-refusal { background: #fffbeb; }
.chat-author { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 0.2rem; }
.chat-content { white-space: pre-wrap; word-break: break-word; }

.qr-box { max-width: 220px; margin: 1rem 0; }
.qr-box svg { width: 100%; height: auto; }
.setup-steps { padding-left: 1.25rem; margin-bottom: 0.5rem; font-size: 0.92rem; }

@media (max-width: 720px) {
    .app-body { flex-direction: column; }
    .sidebar { width: 100%; }
    .content { padding: 1.25rem; }
    .detail-list { grid-template-columns: 1fr; row-gap: 0.2rem; }
    .detail-list dt { margin-top: 0.5rem; }
}
