:root {
  --bg: #eef2f6;
  --card: #ffffff;
  --text: #17202b;
  --muted: #64748c;
  --border: #dbe3ec;
  --input-bg: #f6f8fb;
  --primary: #5b21b6;
  --primary-dark: #4c1d95;
  --primary-light: #7c3aed;
  --danger: #d64545;
  --warn: #e6a23c;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141a;
    --card: #1a212b;
    --text: #e8edf3;
    --muted: #94a1b5;
    --border: #2b333f;
    --input-bg: #131a22;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

[data-theme="dark"] {
  --bg: #0f141a;
  --card: #1a212b;
  --text: #e8edf3;
  --muted: #94a1b5;
  --border: #2b333f;
  --input-bg: #131a22;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(900px 320px at 50% -80px, rgba(91, 33, 182, 0.1), transparent), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: calc(104px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px 12px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: linear-gradient(135deg, #2e1065, #4c1d95 55%, #6d28d9);
  color: #fff;
  box-shadow: 0 2px 14px rgba(30, 12, 70, 0.28);
}

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

.brand h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.2px;
}

.logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.16);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.top-icon {
  margin-left: auto;
  color: #fff;
}

.top-icon:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.tabs {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 4px;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.tab.active {
  background: #fff;
  color: var(--primary-dark);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 14px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
  animation: rise 0.35s ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grid3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.span2 {
  grid-column: span 2;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

input,
select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  min-height: 46px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 33, 182, 0.15);
}

.btn {
  font: inherit;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  min-height: 46px;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  box-shadow: 0 4px 14px rgba(91, 33, 182, 0.35);
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.btn.ghost {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.btn.danger-ghost {
  background: transparent;
  color: var(--danger);
  border: 1.5px solid var(--danger);
}

.btn.wide {
  width: 100%;
}

.btn.small-btn {
  padding: 7px 12px;
  min-height: 36px;
  font-size: 0.85rem;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--input-bg);
  color: var(--text);
}

.session-title {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.82rem;
}

.empty {
  text-align: center;
  padding: 20px 10px;
}

.illu {
  width: 56px;
  height: 56px;
  display: block;
  margin: 0 auto 8px;
  opacity: 0.35;
}

.budget-card {
  display: flex;
  align-items: center;
  gap: 14px;
}

.ring-wrap {
  position: relative;
  width: 76px;
  height: 76px;
  flex-shrink: 0;
}

.ring {
  width: 100%;
  height: 100%;
}

.ring circle {
  fill: none;
  stroke-width: 7;
}

.ring-track {
  stroke: var(--border);
}

.ring-fill {
  stroke: var(--primary);
  stroke-dasharray: 163.36;
  stroke-dashoffset: 163.36;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: center;
  transition: stroke-dashoffset 0.5s ease, stroke 0.3s ease;
}

.ring-fill.warn {
  stroke: var(--warn);
}

.ring-fill.over {
  stroke: var(--danger);
}

.ring-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.95rem;
}

.budget-info {
  flex: 1;
  min-width: 0;
}

.budget-input {
  max-width: 120px;
  text-align: right;
}

.chip {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.chip.ok {
  background: rgba(91, 33, 182, 0.12);
  color: var(--primary);
}

.chip.bad {
  background: rgba(214, 69, 69, 0.12);
  color: var(--danger);
}

.deal {
  border-top: 1px dashed var(--border);
  margin: 4px 0 12px;
  padding-top: 10px;
}

.deal summary {
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 10px;
}

.list-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.list-actions .btn {
  flex: 1;
  min-width: 110px;
  padding-left: 8px;
  padding-right: 8px;
}

.item-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.item.enter {
  animation: rise 0.3s ease both;
}

.item.removing {
  opacity: 0;
  transform: translateX(36px);
}

.item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.item-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.item-side {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.item-side strong {
  font-variant-numeric: tabular-nums;
}

.item-actions {
  display: flex;
  gap: 2px;
}

.edit-form .e-name {
  grid-column: 1 / -1;
}

.edit-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
}

.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 999px;
  padding: 2px 8px;
  vertical-align: middle;
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-card.enter {
  animation: rise 0.3s ease both;
}

.active-session {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary), var(--shadow);
}

.totalbar {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 488px;
  margin: 0 auto;
  padding: 13px 20px;
  border-radius: 18px;
  background: linear-gradient(135deg, #2e1065, #6d28d9);
  color: #fff;
  box-shadow: 0 12px 32px rgba(30, 12, 70, 0.45);
}

.tb-left {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.tb-label {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.75;
}

#totalCount {
  font-size: 0.82rem;
  opacity: 0.9;
}

.totalbar strong {
  font-size: 1.35rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 30;
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  background: #1c2430;
  color: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-size: 0.88rem;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
  pointer-events: auto;
}

.toast-btn {
  font: inherit;
  font-weight: 800;
  color: #fff;
  background: var(--primary-light);
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(10, 16, 24, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.2s ease;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.modal-box {
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  animation: sheetUp 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes sheetUp {
  from {
    transform: translateY(48px);
    opacity: 0.5;
  }
}

.modal-head h2 {
  font-size: 1.1rem;
}

.compare-row {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  margin-top: 8px;
}

.compare-row .bar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  background: rgba(91, 33, 182, 0.08);
  z-index: 0;
  transition: width 0.4s ease;
}

.compare-row.best {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.compare-row.best .bar {
  background: rgba(91, 33, 182, 0.16);
}

.compare-row > *:not(.bar) {
  position: relative;
  z-index: 1;
}

.delta {
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 600;
}

.footer {
  text-align: center;
  padding: 8px 0 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  opacity: 0.85;
}

#compareResults {
  margin-top: 6px;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
