/* M3 component primitives — source of truth for Phases B/C/D. */

.m3-icon { display: inline-flex; width: 24px; height: 24px; flex-shrink: 0; }
.m3-icon > svg { width: 100%; height: 100%; display: block; }
.m3-icon--sm { width: 20px; height: 20px; }
.m3-icon--lg { width: 32px; height: 32px; }

.m3-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  min-width: 48px;
  padding: 0 24px;
  border-radius: var(--md-sys-shape-corner-full);
  border: 0;
  cursor: pointer;
  font-family: var(--md-sys-typescale-font-family, inherit);
  font-size: var(--md-sys-typescale-label-large-size);
  line-height: var(--md-sys-typescale-label-large-line);
  font-weight: var(--md-sys-typescale-label-large-weight);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  position: relative;
  isolation: isolate;
  transition: box-shadow var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.m3-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
@media (hover: hover) {
  .m3-btn:hover::after { opacity: var(--md-sys-state-hover-opacity); }
}
.m3-btn:active::after { opacity: var(--md-sys-state-pressed-opacity); }
.m3-btn:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: 2px; }
.m3-btn:disabled { opacity: 0.38; cursor: not-allowed; pointer-events: none; }
.m3-btn .m3-icon { width: 18px; height: 18px; font-size: 18px; }

.m3-btn--filled { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
@media (hover: hover) { .m3-btn--filled:hover { box-shadow: var(--md-sys-elevation-1); } }
.m3-btn--tonal { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.m3-btn--outlined { background: transparent; color: var(--md-sys-color-primary); border: 1px solid var(--md-sys-color-outline); }
.m3-btn--text { background: transparent; color: var(--md-sys-color-primary); padding: 0 12px; }
.m3-btn--elevated { background: var(--md-sys-color-surface-container-low); color: var(--md-sys-color-primary); box-shadow: var(--md-sys-elevation-1); }
@media (hover: hover) { .m3-btn--elevated:hover { box-shadow: var(--md-sys-elevation-2); } }
.m3-btn--error { background: var(--md-sys-color-error); color: var(--md-sys-color-on-error); }

@media (pointer: coarse) {
  .m3-btn { min-height: 48px; }
}

.m3-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--md-sys-shape-corner-full);
  border: 0;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  position: relative;
  isolation: isolate;
  transition: color var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  -webkit-tap-highlight-color: transparent;
}
.m3-icon-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
@media (hover: hover) {
  .m3-icon-btn:hover::after { opacity: var(--md-sys-state-hover-opacity); }
}
.m3-icon-btn:active::after { opacity: var(--md-sys-state-pressed-opacity); }
.m3-icon-btn:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: 2px; }
.m3-icon-btn:disabled { opacity: 0.38; cursor: not-allowed; pointer-events: none; }

.m3-icon-btn > svg,
.m3-icon-btn > .m3-icon { width: 24px; height: 24px; }

.m3-icon-btn--filled { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.m3-icon-btn--tonal { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.m3-icon-btn--outlined { border: 1px solid var(--md-sys-color-outline); color: var(--md-sys-color-on-surface); }

.m3-icon-btn--sm { width: 32px; height: 32px; }
.m3-icon-btn--sm > svg,
.m3-icon-btn--sm > .m3-icon { width: 20px; height: 20px; }
.m3-icon-btn--lg { width: 56px; height: 56px; }

@media (pointer: coarse) {
  .m3-icon-btn { width: 48px; height: 48px; }
  .m3-icon-btn--sm { width: 40px; height: 40px; }
}

.m3-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 16px;
  border-radius: var(--md-sys-shape-corner-sm);
  border: 1px solid var(--md-sys-color-outline);
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  font-family: var(--md-sys-typescale-font-family, inherit);
  font-size: var(--md-sys-typescale-label-large-size);
  line-height: var(--md-sys-typescale-label-large-line);
  font-weight: var(--md-sys-typescale-label-large-weight);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  position: relative;
  isolation: isolate;
  transition: background var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  -webkit-tap-highlight-color: transparent;
}
.m3-chip::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
@media (hover: hover) {
  .m3-chip:hover::after { opacity: var(--md-sys-state-hover-opacity); }
}
.m3-chip:active::after { opacity: var(--md-sys-state-pressed-opacity); }
.m3-chip:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: 2px; }
.m3-chip:has(> .m3-icon:first-child),
.m3-chip:has(> svg:first-child) { padding: 0 16px 0 8px; }
.m3-chip .m3-icon { width: 18px; height: 18px; }

.m3-chip--assist { border-color: var(--md-sys-color-outline); }
.m3-chip--suggestion { border-color: var(--md-sys-color-outline); }
.m3-chip--filter.m3-chip--selected,
.m3-chip--selected {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border-color: transparent;
}
.m3-chip--input {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  border-color: transparent;
  padding-right: 8px;
}

.m3-chip__close {
  width: 18px;
  height: 18px;
  border-radius: var(--md-sys-shape-corner-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 2px;
  cursor: pointer;
  background: transparent;
  border: 0;
  color: inherit;
}
.m3-chip__close > .m3-icon,
.m3-chip__close > svg { width: 14px; height: 14px; }

@media (pointer: coarse) {
  .m3-chip { min-height: 40px; height: auto; padding-top: 4px; padding-bottom: 4px; }
}

.m3-fab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 56px;
  height: 56px;
  border-radius: var(--md-sys-shape-corner-lg);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border: 0;
  cursor: pointer;
  box-shadow: var(--md-sys-elevation-3);
  position: relative;
  isolation: isolate;
  transition: box-shadow var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  -webkit-tap-highlight-color: transparent;
}
.m3-fab::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
@media (hover: hover) {
  .m3-fab:hover { box-shadow: var(--md-sys-elevation-4); }
  .m3-fab:hover::after { opacity: var(--md-sys-state-hover-opacity); }
}
.m3-fab:active::after { opacity: var(--md-sys-state-pressed-opacity); }
.m3-fab:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: 2px; }
.m3-fab > svg,
.m3-fab > .m3-icon { width: 24px; height: 24px; }

.m3-fab--small {
  width: 40px;
  height: 40px;
  border-radius: var(--md-sys-shape-corner-md);
}
.m3-fab--small > svg,
.m3-fab--small > .m3-icon { width: 20px; height: 20px; }

.m3-fab--large {
  width: 96px;
  height: 96px;
  border-radius: var(--md-sys-shape-corner-xl);
}
.m3-fab--large > svg,
.m3-fab--large > .m3-icon { width: 32px; height: 32px; }

.m3-fab--extended {
  width: auto;
  height: 56px;
  padding: 0 20px;
  border-radius: var(--md-sys-shape-corner-lg);
  gap: 12px;
  font-family: inherit;
  font-size: var(--md-sys-typescale-label-large-size);
  line-height: var(--md-sys-typescale-label-large-line);
  font-weight: var(--md-sys-typescale-label-large-weight);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
}

.m3-tf {
  position: relative;
  height: 56px;
  display: flex;
  align-items: flex-end;
}
.m3-tf input,
.m3-tf textarea {
  background: transparent;
  border: 0;
  outline: none;
  color: var(--md-sys-color-on-surface);
  font: inherit;
  font-size: 16px;
  width: 100%;
}
.m3-tf input::placeholder,
.m3-tf textarea::placeholder { color: var(--md-sys-color-on-surface-variant); }

.m3-tf--filled {
  background: var(--md-sys-color-surface-container-highest);
  border-radius: var(--md-sys-shape-corner-xs) var(--md-sys-shape-corner-xs) 0 0;
  padding: 18px 16px 4px;
}
.m3-tf--filled::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--md-sys-color-on-surface-variant);
  transition: height var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard),
              background var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
.m3-tf--filled:focus-within::after {
  height: 2px;
  background: var(--md-sys-color-primary);
}
.m3-tf--filled .m3-tf__label {
  position: absolute;
  left: 16px;
  top: 8px;
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  pointer-events: none;
  transition: color var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
.m3-tf--filled:focus-within .m3-tf__label { color: var(--md-sys-color-primary); }

.m3-tf--outlined {
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-xs);
  background: transparent;
  padding: 14px 16px;
  align-items: center;
  transition: border-color var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard),
              border-width var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
.m3-tf--outlined:focus-within {
  border: 2px solid var(--md-sys-color-primary);
  padding: 13px 15px;
}

.m3-card {
  padding: 16px;
  border-radius: var(--md-sys-shape-corner-md);
  position: relative;
  isolation: isolate;
}
.m3-card--filled { background: var(--md-sys-color-surface-container-high); }
.m3-card--outlined { background: transparent; border: 1px solid var(--md-sys-color-outline-variant); }
.m3-card--elevated { background: var(--md-sys-color-surface-container-low); box-shadow: var(--md-sys-elevation-1); }

.m3-card--clickable { cursor: pointer; -webkit-tap-highlight-color: transparent; transition: box-shadow var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard); }
.m3-card--clickable::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
@media (hover: hover) {
  .m3-card--clickable:hover::after { opacity: var(--md-sys-state-hover-opacity); }
  .m3-card--elevated.m3-card--clickable:hover { box-shadow: var(--md-sys-elevation-2); }
}
.m3-card--clickable:active::after { opacity: var(--md-sys-state-pressed-opacity); }
.m3-card--clickable:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: 2px; }

.m3-list-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  min-height: 56px;
  cursor: pointer;
  border-radius: var(--md-sys-shape-corner-xl);
  position: relative;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
}
.m3-list-item::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
@media (hover: hover) {
  .m3-list-item:hover::after { opacity: var(--md-sys-state-hover-opacity); }
}
.m3-list-item:active::after { opacity: var(--md-sys-state-pressed-opacity); }
.m3-list-item:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: 2px; }
.m3-list-item--selected {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.m3-list-item__leading {
  width: 40px;
  height: 40px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}
.m3-list-item--selected .m3-list-item__leading {
  background: rgba(255, 255, 255, 0.18);
  color: var(--md-sys-color-on-secondary-container);
}
.m3-list-item__body { flex: 1; min-width: 0; }
.m3-list-item__headline {
  font-size: var(--md-sys-typescale-body-large-size);
  line-height: var(--md-sys-typescale-body-large-line);
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.m3-list-item--selected .m3-list-item__headline { color: var(--md-sys-color-on-secondary-container); font-weight: 600; }
.m3-list-item__support {
  font-size: var(--md-sys-typescale-body-small-size);
  line-height: var(--md-sys-typescale-body-small-line);
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.m3-list-item--selected .m3-list-item__support { color: rgba(219, 234, 254, 0.7); }
.m3-list-item__trailing {
  color: var(--md-sys-color-on-surface-variant);
  flex-shrink: 0;
}
.m3-list-item--selected .m3-list-item__trailing { color: var(--md-sys-color-on-secondary-container); }

.m3-list-subhead {
  padding: 12px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
}

.m3-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 64px;
  padding: 0 20px;
  background: var(--md-sys-color-surface-container-low);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.m3-topbar__title {
  font-size: var(--md-sys-typescale-title-medium-size);
  line-height: var(--md-sys-typescale-title-medium-line);
  font-weight: 600;
}
.m3-topbar__meta {
  font-size: var(--md-sys-typescale-body-small-size);
  line-height: var(--md-sys-typescale-body-small-line);
  color: var(--md-sys-color-on-surface-variant);
}
.m3-topbar__actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
  align-items: center;
}
@media (max-width: 600px) {
  .m3-topbar { height: 56px; padding: 0 12px; }
}

.m3-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--md-sys-shape-corner-full);
  color: #FFFFFF;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}
.m3-avatar--sm { width: 32px; height: 32px; font-size: 12px; }
.m3-avatar--lg { width: 56px; height: 56px; font-size: 18px; }
.m3-avatar-ring {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  border-radius: var(--md-sys-shape-corner-full);
}

@keyframes m3StatusPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

.m3-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 11px;
  font-weight: 600;
}
.m3-status-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: var(--md-sys-shape-corner-full);
  flex-shrink: 0;
}
.m3-status-pill--working { background: rgba(245, 158, 11, 0.14); color: #FBBF24; }
.m3-status-pill--working::before { background: #FBBF24; animation: m3StatusPulse 1.4s ease-in-out infinite; }
.m3-status-pill--done { background: rgba(16, 185, 129, 0.14); color: #34D399; }
.m3-status-pill--done::before { background: #34D399; }
.m3-status-pill--snoozed { background: rgba(99, 102, 241, 0.14); color: #A5B4FC; }
.m3-status-pill--snoozed::before { background: #A5B4FC; }
.m3-status-pill--error { background: rgba(239, 68, 68, 0.14); color: var(--md-sys-color-error); }
.m3-status-pill--error::before { background: var(--md-sys-color-error); }

.m3-bottom-sheet {
  background: var(--md-sys-color-surface-container-high);
  border-top-left-radius: var(--md-sys-shape-corner-xl);
  border-top-right-radius: var(--md-sys-shape-corner-xl);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
}
.m3-bottom-sheet__handle {
  width: 32px;
  height: 4px;
  border-radius: 2px;
  background: var(--md-sys-color-outline);
  margin: 12px auto 4px;
}
.m3-bottom-sheet__head { padding: 8px 16px 12px; }
.m3-bottom-sheet__body { flex: 1; overflow-y: auto; padding: 4px 16px 8px; }
.m3-bottom-sheet__foot { padding: 12px 16px 16px; display: flex; gap: 8px; }

.m3-nav-rail-item {
  width: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 0;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  background: transparent;
  border: 0;
  position: relative;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
}
.m3-nav-rail-item__target {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--md-sys-shape-corner-full);
  position: relative;
  isolation: isolate;
  transition: width var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-emphasized-decel),
              background var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
.m3-nav-rail-item__target::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
@media (hover: hover) {
  .m3-nav-rail-item:hover .m3-nav-rail-item__target::after { opacity: var(--md-sys-state-hover-opacity); }
}
.m3-nav-rail-item__target > svg,
.m3-nav-rail-item__target > .m3-icon { width: 24px; height: 24px; }
.m3-nav-rail-item__label {
  font-size: var(--md-sys-typescale-label-medium-size);
  line-height: var(--md-sys-typescale-label-medium-line);
  font-weight: 600;
  letter-spacing: var(--md-sys-typescale-label-medium-tracking);
}
.m3-nav-rail-item--selected { color: var(--md-sys-color-on-secondary-container); }
.m3-nav-rail-item--selected .m3-nav-rail-item__target {
  width: 56px;
  background: var(--md-sys-color-secondary-container);
}
.m3-nav-rail-item:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: 2px; border-radius: var(--md-sys-shape-corner-md); }

.m3-nav-bar-item {
  width: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 0;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  background: transparent;
  border: 0;
  position: relative;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
}
.m3-nav-bar-item__target {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--md-sys-shape-corner-full);
  position: relative;
  isolation: isolate;
  transition: width var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-emphasized-decel),
              background var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
.m3-nav-bar-item__target::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: currentColor;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
  transition: opacity var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
}
@media (hover: hover) {
  .m3-nav-bar-item:hover .m3-nav-bar-item__target::after { opacity: var(--md-sys-state-hover-opacity); }
}
.m3-nav-bar-item__target > svg,
.m3-nav-bar-item__target > .m3-icon { width: 24px; height: 24px; }
.m3-nav-bar-item__label {
  font-size: var(--md-sys-typescale-label-medium-size);
  line-height: var(--md-sys-typescale-label-medium-line);
  font-weight: 600;
  letter-spacing: var(--md-sys-typescale-label-medium-tracking);
}
.m3-nav-bar-item--selected { color: var(--md-sys-color-on-secondary-container); }
.m3-nav-bar-item--selected .m3-nav-bar-item__target {
  width: 60px;
  background: var(--md-sys-color-secondary-container);
}
.m3-nav-bar-item:focus-visible { outline: 2px solid var(--md-sys-color-primary); outline-offset: 2px; border-radius: var(--md-sys-shape-corner-md); }
