/* ==========================================================================
   SmartCalc Modern Design System & Stylesheet
   Glassmorphism, Dark/Light Themes, Mobile-First Responsiveness, Micro-Interactions
   ========================================================================== */

:root {
  /* Light Theme Palette */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-input: #ffffff;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --accent-primary: #4f46e5;
  --accent-primary-hover: #4338ca;
  --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --accent-glow: rgba(79, 70, 229, 0.25);
  
  --success: #10b981;
  --success-bg: #ecfdf5;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --info: #06b6d4;
  
  /* Keypad Colors */
  --key-num-bg: #ffffff;
  --key-num-hover: #f1f5f9;
  --key-op-bg: #f1f5f9;
  --key-op-hover: #e2e8f0;
  --key-fn-bg: #ede9fe;
  --key-fn-text: #6d28d9;
  --key-equals-bg: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --key-equals-text: #ffffff;
  --key-clear-bg: #fee2e2;
  --key-clear-text: #b91c1c;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);
  --shadow-glow: 0 0 20px rgba(79, 70, 229, 0.25);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

[data-theme="dark"] {
  /* Dark Theme Palette */
  --bg-primary: #090d16;
  --bg-secondary: #0f172a;
  --bg-tertiary: #1e293b;
  --bg-card: rgba(15, 23, 42, 0.75);
  --bg-input: #1e293b;
  --border-color: #334155;
  --border-focus: #6366f1;
  
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  
  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --accent-glow: rgba(99, 102, 241, 0.35);
  
  --success: #34d399;
  --success-bg: rgba(16, 185, 129, 0.15);
  --warning: #fbbf24;
  --warning-bg: rgba(245, 158, 11, 0.15);
  --danger: #f87171;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --info: #38bdf8;

  /* Keypad Colors Dark */
  --key-num-bg: #1e293b;
  --key-num-hover: #334155;
  --key-op-bg: #1e293b;
  --key-op-hover: #334155;
  --key-fn-bg: #2e1065;
  --key-fn-text: #c4b5fd;
  --key-equals-bg: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --key-equals-text: #ffffff;
  --key-clear-bg: #450a0a;
  --key-clear-text: #fca5a5;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.3);
}

/* Base Reset & Typography */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Outfit', 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  transition: background-color 0.25s ease, color 0.25s ease;
  overflow-x: hidden;
}

/* App Container Layout */
.app-container {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* Sidebar (Desktop) */
.sidebar {
  width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 40;
  transition: all 0.3s ease;
}

.brand-header {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.brand-header:hover {
  background: var(--bg-tertiary);
}

.brand-header:hover .brand-icon {
  transform: scale(1.05);
}

.brand-header:active {
  transform: scale(0.98);
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 22px;
  font-weight: 800;
  box-shadow: var(--shadow-glow);
  transition: transform 0.2s ease;
}

.brand-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.nav-list {
  list-style: none;
  padding: 16px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.nav-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  transform: translateX(3px);
}

.nav-item.active {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: var(--shadow-glow);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Main Content Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
}

/* Top App Bar */
.top-bar {
  height: 64px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.page-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-title {
  font-size: 18px;
  font-weight: 700;
}

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

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--accent-primary);
}

/* Content Canvas */
.content-canvas {
  padding: 24px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

.module-view {
  width: 100%;
  animation: fadeIn 0.2s ease-in-out;
}

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

/* Bottom Navigation (Mobile) */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-color);
  z-index: 50;
  padding: 4px 8px;
  justify-content: space-around;
  align-items: center;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  flex: 1;
  text-align: center;
}

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

.bottom-nav-item svg {
  width: 20px;
  height: 20px;
}

/* Cards & Containers */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: var(--shadow-md);
}

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

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-field {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: all 0.2s;
}

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

.input-prefix {
  position: absolute;
  left: 14px;
  font-weight: 700;
  color: var(--text-muted);
  pointer-events: none;
}

.input-suffix {
  position: absolute;
  right: 14px;
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
}

.input-has-prefix {
  padding-left: 42px;
}

.input-has-suffix {
  padding-right: 42px;
}

.form-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Segmented Control / Variable Solvers */
.segmented-control {
  display: flex;
  background: var(--bg-tertiary);
  padding: 4px;
  border-radius: var(--radius-md);
  gap: 4px;
  border: 1px solid var(--border-color);
}

.segmented-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.segmented-btn.active {
  background: var(--bg-secondary);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .segmented-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
}

/* Calculator Keypad Grid */
.calc-wrapper {
  max-width: 480px;
  margin: 0 auto;
}

.calc-display {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 20px 24px;
  margin-bottom: 20px;
  text-align: right;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.calc-expression {
  font-size: 15px;
  color: var(--text-muted);
  min-height: 24px;
  margin-bottom: 6px;
  word-break: break-all;
  font-family: 'JetBrains Mono', monospace;
}

.calc-result {
  font-size: 38px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
  word-break: break-all;
  font-family: 'JetBrains Mono', monospace;
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.calc-grid-sci {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.calc-btn {
  min-height: 54px;
  min-width: 50px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  user-select: none;
}

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

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

.btn-op {
  background: var(--key-op-bg);
  color: var(--accent-primary);
  font-weight: 700;
}
.btn-op:hover {
  background: var(--key-op-hover);
}

.btn-fn {
  background: var(--key-fn-bg);
  color: var(--key-fn-text);
  font-size: 15px;
}
.btn-fn:hover {
  opacity: 0.9;
}

.btn-clear {
  background: var(--key-clear-bg);
  color: var(--key-clear-text);
}

.btn-equals {
  background: var(--key-equals-bg);
  color: var(--key-equals-text);
  font-size: 22px;
  font-weight: 800;
  box-shadow: var(--shadow-glow);
}

.btn-equals:hover {
  filter: brightness(1.1);
}

.btn-pill {
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-pill.active {
  background: var(--accent-gradient);
  color: #ffffff;
  border-color: transparent;
}

/* Accordion Steps */
.step-accordion {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  overflow: hidden;
  margin-top: 20px;
}

.step-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  background: var(--bg-tertiary);
  font-weight: 700;
  font-size: 15px;
}

.step-content {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.step-item {
  padding: 14px 18px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  border-left: 4px solid var(--accent-primary);
}

.step-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--accent-primary);
}

.step-formula {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.step-result {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
}

/* Data Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  margin-top: 20px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.data-table th {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 700;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: var(--bg-tertiary);
}

/* History Stack Drawer / Card */
.history-item {
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.history-item:hover {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
}

/* Buttons */
.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  border: none;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: var(--shadow-glow);
  transition: all 0.2s;
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--border-color);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 80px;
  right: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
  animation: toastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* Ad Container Units (Non-intrusive & Google AdSense Policy Compliant) */
.ad-container-bottom {
  margin-top: 32px;
  margin-bottom: 16px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  border: 1px dashed var(--border-color);
  text-align: center;
  position: relative;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ad-container-sidebar {
  margin: 12px 16px;
  padding: 10px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  border: 1px dashed var(--border-color);
  text-align: center;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ad-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 6px;
  user-select: none;
}

/* Touch & Responsive Optimizations */
.calc-btn, .btn-pill, .segmented-btn, .icon-btn, .btn-primary, .btn-secondary {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

/* Responsive Breakpoints */
@media (max-width: 900px) {
  .sidebar {
    display: none;
  }
  .bottom-nav {
    display: flex;
  }
  .content-canvas {
    padding: 16px;
    padding-bottom: 96px;
  }
  .calc-wrapper {
    max-width: 100%;
  }
  .top-bar {
    padding: 0 16px;
  }
}

@media (max-width: 480px) {
  .calc-btn {
    min-height: 48px;
    font-size: 16px;
  }
  .calc-result {
    font-size: 28px !important;
  }
  .calc-grid-sci {
    gap: 5px;
  }
  .calc-grid-sci .calc-btn {
    min-height: 44px;
    font-size: 13px;
  }
  .bottom-nav-item span {
    font-size: 10px;
  }
}

