/* OmniCalc - Modern Design System */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  /* Dark Theme (Default) */
  --bg-app: #090d16;
  --bg-calculator: #111827;
  --bg-calculator-glass: rgba(17, 24, 39, 0.88);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);

  --display-bg: #030712;
  --display-text: #f9fafb;
  --display-expr: #9ca3af;

  /* Button Tokens */
  --btn-num-bg: #1f2937;
  --btn-num-text: #f3f4f6;
  --btn-num-hover: #374151;
  --btn-num-active: #4b5563;

  --btn-op-bg: #1e3a8a;
  --btn-op-text: #93c5fd;
  --btn-op-hover: #1d4ed8;
  --btn-op-active: #2563eb;

  --btn-fn-bg: #334155;
  --btn-fn-text: #e2e8f0;
  --btn-fn-hover: #475569;

  --btn-equals-bg: #059669;
  --btn-equals-text: #ffffff;
  --btn-equals-hover: #10b981;
  --btn-equals-active: #047857;

  --btn-sci-bg: #131c2e;
  --btn-sci-text: #94a3b8;
  --btn-sci-hover: #1e293b;
  --btn-sci-active: #334155;

  --btn-danger-text: #f87171;

  --panel-bg: rgba(15, 23, 42, 0.95);
  --badge-online: #10b981;
  --badge-offline: #ef4444;

  --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-xl: 28px;
  --shadow-main: 0 20px 45px -10px rgba(0, 0, 0, 0.6), 0 0 1px 1px var(--border-subtle);
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Light Theme */
body.light-theme {
  --bg-app: #e2e8f0;
  --bg-calculator: #ffffff;
  --bg-calculator-glass: rgba(255, 255, 255, 0.92);
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.15);

  --display-bg: #f8fafc;
  --display-text: #0f172a;
  --display-expr: #64748b;

  --btn-num-bg: #f1f5f9;
  --btn-num-text: #1e293b;
  --btn-num-hover: #e2e8f0;
  --btn-num-active: #cbd5e1;

  --btn-op-bg: #dbeafe;
  --btn-op-text: #1d4ed8;
  --btn-op-hover: #bfdbfe;
  --btn-op-active: #93c5fd;

  --btn-fn-bg: #e2e8f0;
  --btn-fn-text: #334155;
  --btn-fn-hover: #cbd5e1;

  --btn-equals-bg: #059669;
  --btn-equals-text: #ffffff;
  --btn-equals-hover: #10b981;
  --btn-equals-active: #047857;

  --btn-sci-bg: #f8fafc;
  --btn-sci-text: #475569;
  --btn-sci-hover: #f1f5f9;
  --btn-sci-active: #e2e8f0;

  --panel-bg: rgba(255, 255, 255, 0.97);
  --shadow-main: 0 20px 40px -15px rgba(0, 0, 0, 0.15), 0 0 1px 1px var(--border-subtle);
}

/* Base Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  min-height: 100vh;
  font-family: var(--font-main);
  background-color: var(--bg-app);
  color: var(--display-text);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  transition: background-color var(--transition-smooth);
}

/* App Wrapper */
.app-container {
  width: 100%;
  max-width: 440px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px;
  position: relative;
}

@media (min-width: 600px) {
  .app-container {
    min-height: auto;
    padding: 24px 0;
  }
}

/* Main Calculator Card */
.calculator-card {
  background: var(--bg-calculator-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-main);
  padding: 20px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Top Navigation Bar */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
}

.app-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.status-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-badge.online .status-dot {
  background-color: var(--badge-online);
  box-shadow: 0 0 6px var(--badge-online);
}

.status-badge.offline .status-dot {
  background-color: var(--badge-offline);
  box-shadow: 0 0 6px var(--badge-offline);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-pill-icon {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--display-text);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all var(--transition-fast);
}

.btn-pill-icon:hover {
  background: var(--btn-num-hover);
  border-color: var(--border-hover);
  transform: translateY(-1px);
}

.btn-pill-icon:active {
  transform: scale(0.95);
}

.btn-install {
  background: #2563eb;
  color: #ffffff;
  border: none;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all var(--transition-fast);
}

.btn-install:hover {
  background: #1d4ed8;
}

.btn-install.pulse {
  animation: pulse-glow 2s infinite;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.7); }
  50% { box-shadow: 0 0 0 8px rgba(37, 99, 235, 0); }
}

/* Mode Switch Tabs */
.mode-tabs {
  display: flex;
  background: var(--display-bg);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--display-expr);
  padding: 7px 10px;
  border-radius: calc(var(--radius-md) - 3px);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tab-btn.active {
  background: var(--btn-num-bg);
  color: var(--display-text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Display Screen */
.display-screen {
  background: var(--display-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 120px;
  position: relative;
}

.display-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  min-height: 20px;
}

.memory-indicator {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  padding: 2px 7px;
  border-radius: 6px;
}

.calc-expression {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--display-expr);
  text-align: right;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
  min-height: 1.2rem;
}

.calc-expression::-webkit-scrollbar {
  display: none;
}

.display-main-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px;
}

.btn-copy-mini {
  background: transparent;
  border: none;
  color: var(--display-expr);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  opacity: 0.5;
  transition: opacity var(--transition-fast);
}

.btn-copy-mini:hover {
  opacity: 1;
}

.calc-display-val {
  font-family: var(--font-mono);
  font-size: 3.2rem;
  font-weight: 700;
  line-height: 1;
  text-align: right;
  flex: 1;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
  letter-spacing: -0.03em;
}

.calc-display-val::-webkit-scrollbar {
  display: none;
}

/* Keypad Grids */
.keypad-grid {
  display: grid;
  gap: 10px;
}

.mem-grid {
  grid-template-columns: repeat(5, 1fr);
}

.sci-grid {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 2px;
}

.main-grid {
  grid-template-columns: repeat(4, 1fr);
}

/* Keypad Buttons */
.btn-calc {
  font-family: var(--font-main);
  font-size: 1.18rem;
  font-weight: 600;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.08s ease, background-color var(--transition-fast);
}

.btn-calc:active {
  transform: scale(0.94);
}

/* Button Variants */
.btn-num {
  background: var(--btn-num-bg);
  color: var(--btn-num-text);
  font-size: 1.35rem;
  font-weight: 600;
}

.btn-num:hover {
  background: var(--btn-num-hover);
}

.btn-op {
  background: var(--btn-op-bg);
  color: var(--btn-op-text);
  font-size: 1.45rem;
  font-weight: 700;
}

.btn-op:hover {
  background: var(--btn-op-hover);
  color: #ffffff;
}

.btn-fn {
  background: var(--btn-fn-bg);
  color: var(--btn-fn-text);
  font-size: 1.05rem;
  font-weight: 700;
}

.btn-fn:hover {
  background: var(--btn-fn-hover);
}

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

.btn-equals {
  background: var(--btn-equals-bg);
  color: var(--btn-equals-text);
  font-size: 1.5rem;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.4);
}

.btn-equals:hover {
  background: var(--btn-equals-hover);
}

.btn-mem {
  height: 38px;
  font-size: 0.78rem;
  font-weight: 700;
  background: transparent;
  color: var(--display-expr);
  border: 1px solid transparent;
}

.btn-mem:hover {
  background: var(--btn-num-bg);
  border-color: var(--border-subtle);
  color: var(--display-text);
}

.btn-sci {
  height: 42px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--btn-sci-bg);
  color: var(--btn-sci-text);
}

.btn-sci:hover {
  background: var(--btn-sci-hover);
  color: var(--display-text);
}

.btn-sci.active {
  background: #2563eb;
  color: #ffffff;
}

/* Sliding Panels (History & Converter) */
.sliding-panel {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--panel-bg);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border-radius: var(--radius-xl);
  z-index: 20;
  padding: 20px;
  display: flex;
  flex-direction: column;
  transform: translateY(102%);
  transition: transform var(--transition-smooth);
}

.sliding-panel.active {
  transform: translateY(0);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.panel-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
}

/* History List */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: var(--display-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.history-item:hover {
  background: var(--btn-num-bg);
  border-color: var(--border-hover);
}

.history-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--display-expr);
  font-family: var(--font-mono);
  margin-bottom: 4px;
}

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

.history-res {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--display-text);
}

.history-actions {
  display: flex;
  gap: 4px;
}

.btn-icon {
  background: transparent;
  border: none;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  opacity: 0.7;
}

.btn-icon:hover {
  opacity: 1;
  background: var(--btn-fn-bg);
}

.history-empty {
  text-align: center;
  padding: 40px 10px;
  color: var(--display-expr);
  font-size: 0.9rem;
}

/* Unit Converter UI */
.converter-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.conv-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.conv-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--display-expr);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.conv-select, .conv-input {
  background: var(--display-bg);
  color: var(--display-text);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-family: var(--font-main);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

.conv-select:focus, .conv-input:focus {
  border-color: #3b82f6;
}

.conv-swap-container {
  display: flex;
  justify-content: center;
}

.btn-conv-swap {
  background: var(--btn-num-bg);
  border: 1px solid var(--border-subtle);
  color: var(--display-text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-conv-swap:hover {
  background: var(--btn-op-bg);
  color: #fff;
}

.conv-result-card {
  background: var(--display-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conv-result-val {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 700;
  color: #38bdf8;
  word-break: break-all;
}

/* Toast Container */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(12px) scale(0.95);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}

.toast.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast-content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast-action {
  background: #3b82f6;
  color: #fff;
  border: none;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

/* Install Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-content {
  background: var(--bg-calculator);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-main);
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
}

.modal-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 16px;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 800;
}

.modal-desc {
  font-size: 0.88rem;
  color: var(--display-expr);
  line-height: 1.5;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.modal-btn-primary {
  flex: 1;
  background: #2563eb;
  color: #ffffff;
  border: none;
  padding: 12px;
  border-radius: var(--radius-md);
  font-weight: 700;
  cursor: pointer;
}

.modal-btn-secondary {
  background: var(--btn-num-bg);
  color: var(--display-text);
  border: 1px solid var(--border-subtle);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
}

/* Utilities */
.hidden {
  display: none !important;
}
