/* App-specific styles layered on top of Tailwind CDN */

:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-alt: #f8faff;
    --surface-hover: #edf3ff;
    --border: #d9e2f2;
    --border-soft: #e7edf8;
    --text: #111827;
    --text-muted: #64748b;
    --text-subtle: #94a3b8;
    --brand: #3a82f6;
    --brand-hover: #2f66cc;
    --brand-soft-bg: #e8f1ff;
    --brand-soft-text: #2f66cc;
    --skeleton-from: #eef3fb;
    --skeleton-to: #d9e2f2;
    --shadow-toast: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}

html.dark {
    --bg: #0f1729;
    --surface: #111b30;
    --surface-alt: #15223f;
    --surface-hover: #1b2c4d;
    --border: #2a3b61;
    --border-soft: #223252;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --text-subtle: #64748b;
    --brand: #7aa7ff;
    --brand-hover: #9ebdff;
    --brand-soft-bg: #1d2c4f;
    --brand-soft-text: #7aa7ff;
    --skeleton-from: #1a2946;
    --skeleton-to: #2a3b61;
    --shadow-toast: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

[x-cloak] { display: none !important; }

html, body { background: var(--bg); }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
}
.panel-soft { background: var(--surface-alt); }
.text-muted { color: var(--text-muted); }
.accent-soft {
    background: var(--brand-soft-bg);
    color: var(--brand-soft-text);
}
.accent-text { color: var(--brand); }

.pref-panel {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem;
    border-radius: 0.75rem;
    background: var(--surface-alt);
    border: 1px solid var(--border);
}
.pref-btn {
    border-radius: 0.5rem;
    padding: 0.375rem 0.625rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    border: 1px solid transparent;
    transition: all 0.15s ease;
}
.pref-btn:hover {
    background: var(--brand-soft-bg);
    color: var(--brand-soft-text);
}
.pref-btn.active {
    background: var(--brand-soft-bg);
    color: var(--brand-soft-text);
    border-color: var(--border);
}
.pref-state {
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

[data-privacy-blur="1"] .privacy-target {
    filter: blur(5px);
    user-select: none;
    transition: filter 0.2s ease;
}

.content-wrap {
    max-width: none;
}

[data-layout="default"] .content-wrap {
    max-width: 1200px !important;
}

[data-layout="wide"] .content-wrap {
    max-width: none !important;
}

.htmx-indicator { opacity: 0; transition: opacity 200ms ease; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1;
    transition: all 150ms ease;
    border: 1px solid transparent;
    cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); }
.btn-danger { background: var(--surface); color: #be123c; border-color: #fda4af; }
.btn-danger:hover:not(:disabled) { background: #fff1f2; }
html.dark .btn-danger { color: #fda4af; border-color: #7f1d1d; background: var(--surface); }
html.dark .btn-danger:hover:not(:disabled) { background: rgba(190, 18, 60, 0.15); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }

.input, .select, .textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.875rem;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.textarea {
    resize: vertical;
    min-height: 100px;
    font-family: ui-monospace, SFMono-Regular, monospace;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    overflow: hidden;
}
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}
details.card > summary.card-header {
    list-style: none;
    user-select: none;
    border-bottom: none;
}
details.card[open] > summary.card-header { border-bottom: 1px solid var(--border); }
summary.card-header::-webkit-details-marker { display: none; }
summary.card-header::marker { content: none; }
.card-title {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--text);
}

.table {
    width: 100%;
    font-size: 0.8125rem;
    color: var(--text);
}
.table thead { background: var(--surface-alt); }
.table th {
    text-align: left;
    padding: 0.625rem 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table td {
    padding: 0.75rem 0.875rem;
    border-bottom: 1px solid var(--border-soft);
    color: var(--text);
    vertical-align: middle;
}
.table tr:hover td { background: var(--surface-hover); }
.table tr[data-row-clickable] { cursor: pointer; }
.table tr[data-row-clickable]:hover td { background: var(--surface-hover); }

.table-compact th { padding: 0.4rem 0.75rem; }
.table-compact td {
    padding: 0.35rem 0.75rem;
    font-size: 0.8125rem;
    line-height: 1.2;
}
.table-compact td .btn { padding: 0.25rem 0.5rem; }
.table-compact td .btn-ghost { padding: 0.25rem; }

.dashboard-hier-table th:nth-child(n + 2),
.dashboard-hier-table td:nth-child(n + 2) {
    white-space: nowrap;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
}
.kpi-label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin-top: 0.25rem;
}

.delta-up { color: #10b981; font-weight: 600; }
.delta-down { color: #ef4444; font-weight: 600; }
.delta-flat { color: var(--text-subtle); }

.skeleton {
    background: linear-gradient(90deg, var(--skeleton-from) 25%, var(--skeleton-to) 50%, var(--skeleton-from) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: 0.375rem;
}
@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.toast {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    box-shadow: var(--shadow-toast);
    min-width: 280px;
    animation: toast-in 200ms ease-out;
}
.toast.toast-success { border-left: 3px solid #10b981; }
.toast.toast-error { border-left: 3px solid #ef4444; }
.toast.toast-info { border-left: 3px solid var(--brand); }
@keyframes toast-in {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 600;
}
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-slate { background: #e2e8f0; color: #334155; }
html.dark .badge-blue { background: rgba(59, 130, 246, 0.18); color: #93c5fd; }
html.dark .badge-green { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }
html.dark .badge-yellow { background: rgba(234, 179, 8, 0.18); color: #fde68a; }
html.dark .badge-red { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
html.dark .badge-slate { background: #1f2937; color: #cbd5e1; }
html.dark .badge-success { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }

.tab-link {
    padding: 0.625rem 1rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    transition: all 150ms ease;
}
.tab-link:hover { color: var(--text); }
.tab-link.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
}

/* ============= Tailwind utility overrides for dark theme ============= */
html.dark .bg-white { background-color: var(--surface) !important; }
html.dark .bg-slate-50 { background-color: var(--bg) !important; }
html.dark .bg-slate-100[class*="text-[10px]"] {
    background-color: rgba(122, 167, 255, 0.2) !important;
    color: #cfe0ff !important;
    border: 1px solid rgba(122, 167, 255, 0.35);
    opacity: 1 !important;
}
html.dark .bg-gray-50,
html.dark .bg-gray-100,
html.dark [class*="bg-gray-50"],
html.dark [class*="bg-gray-100"] { background-color: var(--surface-alt) !important; }
html.dark .bg-slate-50\/40,
html.dark .bg-slate-50\/60 { background-color: rgba(31, 41, 55, 0.6) !important; }
html.dark .bg-amber-50\/40 { background-color: rgba(120, 53, 15, 0.18) !important; }

html.dark .border-slate-200 { border-color: var(--border) !important; }
html.dark .border-slate-100 { border-color: var(--border-soft) !important; }
html.dark .border-gray-100,
html.dark .border-gray-200,
html.dark .border-gray-300,
html.dark [class*="border-gray-"] { border-color: var(--border) !important; }
html.dark .divide-slate-100 > * + * { border-color: var(--border-soft) !important; }

html.dark .text-slate-900 { color: var(--text) !important; }
html.dark .text-slate-800 { color: var(--text) !important; }
html.dark .text-slate-700 { color: #cbd5e1 !important; }
html.dark .text-slate-600 { color: #cbd5e1 !important; }
html.dark .text-slate-500 { color: var(--text-muted) !important; }
html.dark .text-slate-400 { color: var(--text-subtle) !important; }
html.dark .text-slate-300 { color: #475569 !important; }
html.dark .text-gray-900,
html.dark .text-gray-800,
html.dark .text-gray-700,
html.dark .text-gray-600 { color: var(--text) !important; }
html.dark .text-gray-500,
html.dark .text-gray-400 { color: var(--text-muted) !important; }

html.dark .hover\:bg-slate-50:hover { background-color: var(--surface-hover) !important; }
html.dark .hover\:text-slate-900:hover { color: var(--text) !important; }
html.dark .hover\:text-slate-700:hover { color: var(--text) !important; }
html.dark .hover\:bg-gray-100:hover { background-color: #243556 !important; }
html.dark .hover\:bg-blue-50:hover,
html.dark .hover\:bg-indigo-50:hover { background-color: #243a64 !important; }
html.dark .hover\:bg-red-50:hover { background-color: #4d2634 !important; }

html.dark .text-brand-600,
html.dark .text-brand-700 { color: #93c5fd !important; }
html.dark .hover\:text-brand-700:hover { color: #93c5fd !important; }
html.dark .bg-brand-50 { background-color: var(--brand-soft-bg) !important; }
html.dark .text-brand-700.bg-brand-50,
html.dark .bg-brand-50 .text-brand-700 { color: var(--brand-soft-text) !important; }
html.dark .bg-indigo-50,
html.dark .bg-purple-50 { background-color: #1d2c4f !important; }
html.dark .bg-green-50 { background-color: #11352d !important; }
html.dark .bg-red-50 { background-color: #3b1f2a !important; }
html.dark .bg-amber-50 { background-color: #3b3120 !important; }

html.dark .text-emerald-700 { color: #34d399 !important; }
html.dark .text-rose-500 { color: #fb7185 !important; }
html.dark .text-rose-600 { color: #fb7185 !important; }
html.dark .text-rose-800 { color: #fecaca !important; }
html.dark .bg-rose-50 { background-color: rgba(190, 18, 60, 0.15) !important; }
html.dark .border-rose-200 { border-color: rgba(190, 18, 60, 0.4) !important; }
html.dark .bg-rose-50\/50 { background-color: rgba(190, 18, 60, 0.1) !important; }
html.dark .text-emerald-800 { color: #6ee7b7 !important; }
html.dark .bg-emerald-50 { background-color: rgba(16, 185, 129, 0.15) !important; }
html.dark .border-emerald-200 { border-color: rgba(16, 185, 129, 0.4) !important; }
html.dark .text-blue-800 { color: #93c5fd !important; }
html.dark .bg-blue-50 { background-color: rgba(59, 130, 246, 0.15) !important; }
html.dark .border-blue-200 { border-color: rgba(59, 130, 246, 0.4) !important; }

html.dark input[type="color"] { background-color: var(--surface); }
html.dark input::placeholder, html.dark textarea::placeholder { color: var(--text-subtle); opacity: 1; }
html.dark input,
html.dark select,
html.dark textarea {
    background-color: var(--surface-alt) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}
html.dark code {
    background: #233251 !important;
    color: #dbeafe !important;
}

/* ============= Positions tab: collapsible groups sidebar ============= */
@media (min-width: 1024px) {
    .positions-grid.is-collapsed { grid-template-columns: 1fr; }
    .positions-grid.is-collapsed [data-positions-sidebar] { display: none; }
}
.positions-grid.is-collapsed [data-expand-sidebar] { display: inline-flex !important; }

/* Sticky right action column needs a clear visual separator from the
   horizontally scrolling table area. Add a soft inset shadow on the left edge. */
.table th.sticky.right-0,
.table td.sticky.right-0 {
    box-shadow: inset 6px 0 6px -6px rgba(15, 23, 42, 0.08);
}
.table th.sticky.left-0,
.table td.sticky.left-0,
.table th.sticky.left-8,
.table td.sticky.left-8 {
    box-shadow: inset -6px 0 6px -6px rgba(15, 23, 42, 0.04);
}
html.dark .table th.sticky.right-0,
html.dark .table td.sticky.right-0 {
    box-shadow: inset 6px 0 6px -6px rgba(0, 0, 0, 0.3);
}
html.dark .table th.sticky.left-0,
html.dark .table td.sticky.left-0,
html.dark .table th.sticky.left-8,
html.dark .table td.sticky.left-8 {
    box-shadow: inset -6px 0 6px -6px rgba(0, 0, 0, 0.2);
}
