/* ============================================
   Bagel University — Component Library
   ============================================
   Requires: design-tokens.css loaded first.
   Usage: Add class names to HTML elements.
   ============================================ */

/* ── BUTTONS ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--text-body);
  line-height: 1;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--duration-normal) var(--easing-default);
  text-decoration: none;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.btn:disabled, .btn.is-disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Sizes */
.btn-sm  { height: 32px; padding: 0 var(--space-3); font-size: var(--text-small); }
.btn-md  { height: 40px; padding: 0 var(--space-5); }
.btn-lg  { height: 48px; padding: 0 var(--space-6); }
.btn-touch { height: 52px; padding: 0 var(--space-8); font-size: var(--text-body); }

/* Variants */
.btn-primary {
  background: var(--brand-blue);
  color: var(--color-text-inverse);
}
.btn-primary:hover { background: var(--brand-blue-hover); }
.btn-primary:active { background: #1a3578; }

.btn-secondary {
  background: var(--color-surface);
  color: var(--brand-blue);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover { background: var(--brand-blue-glow); border-color: var(--brand-blue); }
.btn-secondary:active { background: var(--brand-blue-light); }

.btn-ghost {
  background: transparent;
  color: var(--brand-blue);
}
.btn-ghost:hover { background: var(--brand-blue-glow); }
.btn-ghost:active { background: var(--brand-blue-light); }

.btn-danger {
  background: var(--color-error);
  color: var(--color-text-inverse);
}
.btn-danger:hover { background: #b91c1c; }
.btn-danger:active { background: #991b1b; }

.btn-success {
  background: var(--color-success);
  color: var(--color-text-inverse);
}
.btn-success:hover { background: #15803d; }

/* Full width (mobile) */
.btn-block { width: 100%; }

/* Loading state */
.btn.is-loading { pointer-events: none; position: relative; color: transparent; }
.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}
.btn-primary.is-loading::after { border-color: rgba(255,255,255,0.5); border-right-color: transparent; }

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


/* ── CARDS ── */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--duration-normal) var(--easing-default);
}

.card-interactive { cursor: pointer; }
.card-interactive:hover { box-shadow: var(--shadow-md); }

.card-status {
  border-left: 4px solid var(--color-pending);
}
.card-status.is-complete  { border-left-color: var(--color-success); }
.card-status.is-active    { border-left-color: var(--brand-blue); }
.card-status.is-warning   { border-left-color: var(--color-warning); }
.card-status.is-error     { border-left-color: var(--color-error); }

.card-draggable {
  cursor: grab;
  user-select: none;
}
.card-draggable:active { cursor: grabbing; }
.card-draggable.is-dragging {
  box-shadow: var(--shadow-lg);
  transform: scale(1.02);
  opacity: 0.95;
}

.card-title {
  font-family: var(--font-body);
  font-size: var(--text-h2);
  font-weight: 600;
  line-height: var(--leading-snug);
  margin-bottom: var(--space-2);
}

.card-subtitle {
  font-size: var(--text-small);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-4);
}

.card-body { margin-top: var(--space-4); }
.card-footer {
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}


/* ── FORM INPUTS ── */

.form-group {
  margin-bottom: var(--space-5);
}

.form-label {
  display: block;
  font-size: var(--text-small);
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.form-label-required::after {
  content: ' *';
  color: var(--color-error);
}

.form-hint {
  font-size: var(--text-small);
  color: var(--color-text-secondary);
  margin-top: var(--space-1);
}

.input, .textarea, .select {
  width: 100%;
  font-family: var(--font-body);
  font-size: var(--text-body);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  transition: border-color var(--duration-normal) var(--easing-default),
              box-shadow var(--duration-normal) var(--easing-default);
}

.input { height: 40px; }

.textarea {
  min-height: 80px;
  resize: vertical;
  line-height: var(--leading-normal);
}

.select {
  height: 40px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%235A6178' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-focus);
}

.input.is-error, .textarea.is-error, .select.is-error {
  border-color: var(--color-error);
  background: var(--color-error-bg);
}

.input:disabled, .textarea:disabled, .select:disabled {
  background: var(--color-pending-bg);
  color: var(--color-text-disabled);
  cursor: not-allowed;
}

.input::placeholder, .textarea::placeholder {
  color: var(--color-text-disabled);
}

.form-error {
  font-size: var(--text-small);
  color: var(--color-error);
  margin-top: var(--space-1);
}

/* Save indicator (inline) */
.save-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-small);
  color: var(--color-success);
  opacity: 0;
  transition: opacity var(--duration-normal) var(--easing-default);
}
.save-indicator.is-visible { opacity: 1; }
.save-indicator.is-fading {
  animation: save-fade 2s var(--easing-default) forwards;
}
@keyframes save-fade {
  0%, 60% { opacity: 1; }
  100% { opacity: 0; }
}


/* ── STATUS BADGES ── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge-success  { background: var(--color-success-bg);  color: var(--color-success); }
.badge-error    { background: var(--color-error-bg);    color: var(--color-error); }
.badge-warning  { background: var(--color-warning-bg);  color: var(--color-warning); }
.badge-info     { background: var(--color-info-bg);     color: var(--color-info); }
.badge-pending  { background: var(--color-pending-bg);  color: var(--color-pending); }

/* Dot variant (small circle + text) */
.badge-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}


/* ── PROGRESS BAR ── */

.progress {
  width: 100%;
  height: 8px;
  background: var(--color-pending-bg);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-blue), var(--brand-blue-bright));
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--easing-default);
}

.progress-label {
  font-size: var(--text-small);
  color: var(--color-text-secondary);
  margin-top: var(--space-1);
}

/* Large progress (used in header/dashboard) */
.progress-lg { height: 12px; }


/* ── NAVIGATION — SYSTEM STEP LIST ── */

.step-nav {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.step-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-body);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--duration-normal) var(--easing-default);
  border-left: 3px solid transparent;
}

.step-nav-item:hover { background: var(--brand-blue-glow); }

.step-nav-item.is-active {
  color: var(--brand-blue);
  font-weight: 500;
  border-left-color: var(--brand-blue);
  background: var(--brand-blue-glow);
}

.step-nav-item.is-complete {
  color: var(--color-success);
}

.step-nav-item .step-icon {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  flex-shrink: 0;
  background: var(--color-pending-bg);
  color: var(--color-text-disabled);
}

.step-nav-item.is-active .step-icon {
  background: var(--brand-blue);
  color: var(--color-text-inverse);
}

.step-nav-item.is-complete .step-icon {
  background: var(--color-success-bg);
  color: var(--color-success);
}

/* Sub-steps */
.step-nav-sub {
  list-style: none;
  margin-left: 40px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.step-nav-sub-item {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-small);
  color: var(--color-text-disabled);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--duration-fast) var(--easing-default);
}
.step-nav-sub-item:hover { color: var(--color-text-secondary); }
.step-nav-sub-item.is-active { color: var(--brand-blue); font-weight: 500; }
.step-nav-sub-item.is-complete { color: var(--color-text-secondary); }


/* ── TOAST / NOTIFICATIONS ── */

.toast-container {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

@media (max-width: 600px) {
  .toast-container {
    left: var(--space-4);
    right: var(--space-4);
    bottom: var(--space-4);
    align-items: stretch;
  }
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-small);
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in var(--duration-slow) var(--easing-entrance);
  min-width: 240px;
  max-width: 400px;
}

.toast-success { background: var(--color-success-bg); color: var(--color-success); }
.toast-error   { background: var(--color-error-bg);   color: var(--color-error); }
.toast-info    { background: var(--color-info-bg);     color: var(--color-info); }
.toast-warning { background: var(--color-warning-bg);  color: var(--color-warning); }

.toast-dismiss {
  margin-left: auto;
  background: none;
  border: none;
  color: currentColor;
  opacity: 0.5;
  cursor: pointer;
  font-size: var(--text-body);
  padding: var(--space-1);
}
.toast-dismiss:hover { opacity: 1; }

@keyframes toast-in {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.toast.is-leaving {
  animation: toast-out var(--duration-normal) var(--easing-exit) forwards;
}
@keyframes toast-out {
  to { transform: translateY(8px); opacity: 0; }
}


/* ── MODAL ── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 29, 61, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fade-in var(--duration-normal) var(--easing-default);
  padding: var(--space-5);
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  max-width: 440px;
  width: 100%;
  padding: var(--space-8);
  animation: modal-in var(--duration-slow) var(--easing-entrance);
}

.modal-title {
  font-size: var(--text-h2);
  font-weight: 600;
  margin-bottom: var(--space-3);
}

.modal-body {
  font-size: var(--text-body);
  color: var(--color-text-secondary);
  line-height: var(--leading-normal);
  margin-bottom: var(--space-6);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { transform: scale(0.95) translateY(8px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}


/* ── DRAG HANDLE ── */

.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  color: var(--color-text-disabled);
  cursor: grab;
  flex-shrink: 0;
  user-select: none;
  transition: color var(--duration-fast) var(--easing-default);
}
.drag-handle:hover { color: var(--color-text-secondary); }
.drag-handle:active { cursor: grabbing; }

/* Drag handle dots icon (CSS-only) */
.drag-handle::before {
  content: '⠿';
  font-size: 20px;
  line-height: 1;
}


/* ── SORTABLE LIST ITEM ── */

.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: all var(--duration-normal) var(--easing-default);
}

.list-item:hover { box-shadow: var(--shadow-sm); }

.list-item.is-dragging {
  box-shadow: var(--shadow-lg);
  transform: scale(1.02);
  z-index: 10;
}

.list-item-content { flex: 1; min-width: 0; }

/* Always-visible compact "×" delete button.
   Originally this was opacity:0 until .list-item:hover — but many call sites
   live inside .card / .drag-row / flex rows (recipes, workflows, training,
   inventory categories/vendors), so the hover reveal never fired and the
   button was permanently invisible. Now it's a bordered × that's always
   visible; hover turns it red for affordance. */
.list-item-remove {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  cursor: pointer;
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: var(--radius-sm);
  font-size: var(--text-body);
  font-weight: 500;
  line-height: 1;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: all var(--duration-fast) var(--easing-default);
}
.list-item-remove:hover {
  color: var(--color-error);
  border-color: var(--color-error);
  background: var(--color-error-bg);
}

/* Duplicate/copy button — same size as remove, but blue on hover to signal
   a non-destructive action. Used in recipes, inventory items, workflow
   procedures, and training stages so the user can fork an existing record
   and tweak it instead of retyping everything. */
.list-item-copy {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  cursor: pointer;
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: var(--radius-sm);
  line-height: 1;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: all var(--duration-fast) var(--easing-default);
}
.list-item-copy:hover {
  color: var(--brand-blue);
  border-color: var(--brand-blue);
  background: var(--brand-blue-glow);
}
.list-item-copy svg { width: 14px; height: 14px; }

.list-add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-3);
  background: none;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-family: var(--font-body);
  font-size: var(--text-small);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--duration-normal) var(--easing-default);
}
.list-add-btn:hover {
  border-color: var(--brand-blue);
  color: var(--brand-blue);
  background: var(--brand-blue-glow);
}


/* ── EMPTY STATE ── */

.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-8);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: var(--space-4);
  opacity: 0.4;
}

.empty-state-title {
  font-size: var(--text-h2);
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.empty-state-description {
  font-size: var(--text-body);
  color: var(--color-text-secondary);
  max-width: 360px;
  margin: 0 auto var(--space-6);
  line-height: var(--leading-normal);
}


/* ── HEADER ── */

.app-header {
  background: var(--brand-navy);
  color: var(--color-text-inverse);
}

.app-header-inner {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 36px var(--content-padding) 32px;
  display: flex;
  align-items: center;
  gap: var(--space-5);
}

.app-header-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  flex-shrink: 0;
  filter: brightness(1.15) drop-shadow(0 2px 8px rgba(0,0,0,0.2));
}

.app-header-text { flex: 1; }

.app-header h1 {
  font-family: var(--font-logo);
  font-size: var(--text-display);
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: var(--leading-tight);
  margin-bottom: var(--space-1);
}

.app-header p {
  color: var(--brand-blue-bright);
  font-size: var(--text-small);
  opacity: 0.85;
}

/* Home link in header */
.app-header-home {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: rgba(255, 255, 255, 0.55);
  text-decoration: none;
  font-size: var(--text-small);
  font-weight: 500;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  transition: all var(--duration-normal) var(--easing-default);
  margin-left: auto;
  flex-shrink: 0;
  white-space: nowrap;
}
.app-header-home:hover {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.1);
}
.app-header-home svg { flex-shrink: 0; }

/* Wide header variant (for dashboard) */
.app-header-inner.is-wide {
  max-width: var(--content-max-width-wide);
}


/* ── LAYOUT HELPERS ── */

.container {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--space-8) var(--content-padding) 80px;
}

.container-wide {
  max-width: var(--content-max-width-wide);
  margin: 0 auto;
  padding: var(--space-8) var(--content-padding) 80px;
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

.stack > * + * { margin-top: var(--space-4); }
.stack-sm > * + * { margin-top: var(--space-2); }
.stack-lg > * + * { margin-top: var(--space-6); }


/* ── STATION COLORS ── */

.station-counter  { --station-color: var(--station-counter); }
.station-grill    { --station-color: var(--station-grill); }
.station-prep     { --station-color: var(--station-prep); }
.station-baker    { --station-color: var(--station-baker); }
.station-coffee   { --station-color: var(--station-coffee); }
.station-dish     { --station-color: var(--station-dish); }

.station-card {
  border-left: 4px solid var(--station-color, var(--color-pending));
}
.station-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--station-color, var(--color-pending));
  display: inline-block;
}


/* ── MOBILE OVERRIDES ── */

@media (max-width: 600px) {
  .card { padding: var(--space-5); }
  .app-header-inner { padding: var(--space-6) var(--content-padding) var(--space-5); }
  .app-header-logo { width: 48px; height: 48px; }
  .app-header h1 { font-size: 1.5rem; }
  .btn-md { height: 44px; }
  .btn-lg, .btn-touch { width: 100%; }
  .modal { padding: var(--space-6); }
  .modal-overlay { padding: var(--space-4); }
}

@media (max-width: 480px) {
  .container { padding-left: var(--space-4); padding-right: var(--space-4); }
}
