/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@media (max-width: 600px) {
  html {
    font-size: 14px;
  }
}

/* ============================================
   CSS VARIABLES - THEME CONFIGURATION
   ============================================ */
:root {
  /* Light theme (default) */
  --primary: #2563eb;
  --primary-light: #3b82f6;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --person1-color: #2563eb;
  --person2-color: #10b981;
  
  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  
  /* Typography */
  --font-family: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  
  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s ease;
  --transition-slow: 0.4s ease;
}

/* Dark theme override */
[data-theme="dark"] {
  --bg: #1e2127;
  --card-bg: #282c34;
  --text: #e6e9f0;
  --text-muted: #a0a5b0;
  --border: #4b515d;
  --primary: #7aa2f7;
  --primary-light: #89b4fa;
  --person1-color: #7aa2f7;
  --person2-color: #9ece6a;
}

/* ============================================
   BASE STYLES
   ============================================ */
html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
  background-image: 
    radial-gradient(ellipse at 30% 30%, rgba(99, 102, 241, 0.4) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 70%, rgba(16, 185, 129, 0.35) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 100%, rgba(236, 72, 153, 0.25) 0%, transparent 50%);
}

[data-theme="dark"] body {
  background-image: 
    radial-gradient(ellipse at 25% 25%, rgba(122, 162, 247, 0.25) 0%, transparent 50%),
    radial-gradient(ellipse at 75% 75%, rgba(158, 206, 106, 0.2) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 10%, rgba(168, 85, 247, 0.18) 0%, transparent 40%);
}

/* ============================================
   THEME TOGGLE SWITCH
   ============================================ */
.theme-toggle {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  z-index: 100;
}

.theme-toggle input {
  display: none;
}

.toggle-switch {
  position: relative;
  width: 64px;
  height: 32px;
  background: linear-gradient(135deg, rgba(255,255,255,0.7), rgba(255,255,255,0.4));
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 16px;
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  box-shadow: 
    0 8px 24px rgba(0, 0, 0, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  cursor: pointer;
  transition: all var(--transition-normal);
  display: flex;
  align-items: center;
  padding: 0 4px;
}

.toggle-switch::before {
  content: '';
  position: absolute;
  width: 26px;
  height: 26px;
  background: linear-gradient(135deg, #fff, #f0f0f0);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition-normal);
  left: 2px;
}

.toggle-icons {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 0 6px;
  pointer-events: none;
}

.toggle-icons img {
  width: 16px;
  height: 16px;
  opacity: 0.4;
  transition: opacity var(--transition-normal);
}

[data-theme="dark"] .toggle-switch {
  background: linear-gradient(135deg, rgba(55, 60, 70, 0.8), rgba(40, 44, 52, 0.7));
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .toggle-switch::before {
  transform: translateX(32px);
  background: linear-gradient(135deg, #7aa2f7, #89b4fa);
}

[data-theme="dark"] .toggle-icons .icon-sun { opacity: 0.3; }
[data-theme="dark"] .toggle-icons .icon-moon { opacity: 1; }

.toggle-icons .icon-moon {
  opacity: 1;
  filter: brightness(0.4);
}

.toggle-icons .icon-sun { opacity: 1; }

[data-theme="dark"] .toggle-icons .icon-sun {
  opacity: 1;
  filter: invert(1);
}

[data-theme="dark"] .toggle-icons .icon-moon {
  opacity: 1;
  filter: none;
}

/* ============================================
   LAYOUT
   ============================================ */
.layout {
  display: flex;
  gap: var(--space-lg);
  align-items: stretch;
  max-width: 1100px;
  width: 100%;
  justify-content: center;
}

.layout.show-results {
  justify-content: flex-start;
}

/* ============================================
   CARDS
   ============================================ */
.card {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.75) 0%,
    rgba(255, 255, 255, 0.55) 100%
  );
  backdrop-filter: blur(24px) saturate(200%);
  -webkit-backdrop-filter: blur(24px) saturate(200%);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: 
    0 12px 40px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    inset 0 -1px 0 rgba(255, 255, 255, 0.2);
  flex: 1;
  display: flex;
  flex-direction: column;
}

[data-theme="dark"] .card {
  background: linear-gradient(
    135deg,
    rgba(40, 44, 52, 0.7) 0%,
    rgba(30, 33, 39, 0.55) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 
    0 12px 40px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.input-card {
  max-width: 500px;
  flex: 0 0 500px;
}

.result-card {
  display: none;
  flex: 0 0 500px;
  max-width: 500px;
}

.result-card.show {
  display: flex;
  animation: slideIn var(--transition-slow) ease;
}

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

/* ============================================
   HEADER
   ============================================ */
.header {
  text-align: center;
  margin-bottom: 1rem;
}

.header h1 {
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.80rem;
  letter-spacing: -0.02em;
}

.header p {
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.result-header { margin-bottom: 0.75rem; }

.result-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

/* ============================================
   FORM ELEMENTS
   ============================================ */
.input-group {
  margin-bottom: 1rem;
}

.input-group label {
  display: block;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
}

.input-wrapper {
  position: relative;
}

.input-wrapper span {
  position: absolute;
  left: var(--space-md);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1rem;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  z-index: 1;
}

.input-wrapper input {
  width: 100%;
  padding: 14px var(--space-md);
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.5);
  color: var(--text);
  transition: all var(--transition-normal);
  backdrop-filter: blur(8px);
}

[data-theme="dark"] .input-wrapper input {
  background: rgba(20, 22, 27, 0.5);
  border-color: rgba(255, 255, 255, 0.1);
}

.input-wrapper input:hover {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.7);
}

[data-theme="dark"] .input-wrapper input:hover {
  background: rgba(40, 44, 52, 0.7);
}

.input-wrapper input:focus {
  background: rgba(255, 255, 255, 0.8);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(122, 162, 247, 0.2);
}

[data-theme="dark"] .input-wrapper input:focus {
  background: rgba(40, 44, 52, 0.8);
}

[data-theme="dark"] .input-wrapper input {
  background: rgba(30, 33, 39, 0.75);
}

.input-wrapper input:hover {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.9);
}

[data-theme="dark"] .input-wrapper input:hover {
  background: rgba(40, 44, 52, 0.9);
}

.input-wrapper input::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}

.input-wrapper input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(122, 162, 247, 0.2);
}

.input-wrapper input[id="expenseName"] { padding-left: var(--space-md); }
.input-wrapper input:not([id="expenseName"]) { padding-left: 36px; }

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  width: 100%;
  padding: 0.875rem 1.25rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 0.625rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-normal), transform var(--transition-fast);
  margin-top: 0.75rem;
}

.btn:hover { background: var(--primary-light); }
.btn:active { transform: scale(0.98); }

.btn-reset {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  margin-top: 0.5rem;
}

.btn-reset:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text);
  border-color: var(--text-muted);
}

[data-theme="dark"] .btn-reset:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* ============================================
   RESULTS SECTION
   ============================================ */
.result-section {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow: hidden;
}

.result-person {
  padding: 0.875rem;
  background: var(--bg);
  border-radius: 0.625rem;
}

.person-name {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.person-amount {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.person-percent {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin-bottom: 0.625rem;
}

/* Progress bars */
.bar-container {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease;
}

.bar-1 { background: var(--person1-color); }
.bar-2 { background: var(--person2-color); }

/* Total section */
.result-total {
  margin-top: 0.25rem;
  padding: 0.625rem;
  background: var(--bg);
  border-radius: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.total-label {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-muted);
}

.total-amount {
  font-size: 1.25rem;
  font-weight: 700;
}

/* Formula section */
.result-formula { margin-top: 0.5rem; }

.formula-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.625rem;
}

.formula-card {
  background: var(--bg);
  border-radius: 0.5rem;
  padding: 0.625rem;
  margin-bottom: 0.5rem;
}

.formula-card:last-child { margin-bottom: 0; }

.formula-card-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 0.375rem;
}

.formula-card-content {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.formula-card-content div { margin-bottom: 0.125rem; }

.formula-card-content strong {
  color: var(--text);
  font-weight: 600;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 800px) {
  html, body {
    height: auto;
    min-height: 100%;
    overflow: auto;
  }
  
  body {
    padding: 12px;
    display: block;
  }
  
  .layout {
    flex-direction: column;
    align-items: center;
    justify-content: center !important;
    gap: 12px;
    height: auto;
    max-height: none;
    padding: 10px 0;
  }
  
  .layout.show-results { justify-content: center !important; }
  
  .input-card,
  .result-card {
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    padding: 16px;
    max-height: none;
  }
  
  .result-card.show {
    animation: slideInMobile var(--transition-slow) ease;
  }
  
  @keyframes slideInMobile {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
  }
}