:root {
  --bg-color: #0f172a;
  --surface: #1e293b;
  --card-bg: #1e293b;
  --primary: #94a3b8;
  /* Slate 400 - Metallic Blue-Grey */
  --accent: #64748b;
  /* Slate 500 */
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --glass-border: 1px solid rgba(255, 255, 255, 0.08);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  --metal-gradient: linear-gradient(135deg, #334155 0%, #1e293b 100%);
  --btn-gradient: linear-gradient(to bottom, #475569, #334155);
  --btn-hover-gradient: linear-gradient(to bottom, #64748b, #475569);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
  background-color: var(--bg-color);
  /* Subtle metallic texture/grain effect via radial gradients */
  background-image:
    radial-gradient(circle at 50% 0%, rgba(148, 163, 184, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 0% 100%, rgba(51, 65, 85, 0.2) 0%, transparent 50%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding-top: 4rem;
}

.container {
  width: 100%;
  max-width: 600px;
  padding: 0 1rem;
}

/* Layout for Recipes Page */
.main-layout {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.recipe-grid {
  flex: 2;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.5rem;
}

.selection-card {
  flex: 1.5;
  background: var(--surface);
  padding: 1.5rem;
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: var(--glass-border);
  position: sticky;
  top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 350px;
  animation: fadeIn 0.3s ease-out;
  max-height: 80vh;
  overflow-y: auto;
}

.selection-card.hidden {
  display: none;
}

.selection-card h3 {
  margin-bottom: 0.5rem;
  color: var(--text-heading);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 0.5rem;
}

/* Session Details List */
.session-details-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.detail-card {
  background: rgba(0, 0, 0, 0.2);
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.detail-card h4 {
  color: var(--text-primary);
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  display: flex;
  justify-content: space-between;
}

.detail-card ul {
  padding-left: 1.2rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin: 0;
}

.sidebar {
  flex: 1;
  background: var(--surface);
  padding: 1.5rem;
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: var(--glass-border);
  position: sticky;
  top: 2rem;
  min-width: 280px;
}

/* Recipe Card */
.recipe-card {
  background: var(--metal-gradient);
  padding: 1.5rem;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  border: var(--glass-border);
  box-shadow: var(--shadow);
}

.recipe-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  border-color: var(--primary);
}

.recipe-card h3 {
  margin-top: 0;
  color: var(--text-primary);
}

.recipe-details {
  display: flex;
  gap: 1rem;
  margin: 1rem 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.recipe-operations-preview {
  font-size: 0.8em;
  color: #94a3b8;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Session Sidebar */
.session-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
}

.materials-summary {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 2px solid rgba(255, 255, 255, 0.1);
}

#materialList {
  padding-left: 1.2rem;
  font-size: 0.9rem;
  color: var(--text-primary);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--surface);
  padding: 2rem;
  border: var(--glass-border);
  border-radius: 16px;
  width: 300px;
  text-align: center;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 1.5rem;
}

/* Large Modal */
.large-modal {
  width: 600px;
  max-width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  text-align: left;
}

.form-group {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.form-section {
  margin-bottom: 2rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 1rem;
}

.form-section h3 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  color: var(--text-heading);
}

.dynamic-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.dynamic-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Form Inputs (Tiny) */
.ing-name,
.op-name {
  flex: 4;
}

.ing-qty,
.op-dur {
  flex: 1;
}

.ing-unit {
  flex: 0.5;
}

.ing-operation {
  flex: 2;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
}

.ing-operation option {
  background: var(--background);
  color: var(--text-primary);
}

.op-comm {
  flex: 2;
}

.op-min,
.op-sec {
  flex: 1;
  width: auto !important;
  /* Override global 100% */
  min-width: 0;
  text-align: center;
  padding: 0.5rem !important;
  /* Smaller padding */
}

.btn-small {
  font-size: 0.8rem;
  padding: 0.25rem 0.75rem;
  /* Pill adjustment */
  border-radius: 9999px;
}

/* Utility */
.flex-center {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.gap-1 {
  gap: 1rem;
}

.full-width {
  width: 100%;
  margin-top: 1rem;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--text-secondary);
  color: var(--text-secondary);
  padding: 0.5rem 1.25rem;
  border-radius: 9999px;
  /* Pill */
  cursor: pointer;
  text-decoration: none;
  font-size: 0.9rem;
  display: inline-block;
  transition: all 0.2s;
}

.btn-secondary:hover {
  border-color: var(--text-primary);
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.btn-danger {
  background: linear-gradient(to bottom, #7f1d1d, #450a0a);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 0.5rem 1.25rem;
  border-radius: 9999px;
  font-size: 0.9rem;
}

.btn-danger:hover {
  background: linear-gradient(to bottom, #991b1b, #7f1d1d);
  color: white;
  border-color: rgba(239, 68, 68, 0.5);
}

/* Enhanced Timer Styles */
/* Removed conflicting finished style */

.task-meta {
  font-size: 0.75rem;
  color: #94a3b8;
  margin-top: 0.25rem;
  display: flex;
  gap: 1rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

.task-meta>div {
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

.cumulative-timer {
  background: var(--metal-gradient);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  border-radius: 20px;
  text-align: center;
  color: var(--text-primary);
  border: var(--glass-border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.timer-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.timer-label {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.timer-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-primary);
  font-family: monospace;
}

.hidden {
  display: none !important;
}

.timer-row.hidden {
  display: none;
}

header {
  margin-bottom: 2rem;
  text-align: center;
  animation: fadeIn 0.5s ease-out;
}

h1 {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(to bottom, #f1f5f9, #94a3b8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 0.5rem;
  letter-spacing: -0.05em;
  text-transform: uppercase;
}

/* Card Styles */
.card-form {
  background: var(--metal-gradient);
  border: var(--glass-border);
  border-radius: 20px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
  animation: slideIn 0.4s ease-out;
}

input[type="text"],
input[type="password"],
input[type="number"],
input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]) {
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: 9999px;
  /* Pill inputs */
  font-size: 1rem;
  width: 100%;
  outline: none;
  transition: all 0.2s;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus {
  border-color: var(--primary);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3), 0 0 0 2px rgba(148, 163, 184, 0.2);
}

/* Remove spinners from number inputs */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
  /* Standard property */
  text-align: center;
  /* Center numbers */
  padding: 0.75rem 0.5rem;
  /* Reduce horizontal padding */
}

button {
  cursor: pointer;
  border: none;
  font-weight: 600;
  border-radius: 9999px;
  /* Pill buttons */
  transition: all 0.2s;
}

/* Input Wrappers with Labels */
.input-wrapper {
  position: relative;
  flex: 1;
  min-width: 90px;
  /* Ensure minimum width for 2 digits + label */
}

.input-wrapper input {
  padding-right: 2.2rem !important;
  /* Slightly reduced to give more text space */
  padding-left: 0.5rem !important;
}

.input-label {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  pointer-events: none;
  user-select: none;
}

.btn-primary {
  background: var(--btn-gradient);
  color: #f1f5f9;
  padding: 0.75rem 1.5rem;
  /* Adjusted padding for better pill shape */
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  border-radius: 9999px;
  /* Explicitly set for anchor tags */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--btn-hover-gradient);
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(0, 0, 0, 0.1);
}

/* Task List */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.task-item {
  background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
  border: var(--glass-border);
  border-radius: 16px;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  user-select: none;
}

.task-item.dragging {
  opacity: 0.5;
  transform: scale(0.98);
  border: 1px dashed var(--primary);
}

.task-content {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.task-content>* {
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.task-title {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  color: var(--text-primary);
}

.task-timer {
  font-family: 'Monaco', 'Consolas', monospace;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.task-controls {
  display: flex;
  gap: 0.5rem;
  margin-left: 1rem;
}

.btn-icon {
  background: linear-gradient(to bottom, #475569, #334155);
  color: var(--text-primary);
  width: 42px;
  /* Slightly larger for touch targets */
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  /* Circle implies pill-like curvature */
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.btn-icon:hover {
  background: linear-gradient(to bottom, #64748b, #475569);
  transform: translateY(-1px);
}

.btn-icon-mini {
  width: 32px;
  height: 32px;
  font-size: 0.8rem;
}

.btn-delete {
  background: linear-gradient(to bottom, #991b1b, #7f1d1d);
  color: #fca5a5;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-delete:hover {
  background: linear-gradient(to bottom, #ef4444, #b91c1c);
  color: white;
}

/* Recipe Colors (Metallic/Muted) */
/* Desaturated versions of previous colors */

.recipe-color-0 {
  /* Blue-ish */
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.1) 0%, transparent 100%);
  border-left: 4px solid #60a5fa;
}

.recipe-color-1 {
  /* Emerald-ish */
  background: linear-gradient(90deg, rgba(16, 185, 129, 0.1) 0%, transparent 100%);
  border-left: 4px solid #34d399;
}

.recipe-color-2 {
  /* Amber-ish */
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.1) 0%, transparent 100%);
  border-left: 4px solid #fbbf24;
}

.recipe-color-3 {
  /* Pink-ish */
  background: linear-gradient(90deg, rgba(236, 72, 153, 0.1) 0%, transparent 100%);
  border-left: 4px solid #f472b6;
}

.recipe-color-4 {
  /* Violet-ish */
  background: linear-gradient(90deg, rgba(139, 92, 246, 0.1) 0%, transparent 100%);
  border-left: 4px solid #a78bfa;
}

.recipe-color-5 {
  /* Cyan-ish */
  background: linear-gradient(90deg, rgba(6, 182, 212, 0.1) 0%, transparent 100%);
  border-left: 4px solid #22d3ee;
}


/* Active State */
.task-item.active {
  border-color: #4ade80;
  /* bright green border */
  background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
  /* vibrant green */
  box-shadow: 0 0 15px rgba(34, 197, 94, 0.4);
}

.task-item.active .task-title,
.task-item.active .task-timer {
  color: #ffffff;
  /* White text for contrast */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.task-item.active .task-meta {
  color: #dcfce7;
  /* Light green for meta text */
}

/* Ensure buttons inside active task allow needed contrast or kept as is */
.task-item.active .btn-icon {
  background: rgba(0, 0, 0, 0.2);
  border-color: rgba(255, 255, 255, 0.2);
}

.task-item.active .btn-icon:hover {
  background: rgba(0, 0, 0, 0.4);
}

/* Finished Alarm State */
.task-item.finished {
  animation: shake 0.5s cubic-bezier(.36, .07, .19, .97) both infinite;
  border-color: #ef4444;
  background: linear-gradient(135deg, rgba(127, 29, 29, 0.3) 0%, rgba(69, 10, 10, 0.3) 100%);
}

.task-item.finished .task-timer {
  color: #ef4444;
  text-shadow: 0 0 10px rgba(239, 68, 68, 0.5);
}

/* Confirmed State (Done/Stopped) */
.task-item.confirmed {
  border-color: #10b981;
  background: linear-gradient(135deg, rgba(6, 78, 59, 0.3) 0%, rgba(2, 44, 34, 0.3) 100%);
  animation: none;
  opacity: 0.7;
}

.task-item.confirmed .task-title {
  color: #34d399;
  text-decoration: line-through;
}

.task-item.confirmed .task-timer {
  color: #34d399;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes shake {

  10%,
  90% {
    transform: translate3d(-1px, 0, 0);
  }

  20%,
  80% {
    transform: translate3d(2px, 0, 0);
  }

  30%,
  50%,
  70% {
    transform: translate3d(-4px, 0, 0);
  }

  40%,
  60% {
    transform: translate3d(4px, 0, 0);
  }
}

/* Ingredient Checklist Styles */
.ingredients-checklist {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  width: fit-content;
}

.ingredient-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.1rem 0;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.ingredient-item:hover {
  opacity: 0.8;
}

.ingredient-item input[type="checkbox"] {
  width: 1.2rem;
  height: 1.2rem;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

.ingredient-item span {
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.ingredient-item.checked span {
  text-decoration: line-through;
  color: var(--text-secondary);
  opacity: 0.6;
}

/* Drag Handle */
.drag-handle {
  color: var(--text-secondary);
  cursor: grab;
  padding: 0.5rem;
  margin-right: 0.5rem;
}

.drag-handle:active {
  cursor: grabbing;
}

/* Recipe modal row drag handle */
.row-drag-handle {
  color: var(--text-secondary);
  cursor: grab;
  padding: 0 0.4rem;
  font-size: 1rem;
  flex-shrink: 0;
  user-select: none;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.row-drag-handle:hover {
  opacity: 1;
  color: var(--text-primary);
}

.row-drag-handle:active {
  cursor: grabbing;
}

/* Ghost placeholder while dragging a row */
.sortable-ghost {
  opacity: 0.35;
  background: rgba(148, 163, 184, 0.1);
  border-radius: 8px;
}