/* Material Design 3 Components + Restrained Anime Studio Accents */

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* M3 Cards & Tonal Sheets */
.m3-card {
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-md);
  box-shadow: var(--md-sys-elevation-1);
}

.m3-card-tonal {
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-md);
}

/* M3 Buttons */
.m3-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 20px;
  border-radius: var(--shape-pill);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: background var(--motion-fast), border-color var(--motion-fast), transform var(--motion-fast), opacity var(--motion-fast);
  user-select: none;
  white-space: nowrap;
}

.m3-btn:active:not(:disabled) {
  transform: scale(0.985);
}

.m3-btn:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.m3-btn-filled {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}
.m3-btn-filled:hover:not(:disabled) {
  filter: brightness(0.95);
}

.m3-btn-tonal {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}
.m3-btn-tonal:hover:not(:disabled) {
  filter: brightness(0.96);
}

.m3-btn-secondary {
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  border-color: var(--md-sys-color-outline-variant);
}
.m3-btn-secondary:hover:not(:disabled) {
  background: var(--md-sys-color-surface-container-high);
}

.m3-btn-outlined {
  background: transparent;
  color: var(--md-sys-color-on-surface);
  border-color: var(--md-sys-color-outline);
}
.m3-btn-outlined:hover:not(:disabled) {
  background: var(--md-sys-color-surface-container-low);
}

.m3-btn-text {
  background: transparent;
  color: var(--md-sys-color-primary);
  padding: 0 12px;
  height: 34px;
}
.m3-btn-text:hover:not(:disabled) {
  background: var(--md-sys-color-primary-container);
}

.m3-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--shape-pill);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background var(--motion-fast), color var(--motion-fast);
}
.m3-icon-btn:hover {
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
}

/* M3 Fields */
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}

.m3-input,
.m3-select,
.m3-textarea {
  width: 100%;
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--md-sys-color-on-surface);
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
  outline: none;
}

.m3-input:focus,
.m3-select:focus,
.m3-textarea:focus {
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--md-sys-color-primary) 14%, transparent);
}

.m3-textarea {
  resize: vertical;
  min-height: 112px;
  line-height: 1.55;
}

/* M3 Segmented Button Group */
.m3-segmented {
  display: inline-flex;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-pill);
  padding: 3px;
  gap: 2px;
}

.m3-segmented.full {
  display: flex;
  width: 100%;
}

.m3-seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: var(--shape-pill);
  cursor: pointer;
  transition: background var(--motion-fast), color var(--motion-fast);
  white-space: nowrap;
}

.m3-seg-btn.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

/* M3 Filter & Tag Chips */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.m3-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: var(--shape-xs);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--motion-fast), border-color var(--motion-fast);
}

.m3-chip:hover {
  background: var(--md-sys-color-surface-container-high);
}

.m3-chip.selected {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: transparent;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-family: var(--font-mono);
  line-height: 1.5;
}

.tag-artist {
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}

.tag-style {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.tag-negative {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

.tag-subject {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
}

/* Status Dots & Badges */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: var(--md-sys-color-outline);
}
.status-dot.online { background: var(--md-sys-color-secondary); }
.status-dot.standby { background: var(--md-sys-color-tertiary); }
.status-dot.offline,
.status-dot.error { background: var(--md-sys-color-error); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: var(--shape-pill);
  font-size: 11.5px;
  font-weight: 600;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
}

.badge.primary {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.badge.ok {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

/* M3 Switch */
.m3-switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.m3-switch input {
  appearance: none;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline);
  position: relative;
  cursor: pointer;
  transition: background var(--motion-fast), border-color var(--motion-fast);
  margin: 0;
}

.m3-switch input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--md-sys-color-on-surface-variant);
  transition: transform var(--motion-fast), background var(--motion-fast);
}

.m3-switch input:checked {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}

.m3-switch input:checked::after {
  transform: translateX(20px);
  background: var(--md-sys-color-on-primary);
}

/* Snackbar */
.snackbar-host {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.snackbar {
  background: var(--md-sys-color-on-surface);
  color: var(--md-sys-color-surface);
  padding: 10px 18px;
  border-radius: var(--shape-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--md-sys-elevation-2);
  pointer-events: auto;
  animation: snackIn 180ms ease-out;
}

.snackbar.error {
  background: var(--md-sys-color-error);
  color: #ffffff;
}

@keyframes snackIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Modal / Lightbox */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(23, 20, 18, 0.56);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-panel {
  background: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--shape-lg);
  max-width: 960px;
  width: 100%;
  max-height: 92vh;
  overflow: auto;
  box-shadow: var(--md-sys-elevation-2);
}

.mono {
  font-family: var(--font-mono);
}

.muted {
  color: var(--md-sys-color-on-surface-variant);
}

.small {
  font-size: 12px;
}
