/*
 * AMOSHA UI Foundations v0.1
 *
 * Preview layer loaded after existing legacy CSS.
 * Purpose:
 * - centralize brand/semantic tokens without destructive rewrites;
 * - preview Midnight/Sapphire dark mode;
 * - introduce Muted Gold as a rare value accent;
 * - normalize focus, motion and selection behavior.
 *
 * Do not add component-specific hacks here. Move stable rules into the
 * owning component stylesheet once a migration is verified.
 */

:root {
  /* Brand */
  --brand-ice-blue: #d6e6f3;
  --brand-powder-blue: #a6c5d7;
  --brand-sapphire: #0f52ba;
  --brand-deep-navy: #000926;
  --brand-gold: #c9a85c;

  /* Light semantic palette */
  --bg: #f6f8fb;
  --surface: rgb(255 255 255 / 88%);
  --surface-solid: #ffffff;
  --surface-2: #eef3f8;
  --surface-3: #e3eaf2;
  --text: #111827;
  --text-secondary: #4b5563;
  --muted: #6b7280;
  --border: #d9e2ec;
  --border-strong: #c7d2df;
  --accent: #0f52ba;
  --accent-hover: #174fa5;
  --accent-soft: #e8f0fb;
  --gold: #a9853f;
  --gold-hover: #957438;
  --gold-soft: #f6f0e3;
  --success: #2f855a;
  --warning: #b7791f;
  --danger: #c53030;
  --sidebar: rgb(238 243 248 / 88%);
  --sidebar-text: #253247;
  --shadow: 0 4px 16px rgb(17 24 39 / 7%);
  --shadow-raised: 0 16px 40px rgb(17 24 39 / 14%);

  /* Foundation aliases — preferred for new shared UI. */
  --color-bg-primary: var(--bg);
  --color-bg-secondary: var(--sidebar);
  --color-surface-primary: var(--surface-solid);
  --color-surface-elevated: var(--surface-2);
  --color-surface-selected: var(--accent-soft);
  --color-text-primary: var(--text);
  --color-text-secondary: var(--text-secondary);
  --color-text-muted: var(--muted);
  --color-border-default: var(--border);
  --color-border-strong: var(--border-strong);
  --color-action-primary: var(--accent);
  --color-action-primary-hover: var(--accent-hover);
  --color-action-soft: var(--accent-soft);
  --color-status-success: var(--success);
  --color-status-warning: var(--warning);
  --color-status-danger: var(--danger);
  --color-value-gold: var(--gold);

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-pill: 999px;

  /* Controls */
  --control-compact: 36px;
  --control-default: 40px;
  --control-touch: 44px;

  /* Icon sizes */
  --icon-xs: 14px;
  --icon-sm: 16px;
  --icon-md: 20px;
  --icon-lg: 24px;

  /* Motion */
  --motion-fast: 120ms;
  --motion-default: 160ms;
  --motion-slow: 220ms;
  --ease-ui: ease-out;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  /* Midnight / Deep Navy foundation */
  --bg: #050914;
  --surface: rgb(12 20 36 / 90%);
  --surface-solid: #0c1424;
  --surface-2: #111c2e;
  --surface-3: #17243a;
  --text: #f2f5fa;
  --text-secondary: #a8b3c5;
  --muted: #6f7e94;
  --border: #1e2c42;
  --border-strong: #2b3c55;

  /* Sapphire is slightly lifted in dark mode for readability. */
  --accent: #2f6fdb;
  --accent-hover: #3c7be5;
  --accent-soft: #132a50;

  /* Gold is value/premium only, never the default CTA or warning. */
  --gold: #c9a85c;
  --gold-hover: #d5b76d;
  --gold-soft: #2b2519;

  /* Muted semantic status palette */
  --success: #4faf83;
  --warning: #d89a4a;
  --danger: #d95c65;

  --sidebar: rgb(8 14 28 / 94%);
  --sidebar-text: #e8edf5;
  --shadow: 0 4px 16px rgb(0 0 0 / 14%);
  --shadow-raised: 0 16px 40px rgb(0 0 0 / 28%);
}

/* Secondary copy receives a semantic value without changing existing .muted. */
.text-secondary {
  color: var(--text-secondary);
}

/* Rare value accent. Do not use for ordinary buttons or warnings. */
.value-gold {
  color: var(--gold);
}

.value-gold-surface {
  border-color: color-mix(in srgb, var(--gold) 28%, var(--border));
  background: color-mix(in srgb, var(--gold-soft) 72%, var(--surface-solid));
}

/* Brand-consistent text selection. */
::selection {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
}

/* Keyboard focus must remain visible on real interactive controls. */
:where(button, a, input, textarea, select, summary, [tabindex]:not([tabindex="-1"])):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* #content uses tabindex=-1 only as a programmatic focus target after navigation.
   A full-page focus outline looks like a broken layout border and is not useful. */
#content:focus,
#content:focus-visible {
  outline: none;
}

/* Keep transitions calm and predictable for common interactive surfaces. */
:where(.button, .icon-button, .nav-item, .segmented button, .avatar) {
  transition-duration: var(--motion-default);
  transition-timing-function: var(--ease-ui);
}

/* Prevent brand marks from carrying the old Apple-blue shadow tint. */
.brand-mark {
  box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 24%, transparent);
}

/* Primary button shadow follows the active brand accent. */
.button.primary {
  box-shadow: 0 3px 10px color-mix(in srgb, var(--accent) 20%, transparent);
}

/* Dark surfaces get depth from surface hierarchy, not bright borders. */
:root[data-theme="dark"] .card {
  box-shadow: 0 1px 2px rgb(0 0 0 / 14%);
}

:root[data-theme="dark"] .topbar {
  background: color-mix(in srgb, var(--bg) 86%, transparent);
}

/* Semantic icon system. */
.app-icon {
  display: block;
  flex: 0 0 auto;
  color: currentColor;
  pointer-events: none;
  shape-rendering: geometricPrecision;
}

.app-icon-slot {
  display: inline-grid;
  place-items: center;
  line-height: 0;
}

.nav-icon {
  width: var(--icon-md);
  height: var(--icon-md);
  display: grid;
  place-items: center;
  flex: 0 0 var(--icon-md);
  font-size: 0;
}

.nav-item .app-icon {
  opacity: .88;
  transition: opacity var(--motion-default) var(--ease-ui), transform var(--motion-default) var(--ease-ui);
}

.nav-item:hover .app-icon,
.nav-item.active .app-icon {
  opacity: 1;
}

.nav-item.active .app-icon {
  transform: translateX(1px);
}

.icon-button {
  min-width: var(--control-compact);
  width: var(--control-compact);
  height: var(--control-compact);
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.icon-button .app-icon {
  color: currentColor;
}

.feedback-close.app-icon-slot {
  width: 32px;
  height: 32px;
  padding: 0;
}

/* Sidebar utilities must fit the fixed-width rail without pushing Logout outside
   the content box. Keep the three utility actions equal and let Logout use the
   remaining width. */
.sidebar-footer {
  gap: 6px;
  padding-inline: 0;
}

.sidebar-footer > :is(.feedback-trigger, .icon-button) {
  width: 34px;
  min-width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--surface-solid) 86%, transparent);
}

.sidebar-footer > .button {
  min-width: 0;
  min-height: 34px;
  padding-inline: 9px;
  white-space: nowrap;
}

.app.sidebar-collapsed .sidebar-footer > :is(.feedback-trigger, .icon-button) {
  flex-basis: 34px;
}

/* Task dashboard: keep the count in the card header instead of consuming a
   separate row. This matches the compact dashboard hierarchy. */
.task-dashboard-grid-v2 .task-view-card {
  position: relative;
}

.task-dashboard-grid-v2 .task-view-count {
  position: absolute;
  top: 17px;
  right: 15px;
  z-index: 2;
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 0;
  white-space: nowrap;
}

.task-dashboard-grid-v2 .task-view-card:not(.task-view-card-1) .task-view-count {
  right: 58px;
}

.task-dashboard-grid-v2 .task-view-card-1 .task-view-header > div:first-child {
  max-width: calc(100% - 96px);
}

.task-dashboard-grid-v2 .task-view-card:not(.task-view-card-1) .task-view-header > div:first-child {
  max-width: calc(100% - 138px);
}

.task-dashboard-grid-v2 .task-view-header > div:first-child {
  min-width: 0;
}

.task-dashboard-grid-v2 .task-view-header p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Shared component geometry: gradual migration without changing product logic. */
.button,
input,
textarea,
select {
  border-radius: var(--radius-sm);
}

.card {
  border-radius: var(--radius-md);
}

@media (max-width: 720px) {
  .task-dashboard-grid-v2 .task-view-count {
    top: 18px;
    font-size: 10px;
  }

  .task-dashboard-grid-v2 .task-view-count strong {
    font-size: 18px;
  }

  .task-dashboard-grid-v2 .task-view-card-1 .task-view-header > div:first-child {
    max-width: calc(100% - 82px);
  }

  .task-dashboard-grid-v2 .task-view-card:not(.task-view-card-1) .task-view-header > div:first-child {
    max-width: calc(100% - 124px);
  }
}

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