/**
 * DS-12: UI Polish & SaaS Cleanup
 * 
 * Final design polish before BoozeButler v1.0 launch
 * 
 * Tasks:
 * 1. Color Polish: Balance saturation/contrast, proper button states, remove mismatched grays, audit shadows
 * 2. Typography Polish: Apply DS-08 scale everywhere, consistent letter spacing, fix H2/H3 styles
 * 3. Spacing & Rhythm: Standardize vertical spacing (32px/48px), fix margin collapse, improve form line heights
 * 4. Card Polish: Standardize radius, 3-level shadow system, update padding
 * 5. Iconography Polish: Consistent stroke width, remove any remaining emojis
 */

/* ========================================
 * 1. Color Polish
 * ======================================== */

/* Remove mismatched grays - use DS tokens only */
:root {
  /* Ensure all grays use DS tokens */
  --gray-50: var(--color-surface, rgba(255, 255, 255, 0.04));
  --gray-100: var(--color-surface-hover, rgba(255, 255, 255, 0.08));
  --gray-200: var(--border, rgba(196, 126, 66, 0.28));
  --gray-300: var(--text-muted, rgba(255, 255, 255, 0.85));
  --gray-400: var(--text-muted, rgba(255, 255, 255, 0.85));
  --gray-500: var(--text-secondary, rgba(255, 255, 255, 0.92));
  --gray-600: var(--text, rgba(255, 255, 255, 0.98));
  --gray-700: var(--text-primary, rgba(255, 255, 255, 0.98));
  --gray-800: var(--text-primary, rgba(255, 255, 255, 0.98));
  --gray-900: var(--text-primary, rgba(255, 255, 255, 0.98));
}

/* Button state improvements */
.btn {
  transition: all var(--transition-base, 0.2s ease);
  border: 1px solid transparent;
}

.btn--primary {
  background: var(--accent, var(--aperium-copper));
  color: #ffffff;
  box-shadow: var(--shadow-button, 0 4px 12px rgba(0, 0, 0, 0.15));
}

.btn--primary:hover {
  background: var(--accent-dark, var(--aperium-copperHover));
  box-shadow: var(--shadow-button-hover, 0 6px 16px rgba(0, 0, 0, 0.2));
  transform: translateY(-1px);
}

.btn--primary:active {
  transform: translateY(0);
  box-shadow: var(--shadow-button, 0 4px 12px rgba(0, 0, 0, 0.15));
}

.btn--secondary {
  background: var(--color-surface, rgba(255, 255, 255, 0.04));
  color: var(--text, rgba(255, 255, 255, 0.98));
  border-color: var(--border, rgba(196, 126, 66, 0.28));
}

.btn--secondary:hover {
  background: var(--color-surface-hover, rgba(255, 255, 255, 0.08));
  border-color: var(--accent, var(--aperium-copper));
}

/* Shadow audit - 3-level system */
.shadow-sm {
  box-shadow: var(--shadow-sm, 0 4px 8px rgba(0, 0, 0, 0.06));
}

.shadow-md {
  box-shadow: var(--shadow-card, 0 12px 24px rgba(0, 0, 0, 0.08));
}

.shadow-lg {
  box-shadow: var(--shadow-elevated, 0 20px 40px rgba(0, 0, 0, 0.12));
}

/* ========================================
 * 2. Typography Polish
 * ======================================== */

/* Apply DS-08 typography scale everywhere */
h1 {
  font-size: var(--type-display-size, clamp(3rem, 6vw + 0.2rem, 4.5rem));
  line-height: var(--type-display-line, 1.08);
  font-weight: 700;
  letter-spacing: -0.02em;
}

h2 {
  font-size: var(--type-title-size, clamp(2.125rem, 3.6vw, 3rem));
  line-height: var(--type-title-line, 1.12);
  font-weight: 600;
  letter-spacing: -0.01em;
}

h3 {
  font-size: var(--type-subtitle-size, clamp(1.35rem, 1.8vw + 0.4rem, 1.75rem));
  line-height: var(--type-subtitle-line, 1.35);
  font-weight: 600;
  letter-spacing: 0;
}

h4 {
  font-size: var(--type-body-size, 1rem);
  line-height: var(--type-body-line, 1.6);
  font-weight: 600;
  letter-spacing: 0;
}

p {
  font-size: var(--type-body-size, 1rem);
  line-height: var(--type-body-line, 1.6);
  letter-spacing: 0;
}

small,
.text-small {
  font-size: var(--type-micro-size, 0.8125rem);
  line-height: var(--type-micro-line, 1.45);
  letter-spacing: 0.01em;
}

/* Consistent letter spacing */
body {
  letter-spacing: 0;
}

/* ========================================
 * 3. Spacing & Rhythm
 * ======================================== */

/* Standardize vertical spacing (32px/48px rhythm) */
.section {
  margin-bottom: var(--space-xxxl, 48px);
}

.section + .section {
  margin-top: var(--space-xxxl, 48px);
}

/* Form spacing improvements */
.form-group {
  margin-bottom: var(--space-xl, 32px);
}

.form-group:last-child {
  margin-bottom: 0;
}

label {
  margin-bottom: var(--space-sm, 12px);
  display: block;
  line-height: var(--type-body-line, 1.6);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
  margin-bottom: var(--space-md, 16px);
  line-height: var(--type-body-line, 1.6);
}

/* Fix margin collapse */
.card + .card {
  margin-top: var(--space-xl, 32px);
}

/* Vertical rhythm for lists */
ul, ol {
  margin-bottom: var(--space-lg, 24px);
  padding-left: var(--space-lg, 24px);
}

li {
  margin-bottom: var(--space-xs, 8px);
  line-height: var(--type-body-line, 1.6);
}

/* ========================================
 * 4. Card Polish
 * ======================================== */

/* Standardize card radius */
.card,
.bb-card,
.ap-card {
  border-radius: var(--radius-lg, 16px);
  padding: var(--space-xl, 32px);
  box-shadow: var(--shadow-card, 0 12px 24px rgba(0, 0, 0, 0.08));
}

/* 3-level shadow system */
.card--elevated,
.bb-card--elevated {
  box-shadow: var(--shadow-elevated, 0 20px 40px rgba(0, 0, 0, 0.12));
}

.card--subtle {
  box-shadow: var(--shadow-sm, 0 4px 8px rgba(0, 0, 0, 0.06));
}

/* Card padding standardization */
.card-header {
  padding: var(--space-lg, 24px) var(--space-xl, 32px);
  margin-bottom: var(--space-lg, 24px);
}

.card-body {
  padding: 0 var(--space-xl, 32px);
  margin-bottom: var(--space-lg, 24px);
}

.card-footer {
  padding: var(--space-lg, 24px) var(--space-xl, 32px);
  margin-top: var(--space-lg, 24px);
  border-top: 1px solid var(--border, rgba(196, 126, 66, 0.28));
}

/* ========================================
 * 5. Iconography Polish
 * ======================================== */

/* Consistent stroke width for all icons */
.bb-icon {
  stroke-width: 1.5;
}

.bb-icon--bold {
  stroke-width: 2;
}

.bb-icon--thin {
  stroke-width: 1;
}

/* Remove any remaining emoji styles */
.emoji {
  display: none !important;
}

/* ========================================
 * Inline Style Overrides
 * ======================================== */

/* Override common inline styles with DS tokens */
[style*="padding: 24px"],
[style*="padding:24px"] {
  padding: var(--space-lg, 24px) !important;
}

[style*="padding: 16px"],
[style*="padding:16px"] {
  padding: var(--space-md, 16px) !important;
}

[style*="margin: 0"],
[style*="margin:0"] {
  margin: 0 !important;
}

[style*="margin-bottom: 24px"],
[style*="margin-bottom:24px"] {
  margin-bottom: var(--space-lg, 24px) !important;
}

[style*="margin-bottom: 16px"],
[style*="margin-bottom:16px"] {
  margin-bottom: var(--space-md, 16px) !important;
}

[style*="margin-top: 24px"],
[style*="margin-top:24px"] {
  margin-top: var(--space-lg, 24px) !important;
}

[style*="margin-top: 16px"],
[style*="margin-top:16px"] {
  margin-top: var(--space-md, 16px) !important;
}

[style*="font-size: 16px"],
[style*="font-size:16px"] {
  font-size: var(--type-body-size, 1rem) !important;
}

[style*="font-size: 14px"],
[style*="font-size:14px"] {
  font-size: var(--type-micro-size, 0.8125rem) !important;
}

[style*="border-radius: 8px"],
[style*="border-radius:8px"] {
  border-radius: var(--radius-sm, 8px) !important;
}

/* ========================================
 * Builder Modals (Selection Sheets)
 * ======================================== */

/* Selection sheet modal styling */
.selection-sheet-modal,
.selection-sheet-overlay {
  border-radius: var(--radius-xl, 20px) !important;
  box-shadow: var(--shadow-modal, 0 24px 48px rgba(0, 0, 0, 0.2)) !important;
}

/* Selection sheet close button */
.selection-sheet-close,
.selection-sheet-header button[aria-label*="close"],
.selection-sheet-header button[aria-label*="Close"] {
  color: var(--text-primary) !important;
  border-radius: var(--radius-md, 12px) !important;
  transition: all var(--transition-base, 0.2s ease) !important;
}

.selection-sheet-close:hover,
.selection-sheet-header button[aria-label*="close"]:hover,
.selection-sheet-header button[aria-label*="Close"]:hover {
  background: var(--color-surface-hover) !important;
  color: var(--accent) !important;
}

/* Selection sheet selected state */
.selection-sheet-item.selected,
.selection-sheet-item[aria-selected="true"] {
  background: var(--accent) !important;
  color: #ffffff !important;
  border-color: var(--accent) !important;
}

/* Remove harsh borders from selection sheets */
.selection-sheet-modal {
  border: 1px solid var(--border, rgba(196, 126, 66, 0.28)) !important;
}

/* ========================================
 * Mocktail Builder Specific Polish
 * ======================================== */

/* Mocktail builder section spacing */
.mocktail-builder-section .row {
  margin-bottom: var(--space-xl, 32px) !important;
}

.mocktail-builder-section .row:last-child {
  margin-bottom: 0 !important;
}

/* Mocktail builder labels */
.mocktail-builder-section .label {
  font-size: var(--type-body-size, 1rem) !important;
  font-weight: 600 !important;
  line-height: var(--type-body-line, 1.5) !important;
  margin-bottom: var(--space-sm, 12px) !important;
  color: var(--text-primary) !important;
}

/* Mocktail builder helper text */
.mocktail-builder-section .small.muted {
  font-size: var(--type-caption-size, 0.8125rem) !important;
  line-height: var(--type-caption-line, 1.4) !important;
  color: var(--text-muted) !important;
}

/* Mocktail builder inputs */
.mocktail-builder-section .wide-text-input {
  border-radius: var(--radius-md, 12px) !important;
  border: 1px solid var(--border, rgba(196, 126, 66, 0.28)) !important;
  padding: var(--space-sm, 12px) var(--space-md, 16px) !important;
  font-size: var(--type-body-size, 1rem) !important;
  line-height: var(--type-body-line, 1.5) !important;
  transition: all var(--transition-base, 0.2s ease) !important;
}

.mocktail-builder-section .wide-text-input:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(196, 126, 66, 0.1) !important;
  outline: none !important;
}

/* Mocktail builder textarea */
.mocktail-builder-section textarea.wide-text-input {
  min-height: 80px !important;
  resize: vertical !important;
}

/* Mocktail builder buttons */
.mocktail-builder-section .btn {
  border-radius: var(--radius-md, 12px) !important;
  padding: var(--space-md, 16px) var(--space-lg, 24px) !important;
  font-size: var(--type-body-size, 1rem) !important;
  font-weight: 600 !important;
  transition: all var(--transition-base, 0.2s ease) !important;
}

/* Selection sheet button styling (for dropdowns like Base Soda, Flavors, Creams, Brand Style) */
.selection-sheet-pill-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-sm, 12px) var(--space-md, 16px);
  border: 1px solid var(--border, rgba(196, 126, 66, 0.28));
  border-radius: var(--radius-md, 12px);
  background: var(--color-surface, rgba(255, 255, 255, 0.04));
  background-color: var(--color-surface, rgba(255, 255, 255, 0.04)) !important;
  color: var(--text-primary, rgba(255, 255, 255, 0.98));
  font-size: var(--type-body-size, 1rem);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-base, 0.2s ease);
  text-align: left;
}

.selection-sheet-pill-button:hover {
  background: var(--color-surface-hover, rgba(255, 255, 255, 0.08)) !important;
  background-color: var(--color-surface-hover, rgba(255, 255, 255, 0.08)) !important;
  border-color: var(--accent, rgba(196, 126, 66, 0.5));
}

.selection-sheet-pill-button:focus {
  outline: none;
  border-color: var(--accent, var(--aperium-copper));
  box-shadow: 0 0 0 3px rgba(196, 126, 66, 0.1);
}

.selection-sheet-pill-button .selection-sheet-pill-text {
  flex-grow: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selection-sheet-pill-button .selection-sheet-pill-chevron {
  flex-shrink: 0;
  margin-left: var(--space-sm, 12px);
  color: var(--text-muted, rgba(255, 255, 255, 0.8));
  transition: transform var(--transition-base, 0.2s ease);
}

.selection-sheet-pill-button[aria-expanded="true"] .selection-sheet-pill-chevron {
  transform: rotate(180deg);
}

/* Light mode readability for pill buttons */
:root[data-ui-theme='aperium'][data-bar-mode='light'] .selection-sheet-pill-button,
:root[data-ui-theme='halytic'][data-bar-mode='light'] .selection-sheet-pill-button {
  color: var(--text);
  background: var(--bb-white, #ffffff);
  border-color: var(--border, rgba(196, 126, 66, 0.28));
}

:root[data-ui-theme='aperium'][data-bar-mode='light'] .selection-sheet-pill-button .selection-sheet-pill-chevron,
:root[data-ui-theme='halytic'][data-bar-mode='light'] .selection-sheet-pill-button .selection-sheet-pill-chevron {
  color: var(--text-muted);
}

.selection-sheet-pill-button[aria-expanded="true"] .selection-sheet-pill-chevron {
  transform: rotate(180deg);
}

/* Brand Style Select - Match selection sheet button styling (fallback for old select) */
.mocktail-builder-section .bb-select-wrap {
  position: relative;
}

.mocktail-builder-section .bb-select {
  width: 100% !important;
  padding: var(--space-sm, 12px) var(--space-md, 16px) !important;
  padding-right: calc(var(--space-md, 16px) + 20px) !important;
  border: 1px solid var(--border, rgba(196, 126, 66, 0.28)) !important;
  border-radius: var(--radius-md, 12px) !important;
  background: var(--color-surface, rgba(255, 255, 255, 0.04)) !important;
  background-color: var(--color-surface, rgba(255, 255, 255, 0.04)) !important;
  color: var(--text-primary) !important;
  font-size: var(--type-body-size, 1rem) !important;
  font-weight: 500 !important;
  line-height: var(--type-body-line, 1.5) !important;
  cursor: pointer !important;
  pointer-events: auto !important;
  user-select: none !important;
  transition: all var(--transition-base, 0.2s ease) !important;
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4 6l4 4 4-4' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right var(--space-md, 16px) center !important;
  background-size: 16px 16px !important;
  z-index: 1 !important;
  position: relative !important;
}

.mocktail-builder-section .bb-select:hover {
  border-color: var(--accent, rgba(196, 126, 66, 0.5)) !important;
  background-color: var(--color-surface-hover, rgba(255, 255, 255, 0.08)) !important;
}

.mocktail-builder-section .bb-select:focus {
  outline: none !important;
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(196, 126, 66, 0.1) !important;
}

.mocktail-builder-section .bb-select option {
  background: var(--card, var(--color-surface)) !important;
  color: var(--text-primary) !important;
  padding: var(--space-sm, 12px) !important;
}

[style*="border-radius: 12px"],
[style*="border-radius:12px"] {
  border-radius: var(--radius-md, 12px) !important;
}

[style*="border-radius: 16px"],
[style*="border-radius:16px"] {
  border-radius: var(--radius-lg, 16px) !important;
}

/* Color overrides - replace hardcoded colors with DS tokens */
[style*="color: #666"],
[style*="color:#666"] {
  color: var(--text-muted, rgba(255, 255, 255, 0.85)) !important;
}

[style*="color: #374151"],
[style*="color:#374151"] {
  color: var(--text, rgba(255, 255, 255, 0.98)) !important;
}

[style*="background: #f5f5f5"],
[style*="background:#f5f5f5"] {
  background: var(--color-surface, rgba(255, 255, 255, 0.04)) !important;
}

[style*="background: rgba(239, 68, 68"],
[style*="background:rgba(239, 68, 68"] {
  background: var(--error-bg, rgba(220, 38, 38, 0.12)) !important;
}

/* ========================================
 * Responsive Adjustments
 * ======================================== */

@media (max-width: 768px) {
  .card,
  .bb-card,
  .ap-card {
    padding: var(--space-lg, 24px);
  }
  
  .section {
    margin-bottom: var(--space-xl, 32px);
  }
  
  .section + .section {
    margin-top: var(--space-xl, 32px);
  }
}

