:root {
  /* Color Palette - Light Mode */
  --bg-color: #f3f4f6;
  --surface-color: rgba(255, 255, 255, 0.7);
  --surface-border: rgba(255, 255, 255, 0.5);
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --accent-color: #6366f1;
  --accent-hover: #4f46e5;
  --input-bg: rgba(255, 255, 255, 0.9);
  --input-border: #d1d5db;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --radius: 16px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --glass-blur: blur(16px);
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Color Palette - Dark Mode */
    --bg-color: #111827;
    --surface-color: rgba(31, 41, 55, 0.6);
    --surface-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f9fafb;
    --text-secondary: #9ca3af;
    --accent-color: #818cf8;
    --accent-hover: #6366f1;
    --input-bg: rgba(17, 24, 39, 0.8);
    --input-border: #4b5563;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  }
}

/* Explicit overrides if toggled manually (optional, for future) */
[data-theme='light'] {
  --bg-color: #f3f4f6;
  --surface-color: rgba(255, 255, 255, 0.7);
  --surface-border: rgba(255, 255, 255, 0.5);
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --accent-color: #6366f1;
  --accent-hover: #4f46e5;
  --input-bg: rgba(255, 255, 255, 0.9);
  --input-border: #d1d5db;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

[data-theme='dark'] {
  --bg-color: #111827;
  --surface-color: rgba(31, 41, 55, 0.6);
  --surface-border: rgba(255, 255, 255, 0.1);
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --accent-color: #818cf8;
  --accent-hover: #6366f1;
  --input-bg: rgba(17, 24, 39, 0.8);
  --input-border: #4b5563;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  transition: background-color 0.5s ease;
  overflow-x: hidden;
  position: relative;
}

/* Background Gradients */
body::before, body::after {
  content: '';
  position: absolute;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  filter: blur(80px);
  z-index: -1;
  opacity: 0.6;
}

body::before {
  top: -50px;
  left: -50px;
  background: var(--accent-color);
}

body::after {
  bottom: -50px;
  right: -50px;
  background: #ec4899; /* Pinkish gradient */
}

.app-container {
  width: 100%;
  max-width: 500px;
  background: var(--surface-color);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
  min-height: 500px;
}

.view {
  display: none;
  padding: 2rem;
  flex-direction: column;
  gap: 1.5rem;
  animation: fadeIn 0.3s ease;
}

.view.active {
  display: flex;
}

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

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(to right, var(--accent-color), #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.theme-toggle {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover {
  background: rgba(128, 128, 128, 0.1);
}

/* Category Selector (Custom Dropdown) */
.category-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
  z-index: 20; /* High z-index to appear above conversions */
}

label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.custom-dropdown {
  position: relative;
  width: 100%;
  border-radius: 0.75rem;
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  transition: var(--transition);
  cursor: pointer;
  outline: none;
  font-size: 1rem;
}

.custom-dropdown:focus, .custom-dropdown.open {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.dropdown-selected {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  gap: 0.75rem;
}

.dropdown-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-color);
  width: 20px;
  height: 20px;
}

.dropdown-text {
  flex-grow: 1;
  color: var(--text-primary);
  font-weight: 500;
  display: flex;
  flex-direction: column;
}

.dropdown-chevron {
  width: 1rem;
  height: 1rem;
  color: var(--text-secondary);
  transition: transform 0.3s ease;
}

.custom-dropdown.open .dropdown-chevron {
  transform: rotate(180deg);
}

.dropdown-list {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  background: var(--input-bg);
  border: 1px solid var(--surface-border);
  border-radius: 0.75rem;
  box-shadow: var(--shadow);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  max-height: 250px;
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: var(--transition);
  z-index: 100;
}

.custom-dropdown.open .dropdown-list {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  gap: 0.75rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
  color: var(--text-primary);
}

.dropdown-item:hover, .dropdown-item.focused {
  background-color: rgba(99, 102, 241, 0.1);
}

.dropdown-item.active {
  background-color: rgba(99, 102, 241, 0.2);
  color: var(--accent-color);
  font-weight: 600;
}

.dropdown-item svg {
  color: var(--accent-color);
}

/* Original select styles kept for other selects (like units) */
select {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border-radius: 0.75rem;
  border: 1px solid var(--input-border);
  background-color: var(--input-bg);
  color: var(--text-primary);
  appearance: none;
  outline: none;
  transition: var(--transition);
  font-family: inherit;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23888'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 1rem;
}

select:focus, input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Conversion Blocks */
.conversion-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: relative;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: rgba(128, 128, 128, 0.05);
  padding: 1rem;
  border-radius: 1rem;
  border: 1px solid transparent;
  transition: var(--transition);
}

.input-group:focus-within {
  border-color: var(--surface-border);
  background: rgba(128, 128, 128, 0.1);
}

input[type="number"] {
  width: 100%;
  background: transparent;
  border: none;
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  outline: none;
  font-family: inherit;
}

input[type="number"]::placeholder {
  color: var(--text-secondary);
  opacity: 0.5;
}

/* Remove arrows 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;
}

/* Unit Dropdowns */
.unit-dropdown {
  background-color: var(--surface-color);
  border: 1px solid var(--input-border);
  border-radius: 0.5rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.unit-dropdown:focus, .unit-dropdown.open {
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
  border-color: var(--accent-color);
}

.unit-selected {
  padding: 0.5rem 0.75rem;
  gap: 0.5rem;
}

.unit-selected .dropdown-text {
  font-size: 1rem;
  color: var(--text-primary);
  font-weight: 500;
}

.unit-dropdown .dropdown-list {
  left: 0;
  right: 0;
  min-width: 100%;
}

.unit-dropdown .dropdown-item {
  font-size: 1rem;
}

/* Base Select (still used for precision) */
select {
  padding: 0.5rem;
  font-size: 0.875rem;
  border-radius: 0.5rem;
  border: 1px solid var(--input-border);
  background-color: var(--input-bg);
  color: var(--text-primary);
  outline: none;
  font-family: inherit;
}

/* Swap Button */
.swap-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background: var(--accent-color);
  color: white;
  border: 4px solid var(--surface-color);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  transition: var(--transition);
  z-index: 10;
}

.swap-btn:hover {
  background: var(--accent-hover);
  transform: translate(-50%, -50%) rotate(180deg);
}

.swap-btn svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* Footer / Settings */
.settings-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--surface-border);
}

.precision-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.precision-control select {
  padding: 0.25rem 2rem 0.25rem 0.5rem;
  font-size: 0.875rem;
}

/* Floating Action Button */
.fab-btn {
  position: absolute;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background: var(--text-primary);
  color: var(--bg-color);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: var(--transition);
  z-index: 50;
}
.fab-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

/* ===================================== */
/*        PERCENTAGE VIEW STYLES         */
/* ===================================== */

/* Replace .pct-header with .app-header for common use */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: var(--transition);
}
.icon-btn:hover {
  background: rgba(128, 128, 128, 0.1);
}

.pct-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pct-dropdown {
  background: var(--input-bg);
  padding: 0.25rem 0;
}

.pct-mode-icon-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.15); /* Soft red for discount */
  color: #ef4444;
}

.pct-mode-text-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.pct-mode-subtext {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.pct-input-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.pct-input-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pct-input-inner {
  background: rgba(128, 128, 128, 0.05);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  border: 1px solid transparent;
  transition: var(--transition);
}

.pct-input-inner:focus-within {
  border-color: var(--accent-color);
  background: rgba(128, 128, 128, 0.1);
}

.pct-input-inner input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 1.25rem;
  font-weight: 600;
  font-family: inherit;
}

.pct-input-inner input::placeholder {
  color: var(--text-secondary);
  opacity: 0.5;
}

.pct-symbol {
  color: var(--text-secondary);
  font-weight: 600;
  margin-left: 0.5rem;
}

.pct-operator {
  color: var(--text-secondary);
  font-size: 1.5rem;
  font-weight: 300;
  margin-top: 1.5rem; /* align with inputs, skipping label */
}

.pct-desc-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
  padding-left: 1rem;
}

.pct-desc-row .corner-arrow {
  color: var(--text-secondary);
  opacity: 0.7;
}

.pct-desc-row #pctDescText {
  flex-grow: 1;
}

.pct-desc-row .help-icon {
  cursor: pointer;
}

.pct-results {
  background: rgba(128, 128, 128, 0.05);
  border-radius: 1rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 0.5rem;
}

.pct-results h3 {
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.pct-result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pct-res-label {
  color: var(--text-primary);
  font-weight: 500;
}

.pct-res-value {
  color: var(--text-primary);
  font-size: 1.25rem;
  font-weight: 700;
}

/* ===================================== */
/*           HOME GRID STYLES            */
/* ===================================== */

.home-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-top: 1rem;
}

.nav-card {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 1rem;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: var(--transition);
}

.nav-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent-color);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.nav-icon {
  width: 48px;
  height: 48px;
  background: rgba(99, 102, 241, 0.1);
  color: var(--accent-color);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.5rem;
}
.nav-icon svg {
  width: 24px;
  height: 24px;
}

.nav-card h3 {
  font-size: 1rem;
  color: var(--text-primary);
}

.nav-card p {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ===================================== */
/*     GENERIC CALC FORM STYLES          */
/* ===================================== */

.calc-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.input-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.input-box label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.input-box input {
  background: rgba(128, 128, 128, 0.05);
  border: 1px solid transparent;
  padding: 0.75rem;
  border-radius: 0.75rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  transition: var(--transition);
}

.input-box input:focus {
  border-color: var(--accent-color);
  background: rgba(128, 128, 128, 0.1);
  outline: none;
}

.styled-date::-webkit-calendar-picker-indicator {
  filter: invert(var(--icon-invert));
  cursor: pointer;
}

.date-units-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 0.5rem;
}

.tabs-row {
  display: flex;
  background: rgba(128, 128, 128, 0.05);
  border-radius: 0.75rem;
  padding: 0.25rem;
  margin-bottom: 1rem;
}

.tab-btn {
  flex: 1;
  padding: 0.5rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: var(--transition);
}

.tab-btn.active {
  background: var(--surface-color);
  color: var(--text-primary);
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.calc-results-card {
  background: rgba(128, 128, 128, 0.05);
  border-radius: 1rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: auto; /* Push to bottom if space allows */
}

.calc-results-card h3 {
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.primary-result {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-color);
}

.secondary-results {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border-top: 1px solid var(--surface-border);
  padding-top: 1rem;
}

.sec-res-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sec-res-item span:first-child {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.sec-res-item span:last-child {
  color: var(--text-primary);
  font-weight: 600;
}

/* Copy feedback */
.copy-feedback {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-primary);
  color: var(--bg-color);
  padding: 0.5rem 1.5rem;
  border-radius: 2rem;
  font-size: 0.875rem;
  font-weight: 600;
  opacity: 0;
  transition: var(--transition);
  pointer-events: none;
  z-index: 100;
}

.copy-feedback.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* History Drawer */
.history-drawer {
  position: fixed;
  top: 0;
  right: -100%;
  width: 100%;
  max-width: 400px;
  height: 100%;
  background: var(--surface-color);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  transition: right 0.3s ease-in-out;
  display: flex;
  flex-direction: column;
}

.history-drawer.open {
  right: 0;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--surface-border);
}

.history-header h2 {
  font-size: 1.25rem;
  color: var(--text-primary);
}

.history-actions {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--surface-border);
  display: flex;
  justify-content: flex-end;
}

.clear-history-btn {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.clear-history-btn:hover {
  background: rgba(239, 68, 68, 0.2);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.history-item {
  background: var(--bg-color);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.history-item-body {
  font-size: 1rem;
  color: var(--text-primary);
  font-weight: 500;
}

.history-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease-in-out;
}

.history-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 480px) {
  .app-container {
    padding: 1.5rem;
    border-radius: 24px;
  }
  
  input[type="number"] {
    font-size: 1.75rem;
  }
}
