/**
 * Tacala Workspace - Design system (aligned with Tacala-Middleware)
 * Design tokens, light/dark theme variables, and component overrides.
 */

/* --------------------------------------------------------------------------- */
/* Design tokens                                                               */
/* --------------------------------------------------------------------------- */

:root {
  --app-radius: 8px;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --line-tight: 1.35;
  --line-normal: 1.5;
  --line-relaxed: 1.6;

  /* Light theme */
  --bg-primary: #f0f1f2;
  --bg-secondary: #d8d9dc;
  --bg-tertiary: #c4c6c9;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --text-primary: #334155;
  --text-secondary: #475569;
  --text-tertiary: #64748b;
  --border-color: #d8d9dc;
  --border-strong: #c4c6c9;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-muted: #e0e7ff;
  --purple: #7c3aed;
  --purple-muted: #ede9fe;
  --success: #059669;
  --success-bg: #d1fae5;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --error: #b91c1c;
  --error-bg: #fee2e2;
  --info: #1d4ed8;
  --info-bg: #dbeafe;
  --sticky-column-bg: #f5f5f5;
}

/* Dark theme - when html has .dark-mode */
html.dark-mode {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --surface: #1e293b;
  --surface-hover: #334155;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-tertiary: #64748b;
  --border-color: #334155;
  --border-strong: #475569;
  --primary: #60a5fa;
  --primary-hover: #93c5fd;
  --primary-muted: #1e3a5f;
  --purple: #a78bfa;
  --purple-muted: #2e1065;
  --success: #34d399;
  --success-bg: #064e3b;
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.15);
  --error: #f87171;
  --error-bg: #7f1d1d;
  --info: #93c5fd;
  --info-bg: rgba(59, 130, 246, 0.2);
  --sticky-column-bg: #334155;
}

/* Import Processing: parameter card respects dark mode */
html.dark-mode .invoice-params-container {
  background-color: #334155 !important;
  border-color: #475569 !important;
}

/* Fixed/sticky table columns - single source of truth (overrides inline and scoped styles) */
.sticky-left {
  background: var(--sticky-column-bg) !important;
  background-color: var(--sticky-column-bg) !important;
}

/* MudBlazor components - consistent radius */
.mud-paper,
.mud-card,
.mud-button-root,
.mud-input-control,
.mud-expansion-panels .mud-expansion-panel,
.mud-table-container {
  border-radius: var(--app-radius) !important;
}

.mud-dialog-title-bar + .mud-dialog-content,
.mud-menu .mud-paper {
  border-radius: var(--app-radius) !important;
}

/* File preview dialog: no container scrollbar, only iframe scrolls */
.file-preview-dialog .mud-dialog-content {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Side menu - token-based (text-secondary, surface-hover, primary/primary-muted for active) */
/* Light mode: restore original side menu colors */
html:not(.dark-mode) .app-drawer {
  --bg-secondary: #e2e8f0;
  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;
}
/* Dark mode: sections lighter than drawer so unselected items are distinct */
html.dark-mode .app-drawer {
  --bg-secondary: #334155;
  --border-color: #475569;
  --border-strong: #64748b;
}
.app-drawer .mud-nav-menu .mud-nav-group {
  background: transparent !important;
}
.app-drawer .mud-nav-group .mud-collapse-container,
.app-drawer .mud-nav-group .mud-nav-link {
  background: transparent !important;
  border-radius: 6px;
}
.app-drawer .mud-nav-group .mud-nav-link {
  min-height: 40px;
}
.app-drawer .sidebar-section .mud-nav-group .mud-nav-link {
  padding-left: 12px !important;
}
.app-drawer .sidebar-section .mud-nav-group .mud-collapse-container .mud-nav-link {
  padding-left: 48px !important;
}
.app-drawer .mud-nav-link {
  border-radius: 6px;
  transition: background-color 0.15s ease, color 0.15s ease;
  color: var(--text-secondary) !important;
}
.app-drawer .mud-nav-link .mud-nav-link-icon,
.app-drawer .mud-nav-link .mud-nav-link-text,
.app-drawer .mud-nav-link .mud-nav-link-expand-icon {
  color: inherit !important;
}
.app-drawer .mud-nav-link:hover {
  background: var(--surface-hover) !important;
  color: var(--text-primary) !important;
}
.app-drawer .mud-nav-link.active,
.app-drawer .mud-list-item.active {
  background: var(--primary-muted) !important;
  color: var(--primary) !important;
}
.app-drawer .sidebar-section,
.app-drawer .sidebar-section .mud-card {
  background: var(--bg-secondary) !important;
  border: 1px solid var(--border-color) !important;
}
.app-drawer .sidebar-section .white-navlink,
.app-drawer .sidebar-section .mud-nav-link .mud-nav-link-text {
  color: var(--text-secondary) !important;
}
.app-drawer .sidebar-section .mud-nav-link:hover .mud-nav-link-text,
.app-drawer .sidebar-section .mud-nav-link:hover {
  color: var(--text-primary) !important;
}
.app-drawer .sidebar-section .mud-nav-link.active .mud-nav-link-text,
.app-drawer .sidebar-section .mud-nav-link.active {
  color: var(--primary) !important;
  background: var(--primary-muted) !important;
}
/* Expanded section colors: Taco Bell = purple, 7 Brew = blue, RSC = green */
.app-drawer .sidebar-section-expanded-tacobell,
.app-drawer .sidebar-section-expanded-tacobell .mud-card {
  background: var(--purple-muted) !important;
  border-color: var(--purple) !important;
}
.app-drawer .sidebar-section-expanded-tacobell .white-navlink,
.app-drawer .sidebar-section-expanded-tacobell .mud-nav-link .mud-nav-link-text,
.app-drawer .sidebar-section-expanded-tacobell .mud-nav-link .mud-nav-link-icon {
  color: var(--purple) !important;
}
.app-drawer .sidebar-section-expanded-tacobell .mud-nav-link:hover,
.app-drawer .sidebar-section-expanded-tacobell .mud-nav-link:hover .mud-nav-link-text {
  color: var(--purple) !important;
  background: var(--surface-hover) !important;
}
.app-drawer .sidebar-section-expanded-tacobell .mud-nav-link.active,
.app-drawer .sidebar-section-expanded-tacobell .mud-nav-link.active .mud-nav-link-text {
  color: var(--purple) !important;
  background: var(--purple-muted) !important;
}

.app-drawer .sidebar-section-expanded-7brew,
.app-drawer .sidebar-section-expanded-7brew .mud-card {
  background: var(--primary-muted) !important;
  border-color: var(--primary) !important;
}
.app-drawer .sidebar-section-expanded-7brew .white-navlink,
.app-drawer .sidebar-section-expanded-7brew .mud-nav-link .mud-nav-link-text,
.app-drawer .sidebar-section-expanded-7brew .mud-nav-link .mud-nav-link-icon {
  color: var(--primary) !important;
}
.app-drawer .sidebar-section-expanded-7brew .mud-nav-link:hover,
.app-drawer .sidebar-section-expanded-7brew .mud-nav-link:hover .mud-nav-link-text {
  color: var(--primary) !important;
  background: var(--surface-hover) !important;
}
.app-drawer .sidebar-section-expanded-7brew .mud-nav-link.active,
.app-drawer .sidebar-section-expanded-7brew .mud-nav-link.active .mud-nav-link-text {
  color: var(--primary) !important;
  background: var(--primary-muted) !important;
}

.app-drawer .sidebar-section-expanded-rsc,
.app-drawer .sidebar-section-expanded-rsc .mud-card {
  background: var(--success-bg) !important;
  border-color: var(--success) !important;
}
.app-drawer .sidebar-section-expanded-rsc .white-navlink,
.app-drawer .sidebar-section-expanded-rsc .mud-nav-link .mud-nav-link-text,
.app-drawer .sidebar-section-expanded-rsc .mud-nav-link .mud-nav-link-icon {
  color: var(--success) !important;
}
.app-drawer .sidebar-section-expanded-rsc .mud-nav-link:hover,
.app-drawer .sidebar-section-expanded-rsc .mud-nav-link:hover .mud-nav-link-text {
  color: var(--success) !important;
  background: var(--surface-hover) !important;
}
.app-drawer .sidebar-section-expanded-rsc .mud-nav-link.active,
.app-drawer .sidebar-section-expanded-rsc .mud-nav-link.active .mud-nav-link-text {
  color: var(--success) !important;
  background: var(--success-bg) !important;
}

/* Top-level nav links (Dashboard, Favorites) - override component white color with tokens */
.app-drawer .white-navlink,
.app-drawer .white-navlink .mud-nav-link-text,
.app-drawer .white-navlink .mud-nav-link-icon,
.app-drawer .white-navlink .mud-nav-link-expand-icon {
  color: var(--text-secondary) !important;
}
.app-drawer .white-navlink:hover,
.app-drawer .white-navlink:hover .mud-nav-link-text,
.app-drawer .white-navlink:hover .mud-nav-link-icon {
  color: var(--text-primary) !important;
}
.app-drawer .white-navlink.active,
.app-drawer .white-navlink.active .mud-nav-link-text {
  color: var(--primary) !important;
  background: var(--primary-muted) !important;
}

/* MudAlert - brighter, less opaque Info and Warning site-wide, with borders */
.mud-alert[class*="info"] {
  background-color: var(--info-bg) !important;
  color: var(--info) !important;
  border: 1px solid var(--info) !important;
  border-radius: var(--app-radius) !important;
}
.mud-alert[class*="info"] .mud-alert-message,
.mud-alert[class*="info"] .mud-typography {
  color: var(--info) !important;
}
html.dark-mode .mud-alert[class*="info"] {
  background-color: rgba(96, 165, 250, 0.14) !important;
  color: #93c5fd !important;
  border-color: #60a5fa !important;
}
html.dark-mode .mud-alert[class*="info"] .mud-alert-message,
html.dark-mode .mud-alert[class*="info"] .mud-typography {
  color: #93c5fd !important;
}

.mud-alert[class*="warning"] {
  background-color: var(--warning-bg) !important;
  color: var(--warning) !important;
  border: 1px solid #d97706 !important;
  border-radius: var(--app-radius) !important;
}
.mud-alert[class*="warning"] .mud-alert-message,
.mud-alert[class*="warning"] .mud-typography {
  color: #92400e !important;
}
html.dark-mode .mud-alert[class*="warning"] {
  background-color: var(--warning-bg) !important;
  color: #fcd34d !important;
  border-color: #fbbf24 !important;
}
html.dark-mode .mud-alert[class*="warning"] .mud-alert-message,
html.dark-mode .mud-alert[class*="warning"] .mud-typography {
  color: #fcd34d !important;
}

/* MudBlazor overrides - use design tokens (primary blue, surface, etc.) */
.mud-table-row:hover .mud-table-cell,
.mud-list-item:hover {
  background-color: var(--surface-hover) !important;
}
.mud-table-row.mud-selected-item .mud-table-cell,
.mud-list-item.mud-selected-item,
.mud-list-item.active {
  background-color: var(--primary-muted) !important;
}
.mud-expansion-panels .mud-expansion-panel {
  background-color: var(--surface) !important;
  border: 1px solid var(--border-color) !important;
}

/* Quick Stats and similar in-page expansion panels - use design tokens */
.quick-stats-panel,
.quick-stats-panel.mud-expansion-panel {
  background-color: var(--surface) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: var(--app-radius) !important;
  padding: var(--space-2) !important;
}
.quick-stats-panel .mud-expansion-panel-header,
.quick-stats-panel .mud-expansion-panel-content {
  background: transparent !important;
  color: var(--text-primary) !important;
}
.quick-stats-panel .card-icon {
  color: var(--text-secondary) !important;
}
/* Softer quick stats cards - no heavy shadow, muted background */
.dashboard-date-card {
  border-radius: 20px !important;
  padding: 10px 14px !important;
  min-width: 175px;
  margin-top: -16px;
  align-self: center;
  height: fit-content;
}
.dashboard-date-card .mud-card-content,
.dashboard-date-card .mud-stack {
  min-height: 0;
  padding: 0 !important;
}
.dashboard-date-card .mud-card-content {
  display: flex;
  align-items: center;
}

.quick-stats-panel .dashboard-item-wrapper,
.quick-stats-panel .mud-card {
  background: var(--bg-secondary) !important;
  border: 1px solid var(--border-color) !important;
  box-shadow: none !important;
}
.quick-stats-panel .dashboard-item-wrapper:hover,
.quick-stats-panel .mud-card:hover {
  background: var(--surface-hover) !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06) !important;
}
.mud-button-filled-primary {
  background-color: var(--primary) !important;
}
.mud-button-filled-primary:hover {
  background-color: var(--primary-hover) !important;
}
.mud-input-outlined.mud-input-focused .mud-input-outlined-border,
.mud-select-outlined.mud-input-focused .mud-input-outlined-border {
  border-color: var(--primary) !important;
}
.mud-ripple-primary::after {
  background: var(--primary-muted);
}

/* --------------------------------------------------------------------------- */
/* App shell - layout, drawer, header (surface + borders, Middleware-style)    */
/* --------------------------------------------------------------------------- */

.app-layout {
  background: var(--bg-primary);
}

.app-drawer {
  background: var(--surface) !important;
  border-right: none;
}
.app-drawer .mud-drawer-content {
  padding-left: 0;
  padding-right: 0;
  padding-top: var(--space-5);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.app-drawer-inner {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.app-drawer-collapse-row {
  flex-shrink: 0;
  padding: var(--space-2) 12px var(--space-3);
  border-top: 1px solid var(--border-color);
}
.app-drawer-collapse-btn {
  justify-content: flex-start;
  text-transform: none;
  color: var(--text-secondary) !important;
}
.app-drawer-collapse-btn:hover {
  color: var(--text-primary) !important;
  background: var(--surface-hover) !important;
}
.app-drawer-header {
  background: var(--surface) !important;
  border-bottom: none;
  padding-bottom: var(--space-2) !important;
}
.app-drawer-title {
  color: var(--text-primary) !important;
}
/* Dashboard and Favorites: same row alignment (icon + text start at same left edge) */
.app-drawer-primary-nav {
  padding-left: 0;
  padding-right: 0;
}
.app-drawer-primary-nav .mud-nav-menu {
  padding: 0;
}
.app-drawer-primary-nav .mud-nav-link,
.app-drawer-primary-nav .mud-nav-group .mud-nav-link {
  padding-left: 12px !important;
  min-height: 40px;
  margin-bottom: 2px;
}
.app-drawer-primary-nav .mud-nav-group .mud-collapse-container .mud-nav-link {
  padding-left: 48px !important;
}

/* Layout below header: fill height so main content stretches */
.app-layout.app-layout-below-header,
.app-layout.app-layout-below-header.mud-layout {
  display: flex !important;
  flex: 1;
  min-height: 0;
  height: 100%;
}
.app-layout.app-layout-below-header .mud-main-content {
  display: flex !important;
  flex-direction: column !important;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.app-main {
  padding: 0 !important;
  background: var(--bg-primary) !important;
  flex: 1 !important;
  min-height: 0 !important;
  height: 100% !important;
}

.mud-layout .mud-main-content {
  padding: 0 !important;
}

.app-header {
  background: var(--surface) !important;
  border-bottom: 1px solid var(--border-color);
  height: 56px;
  min-height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
  color: var(--text-primary);
}
.app-bar {
  flex-shrink: 0;
}
.app-header-icon {
  color: var(--text-secondary) !important;
  align-self: center;
}
.app-header-icon:hover {
  color: var(--text-primary) !important;
  background: var(--surface-hover) !important;
}
/* Breadcrumbs: larger page title (current page), align vertically */
.app-header-breadcrumbs {
  margin: 0 0 0 100px;
  flex: 1;
  color: var(--text-secondary) !important;
  display: flex !important;
  align-items: center !important;
  font-size: var(--text-base) !important;
}
.app-header-drawer-closed .app-header-breadcrumbs {
  margin-left: 0;
  justify-content: center;
}
/* Current page (last breadcrumb) - larger page title */
.app-header-breadcrumbs .mud-breadcrumb-item:last-child .mud-breadcrumb-link,
.app-header-breadcrumbs li:last-child a {
  font-size: var(--text-lg) !important;
  font-weight: 600 !important;
  color: var(--text-primary) !important;
}
.app-header .app-profile-btn {
  align-self: center;
}

/* Profile button - Middleware-style bordered */
.app-profile-btn {
  min-height: 44px !important;
  padding: 8px 14px !important;
  text-transform: none !important;
  border: 1px solid var(--border-strong) !important;
  background: var(--surface) !important;
  color: var(--text-secondary) !important;
  border-radius: 8px !important;
}
.app-profile-btn:hover {
  background: var(--surface-hover) !important;
  border-color: var(--border-strong) !important;
  color: var(--text-primary) !important;
}
.app-profile-avatar {
  margin-right: 8px !important;
  background: var(--bg-tertiary) !important;
}
.app-profile-name {
  font-size: var(--text-sm);
  font-weight: 500;
}

/* --------------------------------------------------------------------------- */
/* Scrollbars (dark mode – WebKit + Firefox)                                   */
/* --------------------------------------------------------------------------- */
html.dark-mode::-webkit-scrollbar,
html.dark-mode *::-webkit-scrollbar {
  width: 10px !important;
  height: 10px !important;
}
html.dark-mode::-webkit-scrollbar-track,
html.dark-mode *::-webkit-scrollbar-track {
  background: #1e293b !important;
}
html.dark-mode::-webkit-scrollbar-thumb,
html.dark-mode *::-webkit-scrollbar-thumb {
  background: #475569 !important;
  border-radius: 5px !important;
  border: 2px solid #1e293b !important;
}
html.dark-mode::-webkit-scrollbar-thumb:hover,
html.dark-mode *::-webkit-scrollbar-thumb:hover {
  background: #64748b !important;
}
html.dark-mode {
  scrollbar-color: #475569 #1e293b;
  scrollbar-width: thin;
}

/* --------------------------------------------------------------------------- */
/* Lighten non-striped table rows slightly                                     */
/* --------------------------------------------------------------------------- */
.mud-table-body .mud-table-row:not(.mud-table-row-striped) td {
  background-color: rgba(0, 0, 0, 0.015);
}
html.dark-mode .mud-table-body .mud-table-row:not(.mud-table-row-striped) td {
  background-color: rgba(255, 255, 255, 0.015);
}

/* --------------------------------------------------------------------------- */
/* Focus-visible – primary outline for buttons and nav links                   */
/* --------------------------------------------------------------------------- */
.app-profile-btn:focus-visible,
.app-drawer .mud-nav-link:focus-visible,
.mud-button-root:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
