/**
 * UI Utility Styles
 * @countermeasure/web-components
 *
 * TODO(phase-1): Hex literals here are direct values for --cmm-* custom
 * property definitions. A future pass should derive these from the canonical
 * tokens in tokens.css (e.g. --cmm-bg-primary → hsl(var(--background))).
 */

/* Theme Variables - Dark (default) */
:root {
  --cmm-bg-primary: #0f172a;
  --cmm-bg-secondary: #1e293b;
  --cmm-bg-tertiary: #334155;
  --cmm-text-primary: #ffffff;
  --cmm-text-secondary: #e2e8f0;
  --cmm-text-muted: #94a3b8;
  --cmm-border: #334155;
  --cmm-accent: #2563eb;
  --cmm-accent-hover: #3b82f6;
  --cmm-success: #22c55e;
  --cmm-warning: #f59e0b;
  --cmm-error: #ef4444;
  --cmm-info: #3b82f6;
}

/* Theme Variables - Light */
[data-theme="light"] {
  --cmm-bg-primary: #ffffff;
  --cmm-bg-secondary: #f8fafc;
  --cmm-bg-tertiary: #f1f5f9;
  --cmm-text-primary: #0f172a;
  --cmm-text-secondary: #334155;
  --cmm-text-muted: #64748b;
  --cmm-border: #e2e8f0;
  --cmm-accent: #2563eb;
  --cmm-accent-hover: #1d4ed8;
  --cmm-success: #16a34a;
  --cmm-warning: #d97706;
  --cmm-error: #dc2626;
  --cmm-info: #2563eb;
}

/* Theme Variables - Monokai */
[data-theme="monokai"] {
  --cmm-bg-primary: #272822;
  --cmm-bg-secondary: #31322c;
  --cmm-bg-tertiary: #3a3b34;
  --cmm-text-primary: #f8f8f2;
  --cmm-text-secondary: #c7c7bd;
  --cmm-text-muted: #75715e;
  --cmm-border: rgba(248, 248, 242, 0.12);
  --cmm-accent: #a6e22e;
  --cmm-accent-hover: #b8f340;
  --cmm-success: #a6e22e;
  --cmm-warning: #fd971f;
  --cmm-error: #f92672;
  --cmm-info: #66d9ef;
}

/* Theme Variables - Glass */
[data-theme="glass"] {
  --cmm-bg-primary: #0a0a10;
  --cmm-bg-secondary: rgba(255, 255, 255, 0.035);
  --cmm-bg-tertiary: rgba(255, 255, 255, 0.07);
  --cmm-text-primary: #e8e8f0;
  --cmm-text-secondary: #b0b0c0;
  --cmm-text-muted: #5c5c70;
  --cmm-border: rgba(255, 255, 255, 0.08);
  --cmm-accent: #fb923c;
  --cmm-accent-hover: #f97316;
  --cmm-success: #34d399;
  --cmm-warning: #fbbf24;
  --cmm-error: #fb7185;
  --cmm-info: #f97316;
}

/* Auto-dismiss Alerts */
.cmm-alert {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10001;
  max-width: 24rem;
  padding: 1rem;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  transform: translateX(0);
  opacity: 1;
  transition:
    transform 0.3s ease-out,
    opacity 0.3s ease-out;
}

.cmm-alert--hidden {
  transform: translateX(100%);
  opacity: 0;
}

.cmm-alert--success {
  background: var(--cmm-success);
  color: white;
}

.cmm-alert--error {
  background: var(--cmm-error);
  color: white;
}

.cmm-alert--warning {
  background: var(--cmm-warning);
  color: white;
}

.cmm-alert--info {
  background: var(--cmm-info);
  color: white;
}

.cmm-alert__icon {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
}

.cmm-alert__content {
  flex: 1;
}

.cmm-alert__title {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.cmm-alert__message {
  font-size: 0.875rem;
  opacity: 0.9;
}

.cmm-alert__close {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: currentColor;
  cursor: pointer;
  padding: 0.25rem;
  opacity: 0.7;
}

.cmm-alert__close:hover {
  opacity: 1;
}

/* Loading Spinner */
.cmm-spinner {
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: cmm-spin 0.75s linear infinite;
}

.cmm-spinner--sm {
  width: 1rem;
  height: 1rem;
}

.cmm-spinner--lg {
  width: 2rem;
  height: 2rem;
}

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

/* Loading Overlay */
.cmm-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.cmm-loading-overlay__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  color: white;
}

.cmm-loading-overlay__text {
  font-size: 0.875rem;
}

/* Toast Container */
.cmm-toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 10001;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
  max-width: 24rem;
}

.cmm-toast {
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  animation: cmm-toast-in 0.3s ease-out;
}

.cmm-toast--exiting {
  animation: cmm-toast-out 0.3s ease-out forwards;
}

@keyframes cmm-toast-in {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes cmm-toast-out {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* Dropdown */
.cmm-dropdown {
  position: relative;
  display: inline-block;
}

.cmm-dropdown__menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5rem;
  background: var(--cmm-bg-secondary);
  border: 1px solid var(--cmm-border);
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  min-width: 12rem;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-0.5rem);
  transition:
    opacity 0.2s,
    transform 0.2s,
    visibility 0.2s;
}

.cmm-dropdown--open .cmm-dropdown__menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.cmm-dropdown__item {
  display: block;
  width: 100%;
  padding: 0.5rem 1rem;
  text-align: left;
  font-size: 0.875rem;
  color: var(--cmm-text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s;
}

.cmm-dropdown__item:hover {
  background: var(--cmm-bg-tertiary);
}

.cmm-dropdown__item:first-child {
  border-radius: 0.5rem 0.5rem 0 0;
}

.cmm-dropdown__item:last-child {
  border-radius: 0 0 0.5rem 0.5rem;
}

.cmm-dropdown__divider {
  height: 1px;
  background: var(--cmm-border);
  margin: 0.25rem 0;
}

/* Modal Base */
.cmm-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.cmm-modal--open {
  display: flex;
}

.cmm-modal__dialog {
  background: var(--cmm-bg-primary);
  border: 1px solid var(--cmm-border);
  border-radius: 0.75rem;
  box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
  max-width: 32rem;
  width: calc(100% - 2rem);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: cmm-modal-in 0.2s ease-out;
}

@keyframes cmm-modal-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.cmm-modal__header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--cmm-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cmm-modal__title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--cmm-text-primary);
}

.cmm-modal__close {
  background: transparent;
  border: none;
  color: var(--cmm-text-muted);
  cursor: pointer;
  padding: 0.25rem;
  transition: color 0.2s;
}

.cmm-modal__close:hover {
  color: var(--cmm-text-primary);
}

.cmm-modal__body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
  color: var(--cmm-text-secondary);
}

.cmm-modal__footer {
  padding: 1.5rem;
  border-top: 1px solid var(--cmm-border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Utility Classes */
.cmm-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;
}

.cmm-hidden {
  display: none !important;
}

.cmm-flex {
  display: flex;
}

.cmm-items-center {
  align-items: center;
}

.cmm-justify-between {
  justify-content: space-between;
}

.cmm-gap-2 {
  gap: 0.5rem;
}

.cmm-gap-4 {
  gap: 1rem;
}

.cmm-mt-4 {
  margin-top: 1rem;
}

.cmm-mb-4 {
  margin-bottom: 1rem;
}
