:root {
  --bg-primary: #09090b;      /* Shadcn Dark Background (Zinc 950) */
  --bg-secondary: #09090b;    /* Shadcn Sidebar Background */
  --bg-card: #09090b;         /* Shadcn Card Background */
  --bg-card-hover: #18181b;   /* Shadcn Card Hover (Zinc 900) */
  --bg-input: #09090b;        /* Shadcn Input Background */
  --bg-modal: #18181b;        /* Shadcn Modal Background (Zinc 900) */

  --border: #27272a;          /* Shadcn Border (Zinc 800) */
  --border-focus: #a1a1aa;    /* Shadcn Border Focus (Zinc 400) */
  --border-subtle: #18181b;

  --text-primary: #fafafa;    /* Shadcn Foreground (Zinc 50) */
  --text-secondary: #e4e4e7;  /* Shadcn Muted Foreground (Zinc 200) */
  --text-muted: #71717a;      /* Shadcn Muted (Zinc 500) */
  --text-heading: #ffffff;    /* Pure white for headings */

  --accent: #27272a;          /* Shadcn Accent/Hover background (Zinc 800) */
  --accent-light: #fafafa;    /* Shadcn Accent text */
  --accent-glow: rgba(250, 250, 250, 0.02);
  --accent-gradient: linear-gradient(135deg, #27272a 0%, #18181b 100%);

  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --info: #3b82f6;
  --info-bg: rgba(59, 130, 246, 0.1);

  --gold: #fbbf24;
  --gold-gradient: linear-gradient(135deg, #fbbf24 0%, #d97706 100%);

  --sidebar-width: 200px;     /* Narrower sidebar to free up horizontal space */
  --radius: 8px;              /* Shadcn border radius (0.5rem) */
  --radius-sm: 6px;
  --radius-xs: 4px;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;            /* Increase base font size from 14px */
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
  line-height: 1.5;
}

h1, h2, h3, h4 {
  color: var(--text-heading);
  font-weight: 700;
  letter-spacing: -0.02em;
}

a { color: var(--accent-light); text-decoration: none; }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  font-size: 28px;
  animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.logo-title {
  display: block;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.08em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-sub {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.05em;
}

.nav-list {
  list-style: none;
  padding: 12px 8px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-weight: 500;
  transition: all var(--transition);
  margin-bottom: 4px;
  position: relative;
}

.nav-item:hover {
  background: var(--accent);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent);
  color: var(--text-primary);
}

.nav-item.active::before {
  display: none;
}

.nav-icon { font-size: 18px; }
.nav-label { font-size: 13px; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

/* ---------- Main Content ---------- */
#main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  padding: 20px;
}

.tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}

.tab-content.active { display: block; }

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

/* ---------- Page Header ---------- */
.page-header {
  margin-bottom: 28px;
}

.page-header h1 {
  font-size: 24px;
  margin-bottom: 6px;
}

.page-desc {
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  overflow: hidden;
  transition: border-color var(--transition);
}

.card:hover {
  border-color: var(--border-focus);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.card-header h2 {
  font-size: 17px;
  font-weight: 700;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-body {
  padding: 20px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
}
.btn-primary:hover {
  background: var(--text-secondary);
  border-color: var(--text-secondary);
  box-shadow: none;
  transform: none;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: var(--accent);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
}

.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.3);
}
.btn-danger-outline:hover {
  background: var(--danger-bg);
}

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-xs { padding: 4px 8px; font-size: 12px; }

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 15px;
}
.btn-icon:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.btn-icon.delete:hover { background: var(--danger-bg); color: var(--danger); }

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 12px 14px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  font-size: 14px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

tbody tr {
  transition: background var(--transition);
}

tbody tr:hover {
  background: rgba(59, 130, 246, 0.04);
}

tbody tr:last-child td {
  border-bottom: none;
}

tfoot td {
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-light);
  background: rgba(59, 130, 246, 0.06);
  border-top: 1px solid var(--border);
}

.col-calc {
  color: var(--accent-light) !important;
}

.col-actions {
  width: 70px;
  text-align: center;
}

.col-highlight {
  color: var(--success) !important;
}

/* Inline editable inputs in tables */
td input, td select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 7px 10px;
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: 14px;
  transition: all var(--transition);
}

td input:focus, td select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 1px var(--border-focus);
}

td input[type="number"] {
  text-align: right;
  -moz-appearance: textfield;
}

td input[type="number"]::-webkit-inner-spin-button,
td input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

td .calc-value {
  color: var(--accent-light);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- Forms ---------- */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input,
.form-group select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: 13px;
  transition: all var(--transition);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 1px var(--border-focus);
}

select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

.section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 8px 0 10px;
}

/* ---------- Calculator Layout ---------- */
.calc-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  align-items: start;
}

.calc-config .card {
  position: sticky;
  top: 32px;
}

.calc-config .card-body {
  max-height: calc(100vh - 180px);
  overflow-y: auto;
}

/* Consumable qty row */
.consumable-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 10px;
  background: var(--bg-input);
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-subtle);
}

.consumable-row .consumable-name {
  flex: 1;
  font-size: 12px;
  color: var(--text-secondary);
}

.consumable-row .consumable-info {
  font-size: 11px;
  color: var(--text-muted);
}

.consumable-row input[type="number"] {
  width: 60px;
  text-align: center;
  padding: 4px 6px;
  font-size: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-xs);
}

/* Carried item checkbox */
.carried-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.carried-check input[type="checkbox"] {
  accent-color: var(--accent);
}

/* ---------- Result Cards ---------- */
.result-card {
  overflow: visible;
}

/* Weight Bar */
.weight-bar-container {
  margin-bottom: 20px;
}

.weight-bar {
  height: 28px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  border: 1px solid var(--border);
}

.weight-segment {
  height: 100%;
  transition: width 0.5s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.segment-used {
  background: linear-gradient(135deg, #f97316 0%, #ef4444 100%);
}

.segment-available {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.weight-bar-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11px;
}

.label-used { color: #f97316; }
.label-available { color: var(--success); }

/* Weight breakdown list */
.weight-breakdown {
  font-size: 13px;
}

.wb-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px dotted var(--border-subtle);
}

.wb-row.wb-total {
  font-weight: 700;
  color: var(--text-heading);
  border-bottom: none;
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 4px;
}

.wb-row.wb-highlight {
  color: var(--success);
  font-weight: 700;
}

.wb-row.wb-sub {
  padding-left: 16px;
  color: var(--text-muted);
  font-size: 12px;
}

.wb-row .wb-label { color: var(--text-secondary); }
.wb-row .wb-value { font-variant-numeric: tabular-nums; }

.wb-row.wb-negative .wb-value { color: var(--danger); }

.wb-divider {
  border-top: 1px dashed var(--border);
  margin: 6px 0;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-item {
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-subtle);
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-heading);
  font-variant-numeric: tabular-nums;
}

.stat-value.text-success { color: var(--success); }
.stat-value.text-danger { color: var(--danger); }
.stat-value.text-warning { color: var(--warning); }
.stat-value.text-accent { color: var(--accent-light); }

.stat-unit {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 2px;
}

/* Cost breakdown */
.cost-breakdown {
  font-size: 13px;
}

.cost-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dotted var(--border-subtle);
}

.cost-row:last-child { border-bottom: none; }

.cost-row .cost-name { color: var(--text-secondary); }
.cost-row .cost-detail { font-size: 11px; color: var(--text-muted); }
.cost-row .cost-amount { color: var(--danger); font-weight: 600; font-variant-numeric: tabular-nums; }

.cost-row.cost-total {
  border-top: 1px solid var(--border);
  border-bottom: none;
  padding-top: 12px;
  margin-top: 4px;
}

.cost-row.cost-total .cost-name { color: var(--text-heading); font-weight: 700; }
.cost-row.cost-total .cost-amount { font-size: 16px; font-weight: 800; }

/* Profit display */
.profit-display {
  text-align: center;
  padding: 16px 0;
}

.profit-main {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: 16px;
}

.profit-block {
  text-align: center;
}

.profit-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.profit-value {
  font-size: 28px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.profit-value.positive {
  color: var(--success);
  text-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
}

.profit-value.negative { color: var(--danger); }

.profit-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.profit-efficiency {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: 20px;
  font-size: 12px;
  color: var(--success);
  font-weight: 600;
}

/* Card accents for result sections */
.card-income { border-left: 3px solid var(--info); }
.card-costs { border-left: 3px solid var(--danger); }
.card-profit { border-left: 3px solid var(--success); }

/* ---------- Settings Grid ---------- */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
}

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

.modal-overlay.show {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 15px; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all var(--transition);
}
.modal-close:hover { color: var(--text-primary); background: rgba(0,0,0,0.05); }

.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ---------- Overview table ---------- */
#tbl-overview tbody td {
  font-variant-numeric: tabular-nums;
}

#tbl-overview .rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-weight: 800;
  font-size: 12px;
}

.rank-1 { background: var(--gold); color: #000; }
.rank-2 { background: #94a3b8; color: #000; }
.rank-3 { background: #b45309; color: #fff; }
.rank-other { background: var(--bg-input); color: var(--text-muted); }

.overview-positive { color: var(--success); font-weight: 600; }
.overview-negative { color: var(--danger); font-weight: 600; }

/* ---------- Checkbox styled ---------- */
input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- Toast / Notification ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 13px;
  color: var(--text-primary);
  z-index: 2000;
  animation: slideUp 0.3s ease, fadeOut 0.3s ease 2.5s forwards;
}

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

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(-10px); }
}

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 36px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 13px;
}

/* ---------- Formulas Tab Styles ---------- */
.formulas-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 24px;
}

.formula-block {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.formula-block:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.formula-title {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-heading);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.formula-expr {
  display: block;
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-xs);
  margin-bottom: 8px;
  word-break: break-all;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}

.formula-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}


/* ---------- Crafting Tab Styles ---------- */
.crafting-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 20px;
  align-items: start;
}

.recipe-card {
  transition: all 0.3s ease;
}

.recipe-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: rgba(37, 99, 235, 0.3);
}

.recipe-info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 15px;
  border: 1px solid var(--border-subtle);
}

.recipe-info-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.recipe-info-item .info-label {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.recipe-info-item .info-val {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.tbl-ingredients {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.tbl-ingredients th {
  padding: 4px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

.tbl-ingredients td {
  padding: 6px 4px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-subtle);
}

.tbl-ingredients input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-xs);
  padding: 4px 6px;
  width: 100%;
  font-size: 11px;
}

.tbl-ingredients input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 1px var(--border-focus);
  outline: none;
}

.recipe-totals-box {
  background: rgba(37, 99, 235, 0.04);
  border: 1px solid rgba(37, 99, 235, 0.15);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-top: 15px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.recipe-totals-box .total-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
}

.recipe-totals-box .total-row strong {
  font-size: 13px;
  color: var(--text-primary);
}

.recipe-totals-box .total-row .text-success { color: var(--success); }
.recipe-totals-box .total-row .text-danger { color: var(--danger); }

/* ---------- Upgrades Tab Styles ---------- */
.upgrade-layout {
  display: grid;
  grid-template-columns: 280px 300px 1fr;
  gap: 20px;
  align-items: start;
}

.upgrade-col {
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-self: stretch;
}

.upgrade-col.double-width {
  grid-column: span 1;
}

@media (min-width: 1400px) {
  .upgrade-layout {
    grid-template-columns: 300px 340px 1fr;
  }
}

.up-level-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.up-level-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.01);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.up-level-item:hover {
  background: rgba(0, 0, 0, 0.03);
  border-color: var(--text-muted);
}

.up-level-item.active {
  background: var(--accent);
  border-color: var(--border-focus);
  box-shadow: none;
}

.up-level-item .level-badge {
  background: var(--border);
  color: var(--text-primary);
  font-weight: 800;
  font-size: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.up-level-item.active .level-badge {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 8px rgba(37, 99, 235, 0.3);
}

.up-level-item .level-summary {
  flex: 1;
  min-width: 0;
}

.upgrade-editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 15px;
}

.upgrade-editor-grid select,
.upgrade-editor-grid input,
.upgrade-col input,
.upgrade-col select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  width: 100%;
  font-size: 13px;
  transition: all 0.2s;
}

.upgrade-editor-grid select:focus,
.upgrade-editor-grid input:focus,
.upgrade-col input:focus,
.upgrade-col select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 1px var(--border-focus);
  outline: none;
}

/* Simulator Panel */
.sim-panel-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 15px;
}

.sim-metric {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

.sim-metric-label {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sim-metric-val {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-primary);
}

.sim-log-list {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: monospace;
  font-size: 11px;
  height: 140px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sim-log-row {
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1.4;
  word-break: break-word;
}

.sim-log-row.success {
  background: rgba(16, 185, 129, 0.08);
  border-left: 3px solid var(--success);
  color: #34d399;
}

.sim-log-row.fail {
  background: rgba(239, 68, 68, 0.08);
  border-left: 3px solid var(--danger);
  color: #fca5a5;
}

.sim-log-row.info {
  background: rgba(59, 130, 246, 0.08);
  border-left: 3px solid var(--info);
  color: #93c5fd;
}

/* Success/Fail Flashes */
@keyframes successPulse {
  0% { box-shadow: 0 0 0 rgba(16, 185, 129, 0); }
  50% { box-shadow: 0 0 25px rgba(16, 185, 129, 0.5); border-color: var(--success); }
  100% { box-shadow: 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes failPulse {
  0% { box-shadow: 0 0 0 rgba(239, 68, 68, 0); }
  50% { box-shadow: 0 0 25px rgba(239, 68, 68, 0.5); border-color: var(--danger); }
  100% { box-shadow: 0 0 0 rgba(239, 68, 68, 0); }
}

.success-flash {
  animation: successPulse 0.8s ease-out;
}

.fail-flash {
  animation: failPulse 0.8s ease-out;
}


/* Badges in Item Directory */
.badge {
  display: inline-block;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-loot {
  background: rgba(59, 130, 246, 0.1);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.badge-tool {
  background: rgba(245, 158, 11, 0.1);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.badge-consumable {
  background: rgba(16, 185, 129, 0.1);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge-craft {
  background: #f5f3ff;
  color: #6d28d9;
  border: 1px solid rgba(109, 40, 217, 0.2);
}

.badge-upgrade {
  background: #fdf2f8;
  color: #be185d;
  border: 1px solid rgba(219, 39, 119, 0.2);
}

.badge-other {
  background: rgba(107, 114, 128, 0.1);
  color: #9ca3af;
  border: 1px solid rgba(107, 114, 128, 0.2);
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .calc-layout {
    grid-template-columns: 1fr;
  }
  .calc-config .card {
    position: static;
  }
}

@media (max-width: 768px) {
  #sidebar {
    width: 60px;
    overflow: hidden;
  }
  .sidebar-logo { padding: 16px 8px; justify-content: center; }
  .logo-text { display: none; }
  .nav-label { display: none; }
  .nav-item { justify-content: center; padding: 12px 8px; }
  .sidebar-footer { display: none; }
  #main-content { margin-left: 60px; padding: 16px; }
  .settings-grid { grid-template-columns: 1fr; }
  .formulas-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .profit-main { flex-direction: column; gap: 20px; }
}

/* ---------- Master Item Registry & Flat Upgrades Styles ---------- */
.formulas-grid-vertical {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.formula-horizontal-card {
  width: 100%;
}

.formula-horizontal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.formula-item {
  padding: 14px 20px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--accent);
  border-top: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  transition: transform var(--transition);
}

.formula-item:hover {
  transform: translateX(4px);
  background: var(--bg-card-hover);
}

.formula-math {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.math-expr {
  font-family: 'Courier New', Courier, monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-light);
}

.math-example {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.math-example strong {
  color: var(--success);
  font-weight: 700;
}

.math-example code {
  color: var(--warning);
  font-family: monospace;
}

.upgrade-layout-flat {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  align-items: start;
}

.upgrade-left-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.upgrade-right-panel {
  position: sticky;
  top: 20px;
}

@media (max-width: 1024px) {
  .upgrade-layout-flat {
    grid-template-columns: 1fr;
  }
  .upgrade-right-panel {
    position: static;
  }
}

/* ---------- Math Legend for formulas ---------- */
.math-legend {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}

.math-legend span {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ---------- Login Overlay ---------- */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  text-align: left;
}

.login-logo {
  text-align: center;
  margin-bottom: 24px;
}

.login-logo .logo-title {
  display: block;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.08em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-logo .logo-sub {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.05em;
}

.login-desc {
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
  margin-bottom: 24px;
  line-height: 1.5;
}

.login-error {
  background: var(--danger-bg);
  border: 1px solid rgba(185, 28, 28, 0.2);
  padding: 10px;
  border-radius: var(--radius-xs);
}

/* ---------- Sub Tabs Navigation ---------- */
.subtabs-bar {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  padding-bottom: 8px;
}

.subtab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  cursor: pointer;
  transition: all var(--transition);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}

.subtab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.subtab-btn.active {
  color: var(--text-primary);
  background: var(--accent);
  border-color: var(--border);
}

.subtab-content {
  display: none;
  animation: fadeIn 0.2s ease;
}

.subtab-content.active {
  display: block;
}

/* ---------- Calculator Dashboard Layout ---------- */
.calc-dashboard-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

@media (max-width: 768px) {
  .calc-dashboard-metrics {
    grid-template-columns: 1fr;
  }
}

.metric-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
}

.card-profit-metric::before {
  background: var(--success);
}

.card-time-metric::before {
  background: var(--warning);
}

.card-weight-metric::before {
  background: var(--info);
}

.metric-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.metric-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
}

.metric-unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 4px;
}

.metric-sub {
  font-size: 12px;
  color: var(--text-secondary);
}

.calc-dashboard-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 1024px) {
  .calc-dashboard-details {
    grid-template-columns: 1fr;
  }
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  font-size: 13px;
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-label {
  color: var(--text-secondary);
}

.detail-value {
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.detail-value.text-accent {
  color: var(--accent-light);
}

.detail-value.text-success {
  color: var(--success);
}

.detail-value.text-warning {
  color: var(--warning);
}

.detail-value.text-danger {
  color: var(--danger);
}


