/* ===================================================================
   ThasmaiSuite Meditator — App v2 Global Styles
   Global resets, FluentUI overrides, and utility classes.
   All values via design-system-v2 tokens — no hardcoded hex.
   =================================================================== */

/* ===================================================================
   Reset
   =================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ===================================================================
   Body
   =================================================================== */
html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background: var(--surface-secondary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* ===================================================================
   FluentUI Component Overrides
   =================================================================== */

/* Cards — Soft rounded, subtle border */
fluent-card {
  border-radius: var(--card-radius) !important;
  border: var(--card-border) !important;
  box-shadow: var(--card-shadow) !important;
  background: var(--surface-elevated) !important;
  transition: box-shadow var(--duration-base) var(--ease-out),
              transform var(--duration-base) var(--ease-out) !important;
}

fluent-card:hover {
  box-shadow: var(--shadow-md) !important;
}

/* Buttons — Touch-friendly, rounded */
fluent-button {
  --control-corner-radius: var(--btn-radius);
  border-radius: var(--btn-radius) !important;
  font-weight: var(--font-semibold) !important;
  transition: all var(--duration-base) var(--ease-out) !important;
}

fluent-button::part(control) {
  min-height: var(--btn-height) !important;
  padding: 0 var(--btn-padding-x) !important;
  border-radius: var(--btn-radius) !important;
  font-weight: var(--font-semibold) !important;
  font-size: var(--text-base) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Accent buttons — same height as base; use .btn-lg class for full-width CTAs */
fluent-button[appearance="accent"]::part(control) {
  min-height: var(--btn-height) !important;
  padding: 0 var(--btn-padding-x) !important;
  font-size: var(--text-base) !important;
  font-weight: var(--font-semibold) !important;
}

/* Large CTA buttons — opt-in with class="btn-lg" */
fluent-button.btn-lg[appearance="accent"]::part(control) {
  min-height: var(--btn-height-lg) !important;
  padding: 0 calc(var(--btn-padding-x) * 1.25) !important;
  font-size: var(--text-md) !important;
}

/* Small buttons */
fluent-button.btn-sm::part(control) {
  min-height: var(--btn-height-sm) !important;
  padding: 0 var(--sp-4) !important;
  font-size: var(--text-sm) !important;
}

/* Text Fields — Clean with proper height */
fluent-text-field {
  --control-corner-radius: var(--input-radius);
}

fluent-text-field::part(root) {
  min-height: var(--input-height) !important;
  border-radius: var(--input-radius) !important;
}

fluent-text-field::part(control) {
  min-height: var(--input-height) !important;
  padding: 0 var(--input-padding-x) !important;
  font-size: var(--text-base) !important;
  line-height: var(--leading-normal) !important;
}

/* Select — Match text field styling */
fluent-select {
  --control-corner-radius: var(--input-radius);
}

fluent-select::part(control) {
  min-height: var(--input-height) !important;
  border-radius: var(--input-radius) !important;
  padding: 0 var(--input-padding-x) !important;
  font-size: var(--text-base) !important;
}

/* Text Area */
fluent-text-area::part(control) {
  border-radius: var(--input-radius) !important;
  padding: var(--sp-3) var(--input-padding-x) !important;
  font-size: var(--text-base) !important;
  line-height: var(--leading-relaxed) !important;
}

/* Labels */
fluent-label {
  line-height: var(--leading-relaxed) !important;
}

/* Badges — Rounded pill */
fluent-badge {
  border-radius: var(--badge-radius) !important;
  font-weight: var(--font-medium) !important;
  font-size: var(--badge-font-size) !important;
  min-height: var(--badge-height) !important;
}

/* Message Bar */
fluent-message-bar {
  border-radius: var(--input-radius) !important;
}

/* Dialog */
fluent-dialog::part(control) {
  border-radius: var(--card-radius) !important;
  background: var(--surface-elevated) !important;
}

/* Progress Ring */
fluent-progress-ring {
  --accent-fill-rest: var(--accent-primary);
}

/* ===================================================================
   Accessibility — Focus-visible ring (WCAG 2.1 AA, G23)
   2px accent ring on all focusable elements, keyboard-only
   =================================================================== */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

button:focus-visible,
a:focus-visible,
[role="tab"]:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* Remove default outline only when :focus-visible is supported */
:focus:not(:focus-visible) {
  outline: none;
}

/* Headings are not interactive — suppress focus rings (Blazor sets focus on h1 after navigation) */
h1:focus,
h1:focus-visible,
h2:focus,
h2:focus-visible {
  outline: none;
}

/* ===================================================================
   Typography Utility Classes
   =================================================================== */
.text-primary   { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary  { color: var(--text-tertiary); }
.text-accent    { color: var(--accent-primary); }
.text-saffron   { color: var(--saffron-primary); }
.text-success   { color: var(--success-primary); }
.text-warning   { color: var(--warning-primary); }
.text-error     { color: var(--error-primary); }
.text-inverse   { color: var(--text-inverse); }

.text-xs  { font-size: var(--text-xs); }
.text-sm  { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-md  { font-size: var(--text-md); }
.text-lg  { font-size: var(--text-lg); }
.text-xl  { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }

.font-regular  { font-weight: var(--font-regular); }
.font-medium   { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold     { font-weight: var(--font-bold); }

/* ===================================================================
   Background Utility Classes
   =================================================================== */
.bg-primary       { background: var(--surface-primary); }
.bg-secondary     { background: var(--surface-secondary); }
.bg-tertiary      { background: var(--surface-tertiary); }
.bg-elevated      { background: var(--surface-elevated); }
.bg-accent-subtle { background: var(--accent-subtle); }
.bg-saffron-subtle { background: var(--saffron-subtle); }
.bg-success-subtle { background: var(--success-subtle); }
.bg-warning-subtle { background: var(--warning-subtle); }
.bg-error-subtle  { background: var(--error-subtle); }
.bg-hero          { background: var(--hero-gradient); }

body.dark .bg-hero { background: var(--hero-gradient-dark); }

/* ===================================================================
   Border & Shadow Utility Classes
   =================================================================== */
.border-default { border: 1px solid var(--border-default); }
.border-subtle  { border: 1px solid var(--border-subtle); }
.border-accent  { border: 1px solid var(--border-accent); }

.shadow-xs { box-shadow: var(--shadow-xs); }
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.shadow-xl { box-shadow: var(--shadow-xl); }

.rounded-card { border-radius: var(--card-radius); }
.rounded-btn  { border-radius: var(--btn-radius); }
.rounded-input { border-radius: var(--input-radius); }

/* ===================================================================
   Layout — Page Container
   Safe-area-aware bottom padding: nav (64px) + safe-area-inset + 16px buffer
   =================================================================== */
.page-container {
  padding: var(--page-padding-top) var(--page-padding-x)
           calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + var(--sp-4));
  max-width: var(--page-max-width);
  margin: 0 auto;
  width: 100%;
}

/* ===================================================================
   Section Spacing
   =================================================================== */
.section {
  margin-bottom: var(--sp-8);
}

.section:last-child {
  margin-bottom: 0;
}

/* ===================================================================
   Card Grid
   =================================================================== */
.card-grid {
  display: grid;
  gap: var(--sp-4);
}

.card-grid--2 {
  grid-template-columns: repeat(2, 1fr);
}

.card-grid--3 {
  grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 360px) {
  .card-grid--3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ===================================================================
   Interactive Cards
   =================================================================== */
.interactive-card {
  cursor: pointer;
  transition: all var(--duration-base) var(--ease-out);
  background: var(--surface-elevated) !important;
}

.interactive-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md) !important;
}

.interactive-card:active {
  transform: translateY(0);
}

/* ===================================================================
   Stat Cards
   =================================================================== */
.stat-card {
  text-align: center;
  padding: var(--sp-5) var(--sp-4) !important;
  background: var(--surface-elevated) !important;
  border: 1px solid var(--border-subtle) !important;
  transition: all var(--duration-base) var(--ease-out) !important;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md) !important;
}

.stat-value {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  line-height: var(--leading-tight);
  margin-bottom: var(--sp-2);
  color: var(--accent-primary);
}

.stat-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: var(--font-medium);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ===================================================================
   Icon Containers
   =================================================================== */
.icon-container-sm {
  width: var(--avatar-sm);
  height: var(--avatar-sm);
  border-radius: var(--sp-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-subtle);
  transition: all var(--duration-base) var(--ease-out);
}

.icon-container-md {
  width: var(--avatar-md);
  height: var(--avatar-md);
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-subtle);
  transition: all var(--duration-base) var(--ease-out);
}

.icon-container-lg {
  width: 64px;
  height: 64px;
  border-radius: var(--input-radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-subtle);
  transition: all var(--duration-base) var(--ease-out);
}

/* ===================================================================
   Empty State
   =================================================================== */
.empty-state {
  text-align: center;
  padding: var(--sp-12) var(--sp-6);
}

.empty-state-icon {
  font-size: var(--text-4xl);
  opacity: 0.2;
  margin-bottom: var(--sp-4);
  color: var(--text-tertiary);
}

/* ===================================================================
   Accent Elements
   =================================================================== */
.accent-card {
  background: var(--accent-primary) !important;
  color: var(--text-on-accent) !important;
  border: none !important;
}

.accent-card * {
  color: var(--text-on-accent) !important;
}

.accent-text {
  color: var(--accent-primary);
  font-weight: var(--font-semibold);
}

/* ===================================================================
   Animation Utilities
   =================================================================== */
.fade-slide-up {
  animation: fadeSlideUp var(--duration-entrance) var(--ease-out) both;
}

.scale-in {
  animation: scaleIn var(--duration-entrance) var(--ease-out) both;
}

.fade-in {
  animation: fadeSlideUp var(--duration-slow) ease-out;
}

/* ===================================================================
   Scrollbar Styling
   =================================================================== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ===================================================================
   Selection
   =================================================================== */
::selection {
  background: var(--accent-muted);
  color: var(--text-primary);
}

/* ===================================================================
   Focus Visible
   =================================================================== */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex="0"]:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* ===================================================================
   Loading Shell (kept from app.css for initial load)
   =================================================================== */
.loading-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--surface-secondary);
  color: var(--text-primary);
}

.progress-container {
  height: 6px;
  background: var(--surface-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: var(--sp-4);
}

.progress-bar {
  height: 100%;
  background: var(--accent-primary);
  width: 0%;
  transition: width var(--duration-slow) var(--ease-out);
  border-radius: 3px;
}

.loading-message {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  min-height: var(--sp-6);
  max-width: 400px;
}

@keyframes gentlePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.9; transform: scale(0.98); }
}

/* ===================================================================
   Card Interaction — Global hover/active for clickable cards
   Applied via .card-interactive class on any tappable card element.
   These create a premium "lift" effect on hover and "press" on active.
   =================================================================== */
@media (hover: hover) {
  .card-interactive {
    transition: box-shadow var(--duration-base, 200ms) var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1)),
                transform var(--duration-base, 200ms) var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1));
  }
  .card-interactive:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
  }
}
.card-interactive:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-sm);
}

/* ===================================================================
   Icon-Only Button — Replaces FluentButton for icon-only usage.
   FluentButton web component has shadow DOM padding that can't be
   overridden, causing icon buttons to render wider than declared.
   Use: <button class="icon-btn"> <FluentIcon .../> </button>
   Variant: .icon-btn--accent for filled accent background
   =================================================================== */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  min-width: 48px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, transform 0.15s ease;
}
.icon-btn:hover { background: var(--surface-tertiary); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: 2px; }
.icon-btn:disabled, .icon-btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.icon-btn:disabled:hover, .icon-btn[disabled]:hover { background: transparent; }
.icon-btn--accent {
  background: var(--accent-primary);
  color: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}
.icon-btn--accent:hover { background: var(--accent-hover); box-shadow: 0 4px 12px rgba(99, 102, 241, 0.45); }
.icon-btn--accent:active { background: var(--accent-pressed); transform: scale(0.92); box-shadow: none; }
/* Force icon to white — FluentIcon may apply its own Fluent token color via inline style */
.icon-btn--accent svg,
.icon-btn--accent svg path {
  color: #fff !important;
  fill: #fff !important;
}

/* ── Blazor Error UI (hidden by default; Blazor shows it on unhandled exceptions) ── */
#blazor-error-ui {
    display: none;
    background: #fef9c3;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.18);
    left: 0;
    padding: 10px 20px;
    position: fixed;
    width: 100%;
    z-index: 9999;
    font-size: 14px;
    color: #713f12;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 12px;
    top: 8px;
}
