/**
 * Nomo Appearance — توحيد الوضع الفاتح والداكن (طبقة فوق app + nomo-ui)
 */

/* ── Light tokens ─────────────────────────────────────── */
:root {
    color-scheme: light;
    --border-strong: #cbd5e1;
    --accent-hover: #166534;
    --nav-active-text: #14532d;
    --input-bg: #ffffff;
    --table-head-bg: #f8fafc;
    --surface-muted: #f1f5f9;
    --overlay-bg: rgba(15, 23, 42, 0.45);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --focus-ring-glow: rgba(20, 83, 45, 0.18);
}

/* ── Dark tokens ──────────────────────────────────────── */
html.dark {
    color-scheme: dark;
    --border-strong: #475569;
    --accent-hover: #4ade80;
    --nav-active-text: #4ade80;
    --input-bg: #0f172a;
    --table-head-bg: #334155;
    --surface-muted: #1e293b;
    --overlay-bg: rgba(2, 6, 23, 0.72);
    --success-bg: rgba(34, 197, 94, 0.14);
    --success-fg: #86efac;
    --warning-bg: rgba(245, 158, 11, 0.14);
    --warning-fg: #fcd34d;
    --danger-bg: rgba(239, 68, 68, 0.14);
    --danger-fg: #fca5a5;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.4);
    --focus-ring-glow: rgba(34, 197, 94, 0.22);
}

html.dark body {
    background:
        radial-gradient(circle at 88% 0%, rgba(34, 197, 94, 0.07), transparent 32%),
        radial-gradient(circle at 4% 100%, rgba(15, 118, 110, 0.06), transparent 28%),
        var(--bg) !important;
}

/* ── Light: sidebar فاتح ──────────────────────────────── */
html:not(.dark) {
    --nav-bg: #ffffff;
    --nav-link: #64748b;
    --nav-link-hover: #0f172a;
    --nav-active: #ecfdf5;
    --nav-active-text: var(--accent, #14532d);
}

html:not(.dark) .app-sidebar {
    border-inline-start: 1px solid var(--border) !important;
    box-shadow: inset -1px 0 0 rgba(15, 23, 42, 0.04);
}

html:not(.dark) .sidebar-toolbar {
    background: var(--card) !important;
    border-color: var(--border) !important;
}

html:not(.dark) .sidebar-brand strong,
html:not(.dark) .sidebar-section-title {
    color: var(--text) !important;
}

html:not(.dark) .sidebar-search {
    background: var(--bg) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
}

html:not(.dark) .sidebar-section {
    background: var(--bg) !important;
    border-color: var(--border) !important;
}

html:not(.dark) .sidebar-more-toggle,
html:not(.dark) .compact-toggle,
html:not(.dark) .reset-order-toggle,
html:not(.dark) .reset-all-toggle,
html:not(.dark) .sidebar-close {
    background: var(--bg) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
}

html:not(.dark) .sidebar-role {
    background: var(--accent-soft) !important;
    color: var(--accent) !important;
}

html:not(.dark) .quick-link-empty {
    color: var(--muted) !important;
}

/* ── Forms & inputs ───────────────────────────────────── */
input:not([type=checkbox]):not([type=radio]):not([type=submit]):not([type=button]),
select,
textarea,
.form-control,
.form-select {
    background-color: var(--input-bg) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}

input::placeholder,
textarea::placeholder {
    color: var(--muted);
    opacity: 0.85;
}

html.dark input:focus,
html.dark select:focus,
html.dark textarea:focus,
html.dark .form-control:focus,
html.dark .form-select:focus {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px var(--focus-ring-glow) !important;
}

html.dark .form-control:disabled,
html.dark .form-select:disabled {
    background-color: var(--surface-muted) !important;
    color: var(--muted) !important;
}

/* ── Tables ───────────────────────────────────────────── */
.data-table thead th,
.table thead th {
    background: var(--table-head-bg) !important;
    color: var(--muted) !important;
    border-color: var(--border) !important;
}

.data-table td,
.table td {
    color: var(--text);
    border-color: var(--border) !important;
}

html.dark .data-table tbody tr:hover td,
html.dark .table tbody tr:hover td {
    background: rgba(34, 197, 94, 0.06) !important;
}

html:not(.dark) .data-table tbody tr:hover td {
    background: rgba(20, 83, 45, 0.04) !important;
}

html.dark .table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text);
    --bs-table-border-color: var(--border);
    --bs-table-striped-bg: rgba(15, 23, 42, 0.35);
    --bs-table-hover-bg: rgba(34, 197, 94, 0.08);
}

html.dark .table-light {
    --bs-table-bg: var(--card);
    --bs-table-color: var(--text);
}

html.dark .table-dark {
    --bs-table-bg: #334155;
    --bs-table-color: #e2e8f0;
    --bs-table-border-color: var(--border);
}

html.dark .table-dark th,
html.dark .table-dark td {
    border-color: var(--border) !important;
}

/* ── Cards & panels ───────────────────────────────────── */
.card,
.metric,
.filter-card,
.stat-strip,
.modal-content,
.dropdown-menu,
.list-group-item {
    color: var(--text);
}

html.dark .card,
html.dark .metric {
    border-color: var(--border) !important;
}

.filter-card {
    background: var(--table-head-bg) !important;
}

html.dark .filter-card {
    background: var(--surface-muted) !important;
}

html.dark .stat-strip {
    background: linear-gradient(90deg, rgba(34, 197, 94, 0.1), rgba(34, 197, 94, 0.02)) !important;
    border-color: var(--border) !important;
}

/* ── Buttons ──────────────────────────────────────────── */
.btn-secondary:hover {
    background: var(--surface-muted) !important;
}

html.dark .btn-secondary:hover {
    background: #334155 !important;
}

html.dark .btn-danger {
    background: var(--card) !important;
    color: #f87171 !important;
    border-color: #7f1d1d !important;
}

html.dark .btn-danger:hover {
    background: var(--danger-bg) !important;
}

html.dark .btn-outline-primary,
html.dark .btn-outline-secondary,
html.dark .btn-outline-success,
html.dark .btn-outline-info,
html.dark .btn-outline-danger {
    color: var(--text);
}

/* ── Bootstrap utilities ──────────────────────────────── */
html.dark .text-dark,
html.dark .text-body {
    color: var(--text) !important;
}

html.dark .text-muted {
    color: var(--muted) !important;
}

html.dark .bg-white,
html.dark .bg-light {
    background-color: var(--card) !important;
}

html.dark .bg-light {
    background-color: var(--surface-muted) !important;
}

html.dark .border,
html.dark .border-top,
html.dark .border-bottom {
    border-color: var(--border) !important;
}

/* ── Alerts & status ──────────────────────────────────── */
html.dark .alert {
    border-width: 1px;
}

html.dark .alert-success {
    background: var(--success-bg) !important;
    color: var(--success-fg) !important;
    border-color: rgba(34, 197, 94, 0.35) !important;
}

html.dark .alert-warning {
    background: var(--warning-bg) !important;
    color: var(--warning-fg) !important;
    border-color: rgba(245, 158, 11, 0.35) !important;
}

html.dark .alert-danger {
    background: var(--danger-bg) !important;
    color: var(--danger-fg) !important;
    border-color: rgba(239, 68, 68, 0.35) !important;
}

html.dark .alert-info {
    background: rgba(59, 130, 246, 0.12) !important;
    color: #93c5fd !important;
    border-color: rgba(59, 130, 246, 0.3) !important;
}

html.dark .alert-light {
    background: var(--surface-muted) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}

html.dark .status {
    background: var(--surface-muted);
    border-color: var(--border);
    color: var(--text);
}

/* ── Modals & dropdowns ───────────────────────────────── */
html.dark .modal-content {
    background: var(--card) !important;
    color: var(--text) !important;
    border: 1px solid var(--border);
}

html.dark .modal-header,
html.dark .modal-footer {
    border-color: var(--border) !important;
}

html.dark .btn-close {
    filter: invert(1) grayscale(100%);
    opacity: 0.7;
}

html.dark .dropdown-menu {
    background: var(--card) !important;
    border-color: var(--border) !important;
}

html.dark .dropdown-item {
    color: var(--text) !important;
}

html.dark .dropdown-item:hover,
html.dark .dropdown-item:focus {
    background: var(--surface-muted) !important;
    color: var(--text) !important;
}

html.dark .list-group-item {
    background: var(--card) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}

html.dark .list-group-item-action:hover {
    background: var(--surface-muted) !important;
}

/* ── Action tiles (hub / dashboard) ─────────────────── */
html:not(.dark) .action-tile--blue { border-color: #bfdbfe; background: #f8fafc; }
html:not(.dark) .action-tile--amber { border-color: #fde68a; background: #fffbeb; }
html:not(.dark) .action-tile--rose { border-color: #fecaca; background: #fef2f2; }
html:not(.dark) .action-tile--teal { border-color: #99f6e4; background: #f0fdfa; }

html.dark .action-tile {
    background: var(--card) !important;
    border-color: var(--border) !important;
}

html.dark .action-tile--blue { border-color: #1e3a8a !important; background: linear-gradient(135deg, #172554 0%, var(--card) 100%) !important; }
html.dark .action-tile--amber { border-color: #78350f !important; background: linear-gradient(135deg, #451a03 0%, var(--card) 100%) !important; }
html.dark .action-tile--rose { border-color: #7f1d1d !important; background: linear-gradient(135deg, #450a0a 0%, var(--card) 100%) !important; }
html.dark .action-tile--teal { border-color: #115e59 !important; background: linear-gradient(135deg, #134e4a 0%, var(--card) 100%) !important; }

/* ── Details / collapse / invoice tabs ────────────────── */
html.dark details {
    border-color: var(--border);
    color: var(--text);
}

html.dark details summary {
    color: var(--text);
}

html.dark .invoice-tab-btn.btn-secondary {
    background: var(--surface-muted) !important;
    color: var(--muted) !important;
    border-color: var(--border) !important;
}

html.dark .invoice-tab-btn.btn-primary {
    color: #fff !important;
}

/* ── Theme toggle affordance ──────────────────────────── */
#dark-mode-toggle,
#auth-dark-toggle {
    transition: background 0.2s, border-color 0.2s, transform 0.15s;
}

#dark-mode-toggle:hover,
#auth-dark-toggle:hover {
    transform: scale(1.05);
}

html[data-nomo-theme-pref="dark"] #dark-mode-toggle,
html[data-nomo-theme-pref="dark"] #auth-dark-toggle,
html[data-nomo-theme-pref="dark"] #mkt-dark-toggle {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 2px var(--focus-ring-glow);
}

html[data-nomo-theme-pref="light"] #dark-mode-toggle,
html[data-nomo-theme-pref="light"] #auth-dark-toggle,
html[data-nomo-theme-pref="light"] #mkt-dark-toggle {
    box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.35);
}

/* ── Accent swatches (settings) ─────────────────────── */
html.dark .ui-accent-swatch {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

html.dark .ui-accent-option input:checked + .ui-accent-swatch {
    border-color: var(--accent) !important;
}

/* ── Pagination ───────────────────────────────────────── */
html.dark .pagination .page-link {
    background: var(--card);
    border-color: var(--border);
    color: var(--text);
}

html.dark .pagination .page-item.active .page-link {
    background: var(--accent);
    border-color: var(--accent);
}

/* ── Onboarding nudge (compact, single surface) ───────── */
.onboarding-nudge {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid #99f6e4;
    background: #ecfeff;
    color: #0f766e;
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
    transition: background 0.15s, border-color 0.15s;
}

.onboarding-nudge:hover {
    background: #cffafe;
    border-color: #5eead4;
    color: #115e59;
}

.onboarding-nudge-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.onboarding-nudge-next {
    font-size: 12px;
    font-weight: 600;
    opacity: 0.9;
}

.onboarding-nudge-track {
    height: 6px;
    background: rgba(15, 118, 110, 0.15);
    border-radius: 999px;
    overflow: hidden;
}

.onboarding-nudge-fill {
    height: 100%;
    background: #0d7a55;
    border-radius: 999px;
    transition: width 0.25s ease;
}

.onboarding-nudge-pct {
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.is-permission-denied {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
    filter: grayscale(0.2);
}

.sidebar-onboarding-link {
    display: block;
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(15, 118, 110, 0.12);
    color: #0f766e;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
}

.sidebar-onboarding-link:hover {
    background: rgba(15, 118, 110, 0.2);
}

html.dark .onboarding-nudge {
    background: rgba(15, 118, 110, 0.18);
    border-color: rgba(94, 234, 212, 0.35);
    color: #99f6e4;
}

html.dark .sidebar-onboarding-link {
    background: rgba(15, 118, 110, 0.25);
    color: #99f6e4;
}
