/* ─── Variables ─────────────────────────────────────────────────────────── */
:root {
    --sidebar-bg: #0f1923;
    --sidebar-width: 230px;
    --sidebar-text: #a8b5c4;
    --sidebar-text-active: #ffffff;
    --sidebar-link-hover: rgba(255,255,255,0.06);
    --sidebar-link-active: rgba(255,255,255,0.12);
    --sidebar-brand-color: #60a5fa;
    --sidebar-section-label: #4a5568;
    --content-bg: #f5f7fa;
    --card-border: #e2e8f0;
    --status-pending: #f59e0b;
    --status-running: #3b82f6;
    --status-completed: #10b981;
    --status-failed: #ef4444;
    --status-cancelled: #6b7280;
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */
html, body {
    height: 100%;
    margin: 0;
}

#app-wrapper {
    height: 100vh;
    overflow: hidden;
}

#main-wrapper {
    overflow-y: auto;
    background: var(--content-bg);
}

.min-width-0 {
    min-width: 0;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    padding: 1rem 0.75rem;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-brand {
    color: var(--sidebar-brand-color) !important;
    font-size: 1.125rem;
    font-weight: 700;
    padding: 0.25rem 0.5rem 0.75rem;
    letter-spacing: -0.01em;
}

.sidebar-brand i {
    font-size: 1.25rem;
}

.sidebar-section-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-section-label);
    padding: 0.5rem 0.75rem 0.25rem;
}

.sidebar-link {
    color: var(--sidebar-text) !important;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.45rem 0.75rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover {
    background: var(--sidebar-link-hover);
    color: var(--sidebar-text-active) !important;
}

.sidebar-link.active {
    background: var(--sidebar-link-active);
    color: var(--sidebar-text-active) !important;
}

.sidebar-link i {
    font-size: 0.9375rem;
    width: 1rem;
    text-align: center;
    flex-shrink: 0;
}

/* ─── Sidebar user ────────────────────────────────────────────────────────── */
.sidebar-user {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 0.75rem 0.25rem 0.25rem;
    margin-top: 0.5rem;
}

.sidebar-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #2563eb;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-user-name {
    color: #e2e8f0;
    font-size: 0.8125rem;
    font-weight: 500;
}

.sidebar-user-org {
    color: var(--sidebar-section-label);
    font-size: 0.75rem;
}

.sidebar-logout {
    color: var(--sidebar-section-label) !important;
    font-size: 1rem;
    opacity: 0.7;
}

.sidebar-logout:hover {
    color: #ef4444 !important;
    opacity: 1;
}

/* ─── Auth pages ─────────────────────────────────────────────────────────── */
.auth-body {
    background: var(--content-bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-container {
    width: 100%;
    max-width: 420px;
    padding: 1rem;
}

.auth-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e40af;
    margin-bottom: 2rem;
}

.auth-brand i {
    font-size: 1.75rem;
    color: #3b82f6;
}

.auth-card {
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.04);
}

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.stat-card {
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
}

.stat-card .stat-label {
    font-size: 0.8125rem;
    color: #6b7280;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #111827;
    line-height: 1.2;
}

.stat-card .stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
}

.stat-card .stat-delta {
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.3;
    margin-top: 0.1rem;
}

a.stat-card-link {
    display: block;
    color: inherit;
    text-decoration: none;
    transition: box-shadow 0.15s, transform 0.15s;
}

a.stat-card-link:hover .stat-card {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    transform: translateY(-1px);
}

.stat-card .stat-delta.positive { color: #10b981; }
.stat-card .stat-delta.negative { color: #ef4444; }
.stat-card .stat-delta.neutral  { color: #9ca3af; }

[data-bs-theme="dark"] .stat-card .stat-delta.neutral { color: #64748b; }

.chart-card {
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
}

.chart-card .chart-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: #111827;
    margin-bottom: 1rem;
}

/* ─── Page header ─────────────────────────────────────────────────────────── */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.375rem;
    font-weight: 700;
    color: #111827;
    margin: 0;
}

.page-header .text-muted {
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* ─── Status badges ──────────────────────────────────────────────────────── */
.badge-pending   { background: #fef3c7; color: #92400e; }
.badge-running   { background: #dbeafe; color: #1e40af; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-failed    { background: #fee2e2; color: #991b1b; }
.badge-cancelled { background: #f3f4f6; color: #374151; }

.run-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

/* ─── Tables ─────────────────────────────────────────────────────────────── */
.data-table-wrapper {
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 10px;
    overflow: hidden;
}

.data-table-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.data-table-header h2 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: #111827;
    margin: 0;
}

.table-responsive {
    overflow-x: auto;
}

.table {
    margin: 0;
    font-size: 0.875rem;
}

.table thead th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6b7280;
    background: #f9fafb;
    border-bottom: 1px solid var(--card-border);
    white-space: nowrap;
    padding: 0.625rem 1rem;
}

.table td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    color: #374151;
    border-bottom: 1px solid #f3f4f6;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover td {
    background: #f9fafb;
}

.table-link {
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
}

.table-link:hover {
    text-decoration: underline;
}

/* ─── Filter bar ─────────────────────────────────────────────────────────── */
.filter-bar {
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

/* ─── Pagination ─────────────────────────────────────────────────────────── */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--card-border);
    font-size: 0.8125rem;
    color: #6b7280;
}

/* ─── Resource detail ────────────────────────────────────────────────────── */
.detail-card {
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 1.5rem;
}

.detail-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
    margin-bottom: 0.25rem;
}

.detail-value {
    font-size: 0.9375rem;
    color: #111827;
    word-break: break-all;
}

.tag-badge {
    display: inline-block;
    background: #eff6ff;
    color: #1e40af;
    border-radius: 4px;
    padding: 0.15rem 0.5rem;
    font-size: 0.75rem;
    font-family: monospace;
    margin: 0.125rem;
}

/* ─── Empty states ───────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #9ca3af;
}

.empty-state i {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    display: block;
}

.empty-state p {
    font-size: 0.9375rem;
    margin: 0;
}

/* ─── Loading spinner ────────────────────────────────────────────────────── */
.loading-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #9ca3af;
}

/* ─── Misc ───────────────────────────────────────────────────────────────── */
.cost-value {
    font-weight: 600;
    color: #059669;
    font-variant-numeric: tabular-nums;
}

.cost-na {
    color: #d1d5db;
    font-size: 0.8125rem;
}

.btn-sm-icon {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
}

.modal-header {
    border-bottom: 1px solid var(--card-border);
}

.modal-footer {
    border-top: 1px solid var(--card-border);
}

/* Toasts */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast-item {
    background: #1f2937;
    color: #fff;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 240px;
    max-width: 360px;
    animation: toastIn 0.2s ease;
}

.toast-item.toast-error {
    background: #991b1b;
}

.toast-item.toast-success {
    background: #065f46;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── Dark mode toggle ───────────────────────────────────────────────────── */
.sidebar-theme-toggle {
    color: var(--sidebar-section-label) !important;
    font-size: 0.875rem;
    opacity: 0.7;
    line-height: 1;
}

.sidebar-theme-toggle:hover {
    color: var(--sidebar-text-active) !important;
    opacity: 1;
}

/* ─── Dark mode overrides ────────────────────────────────────────────────── */
[data-bs-theme="dark"] {
    --content-bg: #0f172a;
    --card-border: #334155;
}

[data-bs-theme="dark"] #main-wrapper {
    background: var(--content-bg);
}

[data-bs-theme="dark"] .stat-card,
[data-bs-theme="dark"] .chart-card,
[data-bs-theme="dark"] .data-table-wrapper,
[data-bs-theme="dark"] .filter-bar,
[data-bs-theme="dark"] .detail-card {
    background: #1e293b;
    border-color: var(--card-border);
}

[data-bs-theme="dark"] .stat-card .stat-label { color: #94a3b8; }
[data-bs-theme="dark"] .stat-card .stat-value { color: #f1f5f9; }
[data-bs-theme="dark"] a.stat-card-link:hover .stat-card { box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
[data-bs-theme="dark"] .page-header h1 { color: #f1f5f9; }
[data-bs-theme="dark"] .chart-card .chart-title { color: #f1f5f9; }
[data-bs-theme="dark"] .data-table-header { border-color: var(--card-border); }
[data-bs-theme="dark"] .data-table-header h2 { color: #f1f5f9; }

[data-bs-theme="dark"] .table thead th {
    background: #0f172a;
    color: #94a3b8;
    border-color: var(--card-border);
}

[data-bs-theme="dark"] .table td {
    color: #cbd5e1;
    border-color: #1e293b;
}

[data-bs-theme="dark"] .table tbody tr:hover td { background: #273447; }
[data-bs-theme="dark"] .sortable-header:hover { background: #273447 !important; }

[data-bs-theme="dark"] .pagination-bar {
    border-color: var(--card-border);
    color: #94a3b8;
}

[data-bs-theme="dark"] .detail-label { color: #64748b; }
[data-bs-theme="dark"] .detail-value { color: #f1f5f9; }

[data-bs-theme="dark"] .tag-badge {
    background: #1e3a5f;
    color: #93c5fd;
}

[data-bs-theme="dark"] .table-link { color: #60a5fa; }

/* ─── Org settings sub-nav ──────────────────────────────────────────────── */
.org-subnav {
    width: 180px;
    min-width: 180px;
}

.org-subnav-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #9ca3af;
    padding: 0 0.75rem 0.5rem;
}

.org-subnav-link {
    color: #374151;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
}

.org-subnav-link:hover {
    background: rgba(0,0,0,0.05);
    color: #111827;
}

.org-subnav-link.active {
    background: #e0e7ff;
    color: #3730a3;
}

.org-subnav-link i {
    font-size: 0.875rem;
    width: 1rem;
    text-align: center;
    flex-shrink: 0;
}

[data-bs-theme="dark"] .org-subnav-label { color: #4a5568; }
[data-bs-theme="dark"] .org-subnav-link { color: #94a3b8; }
[data-bs-theme="dark"] .org-subnav-link:hover { background: rgba(255,255,255,0.06); color: #f1f5f9; }
[data-bs-theme="dark"] .org-subnav-link.active { background: rgba(99,102,241,0.2); color: #a5b4fc; }

/* ── Report designer ────────────────────────────────────────────────────────── */

.step-pill {
    padding: 0.3rem 1rem;
    border-radius: 2rem;
    font-size: 0.8125rem;
    font-weight: 500;
    background: var(--bs-tertiary-bg, #f1f3f5);
    color: var(--bs-secondary-color, #6c757d);
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.step-pill.active {
    background: #4f9cf9;
    color: #fff;
}

.step-pill.done {
    background: #d1fae5;
    color: #065f46;
}

[data-bs-theme="dark"] .step-pill.done {
    background: #064e3b;
    color: #6ee7b7;
}

.step-connector {
    flex: 1;
    height: 2px;
    background: var(--bs-border-color, #dee2e6);
    max-width: 3rem;
}

.filter-checklist {
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 0.375rem;
    max-height: 180px;
    overflow-y: auto;
    padding: 0.25rem 0;
}

.filter-checklist-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background 0.1s;
}

.filter-checklist-item:hover {
    background: var(--bs-tertiary-bg, #f8f9fa);
}

.filter-checklist-item input[type="checkbox"] {
    flex-shrink: 0;
}

/* ── Recipient picker ───────────────────────────────────────────────────────── */

.recipient-picker-wrap {
    position: relative;
}

.recipient-picker-field {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    height: auto;
    min-height: calc(1.5em + 0.75rem + 2px);
    padding: 0.3rem 0.5rem;
    cursor: text;
}

.recipient-picker-field.focused {
    color: var(--bs-body-color);
    background-color: var(--bs-body-bg);
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.recipient-pill {
    display: inline-flex;
    align-items: center;
    gap: 0;
    padding: 0.1rem 0.35rem;
    background-color: var(--bs-primary);
    color: #fff;
    border-radius: 0.25rem;
    font-size: 0.8125rem;
    white-space: nowrap;
    line-height: 1.5;
    user-select: none;
}

.recipient-pill .btn-close {
    margin-inline-start: 0.4rem;
    width: 0.5em;
    height: 0.5em;
}

.recipient-picker-input {
    padding: 0;
    border: 0;
    outline: 0;
    flex-grow: 1;
    min-width: 8rem;
    font-size: 0.875rem;
    background: transparent;
    color: inherit;
}

.recipient-picker-input:focus {
    border: 0;
    outline: 0;
}

.recipient-picker-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1100;
    background-color: var(--bs-body-bg, #fff);
    border: 1px solid var(--bs-border-color, #ced4da);
    border-radius: 0.25rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-height: 220px;
    overflow-y: auto;
    margin-top: 2px;
    padding: 0.25rem 0;
}

.recipient-picker-dropdown.shown {
    display: block;
}

.recipient-picker-option {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 0.35rem 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
    white-space: nowrap;
    color: var(--bs-body-color);
    transition: background-color ease-in-out 0.1s, color ease-in-out 0.1s;
}

.recipient-picker-option:hover,
.recipient-picker-option.active {
    color: #fff;
    background-color: #0d6efd;
}

.recipient-picker-option .option-name {
    font-weight: 500;
}

.recipient-picker-option .option-email {
    font-size: 0.75rem;
    color: #6b7280;
    margin-left: 0.5rem;
}

.recipient-picker-option:hover .option-email,
.recipient-picker-option.active .option-email {
    color: rgba(255, 255, 255, 0.75);
}
