/* Global styles for AlphaCore Web Application */
:root {
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "Roboto",
    "Oxygen",
    "Ubuntu",
    "Cantarell",
    "Fira Sans",
    "Droid Sans",
    "Helvetica Neue",
    sans-serif;
  line-height: 1.5;
  font-weight: 400;

  color-scheme: light;

  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background-color: #f9fafb;
  /* Improved text rendering on mobile */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Prevent horizontal scrolling on mobile */
  overflow-x: hidden;
}

#root {
  min-height: 100vh;
  width: 100%;
  /* Ensure proper stacking context */
  position: relative;
}

/* Screen reader only content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus styles for accessibility */
*:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Responsive utilities */
.container-mobile {
  padding: 0 16px;
}

.container-tablet {
  padding: 0 24px;
}

.container-desktop {
  padding: 0 32px;
  max-width: 1200px;
  margin: 0 auto;
}

/* Touch-friendly interactive elements */
@media (max-width: 899px) {
  .touch-target,
  button,
  a,
  .MuiIconButton-root,
  .MuiButton-root,
  [role="button"] {
    min-height: 44px !important;
    min-width: 44px !important;
  }

  /* Exception for inline text links */
  a:not([role="button"]):not(.MuiButton-root) {
    min-height: unset !important;
    min-width: unset !important;
  }
}

/* Improved responsive grid */
.responsive-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

@media (min-width: 600px) {
  .responsive-grid {
    gap: 20px;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }
}

@media (min-width: 900px) {
  .responsive-grid {
    gap: 24px;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  }
}

/* Better mobile scrolling */
.mobile-scroll {
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

/* Responsive text truncation */
.text-truncate-mobile {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 600px) {
  .text-truncate-mobile {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --color-border: #000000;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Print styles */
@media print {
  .no-print {
    display: none !important;
  }

  * {
    background: transparent !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
}

/* Custom scrollbar for webkit browsers */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* ============================================================
   Design System Utilities — ported from handoff tokens.css
   ============================================================ */

/* ── Card ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.card.flat {
  box-shadow: none;
}
.card.elev {
  box-shadow: var(--sh-1);
}
.card.pop {
  box-shadow: var(--sh-pop);
}

.card-action {
  cursor: pointer;
  transition:
    transform 120ms,
    box-shadow 120ms;
}
.card-action:hover {
  transform: translateY(-2px);
  box-shadow: var(--sh-2);
}

/* ── Button ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-elev);
  color: var(--ink-1);
  font-weight: 500;
  font-size: 13px;
  font-family: inherit;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  transition:
    background 120ms,
    border-color 120ms;
  white-space: nowrap;
}
.btn:hover {
  background: var(--bg-sunken);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn.primary {
  background: var(--ink-1);
  color: var(--bg);
  border-color: var(--ink-1);
}
.btn.primary:hover {
  opacity: 0.88;
}
.btn.accent {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn.accent:hover {
  opacity: 0.88;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-2);
}
.btn.ghost:hover {
  background: var(--bg-sunken);
}
.btn.sm {
  height: 26px;
  padding: 0 10px;
  font-size: 12px;
}
.btn.lg {
  height: 40px;
  padding: 0 18px;
  font-size: 14px;
}
.btn.icon {
  padding: 0;
  width: 32px;
}
.btn.sm.icon {
  width: 26px;
}

/* ── Pill ─────────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--bg-sunken);
  color: var(--ink-2);
}
.pill.ok {
  background: var(--ok-soft);
  color: var(--ok-soft-ink);
}
.pill.warn {
  background: var(--warn-soft);
  color: var(--warn-soft-ink);
}
.pill.risk {
  background: var(--risk-soft);
  color: var(--risk-soft-ink);
}
.pill.info {
  background: var(--info-soft);
  color: var(--info-soft-ink);
}
.pill.accent {
  background: var(--accent-soft);
  color: var(--accent);
}
.pill.ghost {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--ink-2);
}
.pill.dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* ── Typography helpers ───────────────────────────────────── */
.h-display {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--ink-1);
}
.mono {
  font-family: var(--font-mono);
  font-feature-settings: "tnum";
  letter-spacing: -0.01em;
}
.tnum {
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}
.section-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
}

/* ── Icon button ──────────────────────────────────────────── */
.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  color: var(--ink-3);
  background: transparent;
  border: none;
  transition:
    background 120ms,
    color 120ms;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.iconbtn:hover {
  background: var(--bg-sunken);
  color: var(--ink-1);
}

/* ── Table ────────────────────────────────────────────────── */
.tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
.tbl th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  padding: 10px var(--pad-x);
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--line);
}
.tbl td {
  padding: var(--pad-y) var(--pad-x);
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
  vertical-align: middle;
}
.tbl tbody tr:hover td {
  background: var(--bg-sunken);
}
.tbl tbody tr:last-child td {
  border-bottom: none;
}

/* ── Form elements ────────────────────────────────────────── */
.input {
  height: 32px;
  padding: 0 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--ink-1);
  font-size: 13px;
  font-family: inherit;
  line-height: 1;
  outline: none;
  transition: border-color 120ms;
  width: 100%;
}
.input:focus {
  border-color: var(--accent);
}
.input::placeholder {
  color: var(--ink-4);
}
.input.sm {
  height: 26px;
  font-size: 12px;
}
.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 18px;
  min-width: 18px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
  font: 500 10px/1 var(--font-mono);
  color: var(--ink-3);
  background: var(--bg-elev);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
}
.helptext {
  font-size: 11px;
  color: var(--ink-3);
}

/* ── Dividers ─────────────────────────────────────────────── */
.hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 0;
}
.vr {
  border: none;
  border-left: 1px solid var(--line);
  margin: 0;
}

/* ── Scroll ───────────────────────────────────────────────── */
.scroll {
  overflow-y: auto;
}

/* ── DS Batch A additions (ALH-546) ─────────────────────────────────── */

/* Pills — solid (AA-verified ink pairs) */
.pill.solid-ok {
  background: var(--ok);
  color: var(--ok-ink);
}
.pill.solid-risk {
  background: var(--risk);
  color: var(--risk-ink);
}

/* IconButton active modifier */
.iconbtn.active {
  background: var(--bg-sunken);
  color: var(--ink-1);
}

/* Field required / optional markers + error helper text */
.label .req {
  color: var(--risk);
  margin-left: 2px;
}
.label .opt {
  color: var(--ink-3);
  font-weight: 400;
}
.helptext.error {
  color: var(--risk);
}

/* EmptyState placeholder */
.stripe-ph {
  width: 56px;
  height: 70px;
  background: repeating-linear-gradient(
    135deg,
    var(--bg-sunken) 0 6px,
    var(--bg-elev) 6px 12px
  );
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  opacity: 0.6;
}

/* ── KPI card hover reveal ────────────────────────────────── */
.kpi-view-link {
  opacity: 0.6;
  transition: opacity 120ms;
}
.kpi-card:hover .kpi-view-link {
  opacity: 1;
}

/* ── Loading progress animation ──────────────────────────── */
@keyframes progress-slide {
  0% {
    transform: translateX(-100%);
    width: 40%;
  }
  50% {
    width: 70%;
  }
  100% {
    transform: translateX(300%);
    width: 40%;
  }
}

/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* === Batch C: composite primitives ====================================== */

/* -- Tabs (underline pattern; complements segmented DashboardTabBar) ----- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
}
.tabs .tab {
  appearance: none;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 8px 12px;
  font-weight: 500;
  font-size: 12px;
  line-height: 1;
  color: var(--ink-3);
  cursor: pointer;
  transition: color 120ms;
}
.tabs .tab:hover {
  color: var(--ink-2);
}
.tabs .tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: var(--r-sm);
}
.tabs .tab.active,
.tabs .tab[aria-selected="true"] {
  color: var(--ink-1);
  border-bottom-color: var(--accent);
}

/* -- Pipeline strip ------------------------------------------------------ */
.pipeline-strip {
  padding: 16px;
}
.pipeline-strip .head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.pipeline-strip .head .summary {
  font-weight: 500;
  font-size: 11px;
  line-height: 1;
  font-family: var(--font-mono);
  color: var(--ink-3);
}
.pipeline-strip .grid {
  display: grid;
  gap: 8px;
}
.pipeline-cell {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--bg-elev);
}
.pipeline-cell.tone-info {
  background: var(--info-soft);
}
.pipeline-cell.tone-warn {
  background: var(--warn-soft);
}
.pipeline-cell.tone-ok {
  background: var(--ok-soft);
}
.pipeline-cell.tone-risk {
  background: var(--risk-soft);
}
.pipeline-cell.tone-ghost {
  background: var(--bg-elev);
}
.pipeline-cell .bar {
  height: 3px;
  margin-top: 8px;
  background: var(--bg-sunken);
  border-radius: var(--r-xs, 4px);
  overflow: hidden;
}
.pipeline-cell .bar > span {
  display: block;
  height: 100%;
  background: var(--ink-3);
}
.pipeline-cell.tone-info .bar > span {
  background: var(--info);
}
.pipeline-cell.tone-warn .bar > span {
  background: var(--warn);
}
.pipeline-cell.tone-ok .bar > span {
  background: var(--ok);
}
.pipeline-cell.tone-risk .bar > span {
  background: var(--risk);
}
.pipeline-cell.tone-ghost .bar > span {
  background: var(--ink-3);
}

/* -- Form section (label / body two-column form layout) ------------------ */
.form-section {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  gap: 32px;
  padding: 24px 0;
  border-top: 1px solid var(--line);
}
.form-section.first {
  border-top: 0;
  padding-top: 8px;
}
.form-section > :first-child > h2,
.form-section > :first-child > h3,
.form-section > :first-child > h4,
.form-section > :first-child > h5 {
  margin: 0 0 4px;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
  color: var(--ink-1);
}
.form-section > :first-child > p {
  margin: 0;
  font-size: 12px;
  color: var(--ink-3);
}
.form-section > .body {
  display: grid;
  gap: 16px;
}
@media (max-width: 900px) {
  .form-section {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

/* -- DataTable empty-state row & clickable rows -------------------------- */
.tbl tbody tr.empty td {
  padding: 32px;
  text-align: center;
  color: var(--ink-3);
}
.tbl tbody tr[role="button"] {
  cursor: pointer;
}
.tbl tbody tr[role="button"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
