/* ==========================================================================
   Design System & Modern CSS Variables
   ========================================================================== */
:root {
  color-scheme: dark light;

  /* Color Palette */
  --bg-dark: #0a0d14;
  --card-bg: rgba(22, 27, 38, 0.85);
  --card-border: rgba(255, 255, 255, 0.08);
  --input-bg: rgba(15, 19, 28, 0.6);
  --input-border: rgba(255, 255, 255, 0.14);

  --accent-primary: #6366f1; /* Indigo */
  --accent-primary-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.25);
  
  --payer-dodo: #ec4899; /* Pink */
  --payer-dodo-glow: rgba(236, 72, 153, 0.2);
  --payer-rini: #06b6d4; /* Cyan */
  --payer-rini-glow: rgba(6, 182, 212, 0.2);

  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --status-success: #10b981;
  --status-warning: #f59e0b;
  --status-error: #ef4444;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-glow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px;
  position: relative;
  overflow-x: hidden;
  accent-color: var(--accent-primary);
}

.background-decor {
  position: fixed;
  top: -20%;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, rgba(236, 72, 153, 0.1) 40%, rgba(10, 13, 20, 0) 70%);
  pointer-events: none;
  z-index: -1;
}

.app-container {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
}

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

.brand-icon {
  font-size: 2rem;
  background: rgba(255, 255, 255, 0.05);
  padding: 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
}

.brand h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.825rem;
  color: var(--text-secondary);
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  color: var(--text-primary);
  font-size: 1.1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
}

/* Cards */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-glow);
}

@supports not (backdrop-filter: blur(1px)) {
  .card {
    background: #131824;
  }
}

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

.card-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

.sync-badge {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-online {
  background: rgba(16, 185, 129, 0.15);
  color: var(--status-success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-offline {
  background: rgba(245, 158, 11, 0.15);
  color: var(--status-warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Form Controls */
.expense-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.req {
  color: var(--payer-dodo);
}

input[type="number"],
input[type="text"],
input[type="date"],
input[type="url"],
select {
  width: 100%;
  min-height: 44px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: var(--transition);
}

input:focus, select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input:user-invalid {
  border-color: var(--status-error);
}

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

.currency-prefix {
  position: absolute;
  left: 16px;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent-primary);
}

.amount-input-wrapper input {
  padding-left: 38px;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #ffffff;
  min-height: 54px;
}

.error-msg {
  font-size: 0.75rem;
  color: var(--status-error);
  display: none;
  margin-top: 4px;
}

.error-msg.visible {
  display: block;
}

/* Segmented Controls */
.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
}

.segment-option {
  position: relative;
  cursor: pointer;
}

.segment-option input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.segment-label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: var(--transition);
}

.segment-option input:checked + .segment-label {
  background: var(--card-bg);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.segment-option input[value="Dodo"]:checked + .segment-label,
.segment-option input:checked + #labelPayer1 {
  border: 1px solid rgba(236, 72, 153, 0.4);
  color: #f472b6;
  background: var(--payer-dodo-glow);
}

.segment-option input[value="Rini"]:checked + .segment-label,
.segment-option input:checked + #labelPayer2 {
  border: 1px solid rgba(6, 182, 212, 0.4);
  color: #22d3ee;
  background: var(--payer-rini-glow);
}

.segment-option input[value="50%"]:checked + .segment-label,
.segment-option input[value="50/50"]:checked + .segment-label {
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: #a5b4fc;
  background: var(--accent-glow);
}

.optional-details {
  border-top: 1px dashed var(--card-border);
  padding-top: 12px;
}

.details-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
  padding: 6px 0;
  min-height: 40px;
}

.details-toggle::-webkit-details-marker {
  display: none;
}

.details-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--card-border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

.text-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 4px 8px;
}

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

/* Entries & Badges */
.entries-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.entry-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 19, 28, 0.4);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  transition: var(--transition);
}

.entry-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.entry-main {
  display: flex;
  align-items: center;
  gap: 12px;
}

.payer-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  text-transform: uppercase;
}

.split-tag {
  font-size: 0.7rem;
  padding: 2px 6px;
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  border-radius: 4px;
  margin-left: 4px;
}

.payer-dodo {
  background: rgba(236, 72, 153, 0.15);
  color: #f472b6;
  border: 1px solid rgba(236, 72, 153, 0.3);
}

.payer-rini {
  background: rgba(6, 182, 212, 0.15);
  color: #22d3ee;
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.entry-info {
  display: flex;
  flex-direction: column;
}

.entry-cat {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}

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

.entry-amount {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 24px 0;
}

/* Dialog & Backdrop */
dialog.modal {
  border: none;
  background: transparent;
  padding: 16px;
  max-width: 440px;
  width: 100%;
  margin: auto;
  opacity: 0;
  transform: scale(0.95);
  transition: 
    opacity 0.25s ease-out,
    transform 0.25s ease-out,
    overlay 0.25s allow-discrete,
    display 0.25s allow-discrete;
}

dialog.modal[open] {
  opacity: 1;
  transform: scale(1);
}

@starting-style {
  dialog.modal[open] {
    opacity: 0;
    transform: scale(0.95);
  }
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: 
    opacity 0.25s ease-out,
    overlay 0.25s allow-discrete,
    display 0.25s allow-discrete;
}

dialog.modal[open]::backdrop {
  opacity: 1;
}

@starting-style {
  dialog.modal[open]::backdrop {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  dialog.modal,
  dialog.modal::backdrop {
    transition-duration: 0.05s;
    transform: none;
  }

  @starting-style {
    dialog.modal[open] {
      transform: none;
    }
  }
}

.modal-content {
  background: #111522;
  border: 1px solid var(--card-border);
}

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

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.help-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.help-text a {
  color: var(--accent-primary);
}

.test-result {
  margin-top: 12px;
  font-size: 0.825rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}

.test-result.success {
  background: rgba(16, 185, 129, 0.15);
  color: var(--status-success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.test-result.error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--status-error);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 21, 34, 0.95);
  border: 1px solid var(--card-border);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  font-size: 0.9rem;
  z-index: 1000;
  transition: var(--transition);
}

.hidden {
  display: none !important;
}

.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
