:root[data-theme="dark"] {
  --bg-body: #070a12;
  --bg-surface: #0f1523;
  --bg-card: #151d30;
  --bg-card-hover: #1c263f;
  --bg-input: #090d16;
  --border: #232f46;
  --border-highlight: #3b4d71;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-2: #ec4899;
  --accent-glow: rgba(99, 102, 241, 0.2);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 16px 36px -10px rgba(0, 0, 0, 0.6);
}

:root[data-theme="light"] {
  --bg-body: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-input: #f1f5f9;
  --border: #e2e8f0;
  --border-highlight: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --accent: #4f46e5;
  --accent-2: #db2777;
  --accent-glow: rgba(79, 70, 229, 0.12);
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow: 0 12px 28px -8px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.25s, color 0.25s;
}

/* Scrollbar Customization */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-body); }
::-webkit-scrollbar-thumb { background: var(--border-highlight); border-radius: 99px; }

/* Topbar */
.topbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 800;
  font-size: 1.35rem;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 18px var(--accent-glow);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.4px;
}

.pro-badge {
  font-size: 0.68rem;
  background: var(--accent-glow);
  color: var(--accent);
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  vertical-align: middle;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.search-wrapper {
  flex: 1;
  max-width: 480px;
  position: relative;
}

.search-wrapper input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.65rem 4rem 0.65rem 2.5rem;
  border-radius: 11px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border 0.2s, box-shadow 0.2s;
}

.search-wrapper input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-icon {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
}

.shortcut-hint {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-family: 'JetBrains Mono', monospace;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.nav-pill-btn, .theme-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.5rem 0.9rem;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
}

.nav-pill-btn:hover, .theme-toggle:hover {
  border-color: var(--accent);
}

.mini-count {
  background: var(--accent);
  color: #fff;
  padding: 0.05rem 0.4rem;
  border-radius: 99px;
  font-size: 0.72rem;
}

/* Category Strip */
.category-strip {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 1.5rem;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
}

.cat-chip {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 0.42rem 0.9rem;
  border-radius: 9px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.cat-chip:hover {
  color: var(--text-main);
  background: var(--bg-input);
}

.cat-chip.active {
  background: var(--accent);
  color: #fff;
}

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 295px 1fr;
  flex: 1;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
}

/* Sidebar */
.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 115px);
  position: sticky;
  top: 115px;
}

@media (max-width: 960px) {
  .sidebar {
    max-height: 230px;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

.sidebar-header {
  padding: 0.9rem 1.1rem;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.badge-pill {
  background: var(--accent-glow);
  color: var(--accent);
  padding: 0.15rem 0.55rem;
  border-radius: 99px;
  font-size: 0.75rem;
}

.sidebar-list {
  padding: 0.7rem;
  overflow-y: auto;
  flex: 1;
}

.side-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 0.25rem;
  border: 1px solid transparent;
  transition: all 0.15s;
}

.side-item:hover {
  background: var(--bg-input);
}

.side-item.active {
  background: var(--accent-glow);
  border-color: var(--accent);
}

.side-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.side-meta h4 {
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.25;
}

.side-meta span {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Main Stage */
.main-stage {
  padding: 1.75rem;
  overflow-y: auto;
}

.hidden { display: none !important; }

/* Directory Hero & Bento Grid */
.hero-banner {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.16) 0%, rgba(236, 72, 153, 0.1) 100%);
  border: 1px solid var(--border-highlight);
  border-radius: 18px;
  padding: 1.8rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}

.hero-tag {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--bg-surface);
  padding: 0.3rem 0.75rem;
  border-radius: 99px;
  margin-bottom: 0.6rem;
  border: 1px solid var(--border);
}

.hero-content h1 {
  font-size: 1.7rem;
  font-weight: 800;
  margin-bottom: 0.4rem;
}

.hero-content p {
  color: var(--text-muted);
  font-size: 0.92rem;
  max-width: 580px;
}

.hero-stats {
  display: flex;
  gap: 1rem;
}

.stat-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 0.85rem 1.2rem;
  border-radius: 14px;
  text-align: center;
}

.stat-item strong {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--accent);
}

.stat-item span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.bento-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(275px, 1fr));
  gap: 1.1rem;
}

.bento-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 15px;
  padding: 1.3rem;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.bento-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.bento-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
}

.bento-icon {
  font-size: 1.75rem;
  background: var(--bg-input);
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
}

.bento-cat {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.22rem 0.6rem;
  border-radius: 99px;
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.bento-card h3 {
  font-size: 1.02rem;
  margin-bottom: 0.4rem;
}

.bento-card p {
  font-size: 0.83rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* Workspace Bar */
.workspace-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.86rem;
}

.crumb-link {
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

.crumb-sep, .crumb-cat { color: var(--text-muted); text-transform: capitalize; }
.crumb-current { font-weight: 700; }

.workspace-actions {
  display: flex;
  gap: 0.5rem;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.45rem 0.85rem;
  border-radius: 9px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover { border-color: var(--accent); }

/* Active Calculator Grid */
.calc-grid {
  display: grid;
  grid-template-columns: 1.08fr 0.92fr;
  gap: 1.5rem;
  align-items: start;
}

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

.surface-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.65rem;
  box-shadow: var(--shadow);
}

.calc-head {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 0.5rem;
}

.calc-head-icon {
  font-size: 2rem;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
}

.calc-head h2 {
  font-size: 1.35rem;
  font-weight: 800;
}

.calc-subdesc {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 1.4rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

/* Interactive Inputs & Range Sliders */
.input-block {
  margin-bottom: 1.25rem;
}

.input-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.45rem;
}

.input-top label {
  font-size: 0.86rem;
  font-weight: 600;
}

.unit-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  color: var(--accent);
  background: var(--accent-glow);
  padding: 0.12rem 0.5rem;
  border-radius: 6px;
  font-weight: 700;
}

.control-input, .control-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.72rem 0.95rem;
  border-radius: 10px;
  font-size: 0.98rem;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  outline: none;
  transition: border 0.2s;
}

.control-input:focus, .control-select:focus {
  border-color: var(--accent);
}

.range-slider {
  width: 100%;
  margin-top: 0.55rem;
  accent-color: var(--accent);
  cursor: pointer;
  height: 5px;
}

/* Output Result Card */
.hero-result-box {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(236, 72, 153, 0.12));
  border: 1px solid var(--accent);
  border-radius: 16px;
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 1.25rem;
}

.res-overline {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 700;
}

.res-main-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 2.2rem;
  font-weight: 800;
  margin: 0.4rem 0;
  color: var(--text-main);
  word-break: break-word;
}

.res-sub-badge {
  display: inline-block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--success);
  background: rgba(16, 185, 129, 0.12);
  padding: 0.25rem 0.75rem;
  border-radius: 99px;
}

/* Visual Ratio Progress Bar */
.visual-bar-wrap {
  margin-bottom: 1.3rem;
}

.visual-bar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.visual-bar-track {
  height: 10px;
  width: 100%;
  background: var(--bg-input);
  border-radius: 99px;
  overflow: hidden;
  display: flex;
  border: 1px solid var(--border);
}

.visual-bar-fill-a {
  background: var(--accent);
  height: 100%;
  transition: width 0.3s ease;
}

.visual-bar-fill-b {
  background: var(--accent-2);
  height: 100%;
  transition: width 0.3s ease;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1.2rem;
}

.kpi-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem;
}

.kpi-box span {
  display: block;
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.kpi-box strong {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
}

.formula-banner {
  background: var(--bg-input);
  border-left: 4px solid var(--accent);
  padding: 0.8rem 1rem;
  border-radius: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

.calc-btn-row {
  display: flex;
  gap: 0.65rem;
  margin-top: 1.2rem;
}

.btn-act {
  flex: 1;
  padding: 0.72rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-main);
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-act.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Scientific Keypad */
.sci-display {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem;
  text-align: right;
  margin-bottom: 1rem;
  font-family: 'JetBrains Mono', monospace;
}

.sci-expr { font-size: 0.88rem; color: var(--text-muted); min-height: 1.3rem; }
.sci-ans { font-size: 2rem; font-weight: 800; }

.sci-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
}

.sci-btn {
  padding: 0.8rem 0.3rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-main);
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
}

.sci-btn.op { color: var(--accent); background: var(--accent-glow); }
.sci-btn.eq { background: var(--accent); color: #fff; grid-column: span 2; }

/* History Log Panel */
.history-panel {
  margin-top: 1.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.2rem 1.5rem;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
}

.text-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
}

.history-list {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.3rem;
}

.history-chip {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  min-width: 210px;
  font-size: 0.8rem;
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--accent);
  color: var(--text-main);
  padding: 0.75rem 1.1rem;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

@media print {
  .topbar, .category-strip, .sidebar, .workspace-actions, .calc-btn-row, .history-panel {
    display: none !important;
  }
  .app-shell, .calc-grid { display: block; }
  body { background: #fff; color: #000; }
}