/* ============================================================
   Material 3 - component styles
   https://m3.material.io/components
   ============================================================ */

/* ---------- Common: state layer ---------- */
.md-state { position: relative; overflow: hidden; isolation: isolate; }
.md-state::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: currentColor; opacity: 0;
  transition: opacity var(--md-sys-motion-duration-short) var(--md-sys-motion-standard);
  pointer-events: none;
}
.md-state:hover::before { opacity: var(--md-sys-state-hover); }
.md-state:focus-visible::before { opacity: var(--md-sys-state-focus); }
.md-state:active::before { opacity: var(--md-sys-state-pressed); }
:where(button, [role="button"], a):focus-visible {
  outline: 3px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* ---------- Buttons ---------- */
.md-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 24px; border: none; cursor: pointer;
  border-radius: var(--md-sys-shape-corner-full);
  font: 500 14px/20px var(--md-sys-typescale-plain-font); letter-spacing: 0.1px;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-standard);
  white-space: nowrap; user-select: none;
}
.md-button.has-icon { padding-inline: 16px 24px; }
.md-button svg { width: 18px; height: 18px; fill: currentColor; flex: none; }

.md-button--filled { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.md-button--tonal { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.md-button--outlined {
  background: transparent; color: var(--md-sys-color-primary);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-outline-variant);
}
.md-button--text { background: transparent; color: var(--md-sys-color-primary); padding: 0 12px; }
.md-button--danger { background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }
.md-button:disabled {
  cursor: default;
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
  box-shadow: none;
}
.md-button--text:disabled, .md-button--outlined:disabled { background: transparent; }

/* ---------- Icon button ---------- */
.md-icon-button {
  display: inline-grid; place-items: center; flex: none;
  width: 40px; height: 40px; padding: 0; border: none; cursor: pointer;
  border-radius: var(--md-sys-shape-corner-full);
  background: transparent; color: var(--md-sys-color-on-surface-variant);
}
.md-icon-button svg { width: 24px; height: 24px; fill: currentColor; }
.md-icon-button--small { width: 32px; height: 32px; }
.md-icon-button--small svg { width: 20px; height: 20px; }
.md-icon-button--filled { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.md-icon-button--tonal { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.md-icon-button[aria-pressed="true"] { color: var(--md-sys-color-primary); background: var(--md-sys-color-primary-container); }
.md-icon-button:disabled { color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent); cursor: default; }

/* ---------- FAB ---------- */
.md-fab {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  height: 56px; min-width: 56px; padding: 0 20px; border: none; cursor: pointer;
  border-radius: var(--md-sys-shape-corner-l);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font: 500 14px/20px var(--md-sys-typescale-plain-font); letter-spacing: 0.1px;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-standard);
}
.md-fab svg { width: 24px; height: 24px; fill: currentColor; }

/* ---------- Card ---------- */
.md-card {
  border-radius: var(--md-sys-shape-corner-m);
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
}
.md-card--outlined { box-shadow: inset 0 0 0 1px var(--md-sys-color-outline-variant); }
.md-card--elevated { background: var(--md-sys-color-surface-container); }

/* ---------- Top app bar ---------- */
.md-top-app-bar {
  display: flex; align-items: center; gap: 8px;
  height: 64px; padding: 0 12px 0 16px;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.md-top-app-bar .title { flex: 1 1 auto; display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.md-top-app-bar .title h1 { margin: 0; font: 400 22px/28px var(--md-sys-typescale-brand-font); }
.md-top-app-bar .title span { color: var(--md-sys-color-on-surface-variant); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Slider ---------- */
.md-slider { display: block; }
.md-slider .row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin-bottom: 2px;
}
.md-slider .row label {
  font: 500 12px/16px var(--md-sys-typescale-plain-font); letter-spacing: 0.5px;
  color: var(--md-sys-color-on-surface-variant);
}
.md-slider .row output {
  font: 500 12px/16px var(--md-sys-typescale-plain-font);
  color: var(--md-sys-color-on-surface);
  font-variant-numeric: tabular-nums;
  background: var(--md-sys-color-surface-container-highest);
  border-radius: var(--md-sys-shape-corner-xs);
  padding: 1px 6px;
}
input[type="range"].md-slider-input {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 20px; margin: 0; background: transparent; cursor: pointer;
  --fill: 50%;
}
input[type="range"].md-slider-input::-webkit-slider-runnable-track {
  height: 16px; border-radius: var(--md-sys-shape-corner-full);
  background:
    linear-gradient(to right,
      var(--md-sys-color-primary) 0 calc(var(--fill) - 6px),
      transparent calc(var(--fill) - 6px) calc(var(--fill) + 6px),
      var(--md-sys-color-secondary-container) calc(var(--fill) + 6px) 100%);
}
input[type="range"].md-slider-input::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 4px; height: 26px; margin-top: -5px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-primary);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--md-sys-color-primary) 12%, transparent);
  transition: box-shadow var(--md-sys-motion-duration-short) var(--md-sys-motion-standard);
}
input[type="range"].md-slider-input:hover::-webkit-slider-thumb {
  box-shadow: 0 0 0 8px color-mix(in srgb, var(--md-sys-color-primary) 12%, transparent);
}
input[type="range"].md-slider-input::-moz-range-track {
  height: 16px; border-radius: 999px; background: var(--md-sys-color-secondary-container);
}
input[type="range"].md-slider-input::-moz-range-progress {
  height: 16px; border-radius: 999px; background: var(--md-sys-color-primary);
}
input[type="range"].md-slider-input::-moz-range-thumb {
  width: 4px; height: 26px; border: none;
  border-radius: 999px; background: var(--md-sys-color-primary);
}

/* ---------- Switch ---------- */
.md-switch { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 40px; }
.md-switch > span {
  font: 400 14px/20px var(--md-sys-typescale-plain-font);
  color: var(--md-sys-color-on-surface);
}
.md-switch input { position: absolute; opacity: 0; pointer-events: none; }
.md-switch .track {
  position: relative; flex: none; width: 52px; height: 32px; border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-highest);
  box-shadow: inset 0 0 0 2px var(--md-sys-color-outline);
  cursor: pointer;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-standard),
              box-shadow var(--md-sys-motion-duration-short) var(--md-sys-motion-standard);
}
.md-switch .track::after {
  content: ""; position: absolute; top: 50%; left: 8px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--md-sys-color-outline);
  transform: translate(0, -50%);
  transition: all var(--md-sys-motion-duration-medium) var(--md-sys-motion-emphasized);
}
.md-switch input:checked + .track { background: var(--md-sys-color-primary); box-shadow: inset 0 0 0 2px var(--md-sys-color-primary); }
.md-switch input:checked + .track::after {
  left: 24px; width: 24px; height: 24px;
  background: var(--md-sys-color-on-primary);
}
.md-switch input:focus-visible + .track { outline: 3px solid var(--md-sys-color-primary); outline-offset: 2px; }

/* ---------- Segmented button ---------- */
.md-segmented {
  display: flex; border-radius: var(--md-sys-shape-corner-full); overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--md-sys-color-outline);
}
.md-segmented button {
  flex: 1 1 0; min-width: 0; height: 40px; padding: 0 10px; border: none; cursor: pointer;
  background: transparent; color: var(--md-sys-color-on-surface);
  font: 500 13px/20px var(--md-sys-typescale-plain-font); letter-spacing: 0.1px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-right: 1px solid var(--md-sys-color-outline);
}
.md-segmented button:last-child { border-right: none; }
.md-segmented button[aria-pressed="true"] {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.md-segmented button svg { width: 18px; height: 18px; fill: currentColor; }

/* ---------- Chips ---------- */
.md-chip-set { display: flex; flex-wrap: wrap; gap: 8px; }
.md-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px; cursor: pointer; border: none;
  border-radius: var(--md-sys-shape-corner-s);
  box-shadow: inset 0 0 0 1px var(--md-sys-color-outline);
  background: transparent; color: var(--md-sys-color-on-surface-variant);
  font: 500 14px/20px var(--md-sys-typescale-plain-font); letter-spacing: 0.1px;
}
.md-chip svg { width: 18px; height: 18px; fill: currentColor; }
.md-chip[aria-pressed="true"] {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  box-shadow: none;
}

/* ---------- List ---------- */
.md-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.md-list-item {
  display: flex; align-items: center; gap: 12px;
  min-height: 64px; padding: 8px 12px; cursor: pointer;
  border-radius: var(--md-sys-shape-corner-m);
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-low);
}
.md-list-item[aria-selected="true"] {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.md-list-item .headline { font: 500 14px/20px var(--md-sys-typescale-plain-font); }
.md-list-item .supporting {
  font: 400 12px/16px var(--md-sys-typescale-plain-font);
  color: var(--md-sys-color-on-surface-variant);
}
.md-list-item[aria-selected="true"] .supporting { color: var(--md-sys-color-on-secondary-container); opacity: 0.8; }

/* ---------- Divider ---------- */
.md-divider { height: 1px; border: 0; margin: 8px 0; background: var(--md-sys-color-outline-variant); }

/* ---------- Dialog ---------- */
.md-dialog {
  border: none; padding: 0; max-width: min(560px, calc(100vw - 48px));
  border-radius: var(--md-sys-shape-corner-xl);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--app-hairline);
}
.md-dialog::backdrop { background: color-mix(in srgb, black 32%, transparent); }
.md-dialog .content { padding: 24px; }
.md-dialog h2 { margin: 0 0 16px; font: 400 24px/32px var(--md-sys-typescale-brand-font); }
.md-dialog .actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 24px 24px; }

/* ---------- Snackbar ---------- */
.md-snackbar {
  position: fixed; left: 24px; bottom: 24px; transform: translateY(200%);
  display: flex; align-items: center; gap: 8px;
  min-height: 48px; padding: 8px 8px 8px 16px; z-index: 60;
  border-radius: var(--md-sys-shape-corner-xs);
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  font: 400 14px/20px var(--md-sys-typescale-plain-font);
  transition: transform var(--md-sys-motion-duration-long) var(--md-sys-motion-emphasized-decel);
}
.md-snackbar[data-open="true"] { transform: translateY(0); }
.md-snackbar button { color: var(--md-sys-color-inverse-primary); }

/* ---------- Tooltip (plain) ---------- */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip); position: absolute; top: calc(100% + 6px); left: 50%;
  transform: translateX(-50%) scale(0.9); transform-origin: top center;
  padding: 4px 8px; border-radius: var(--md-sys-shape-corner-xs);
  background: var(--md-sys-color-inverse-surface); color: var(--md-sys-color-inverse-on-surface);
  font: 500 11px/16px var(--md-sys-typescale-plain-font); white-space: nowrap;
  opacity: 0; pointer-events: none; z-index: 40;
  transition: opacity var(--md-sys-motion-duration-short) var(--md-sys-motion-standard),
              transform var(--md-sys-motion-duration-short) var(--md-sys-motion-standard);
}
[data-tooltip]:hover::after { opacity: 1; transform: translateX(-50%) scale(1); }
