:root {
      color-scheme: dark;
      --bg: #080b12;
      --bg-elevated: #0d111b;
      --surface: rgba(18, 24, 38, 0.84);
      --surface-solid: #121826;
      --surface-soft: #171e2e;
      --surface-hover: #1c2538;
      --line: rgba(148, 163, 184, 0.14);
      --line-strong: rgba(148, 163, 184, 0.24);
      --text: #f8fafc;
      --text-soft: #cbd5e1;
      --muted: #8491a7;
      --accent: #8b5cf6;
      --accent-2: #22d3ee;
      --accent-soft: rgba(139, 92, 246, 0.15);
      --accent-line: rgba(139, 92, 246, 0.42);
      --positive: #34d399;
      --negative: #fb7185;
      --warning: #fbbf24;
      --danger: #fb7185;
      --danger-soft: rgba(251, 113, 133, 0.12);
      --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
      --radius-xl: 24px;
      --radius-lg: 18px;
      --radius-md: 13px;
      --radius-sm: 10px;
    }

    * {
      box-sizing: border-box;
    }

    html {
      min-height: 100%;
      background: var(--bg);
    }

    body {
      margin: 0;
      min-height: 100vh;
      min-height: 100dvh;
      overflow-x: hidden;
      background:
        radial-gradient(circle at 13% -8%, rgba(139, 92, 246, 0.23), transparent 34rem),
        radial-gradient(circle at 96% 8%, rgba(34, 211, 238, 0.14), transparent 28rem),
        linear-gradient(180deg, #080b12 0%, #0a0e17 45%, #080b12 100%);
      color: var(--text);
      font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      -webkit-font-smoothing: antialiased;
      text-rendering: optimizeLegibility;
    }

    body::before {
      content: "";
      position: fixed;
      inset: 0;
      pointer-events: none;
      opacity: 0.035;
      background-image:
        linear-gradient(rgba(255,255,255,.5) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.5) 1px, transparent 1px);
      background-size: 32px 32px;
      mask-image: linear-gradient(to bottom, black, transparent 68%);
    }

    button,
    input {
      font: inherit;
    }

    button {
      -webkit-tap-highlight-color: transparent;
    }

    .app {
      width: min(100% - 28px, 980px);
      margin: 0 auto;
      padding:
        max(28px, env(safe-area-inset-top))
        0
        max(64px, calc(36px + env(safe-area-inset-bottom)));
    }

    .hero {
      display: flex;
      align-items: flex-end;
      justify-content: space-between;
      gap: 24px;
      margin: 4px 2px 26px;
    }

    .eyebrow {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      margin-bottom: 12px;
      color: #c4b5fd;
      font-size: 0.74rem;
      font-weight: 900;
      letter-spacing: 0.16em;
      text-transform: uppercase;
    }

    .eyebrow::before {
      content: "";
      width: 20px;
      height: 2px;
      border-radius: 999px;
      background: linear-gradient(90deg, var(--accent), var(--accent-2));
      box-shadow: 0 0 18px rgba(139, 92, 246, 0.7);
    }

    h1 {
      margin: 0;
      font-size: clamp(2.35rem, 8vw, 4.75rem);
      line-height: 0.92;
      letter-spacing: -0.065em;
      font-weight: 900;
    }

    .hero-copy {
      margin: 16px 0 0;
      max-width: 560px;
      color: var(--muted);
      font-size: clamp(0.92rem, 2.2vw, 1.03rem);
      line-height: 1.65;
    }

    .rate-chip {
      display: flex;
      flex-direction: column;
      align-items: flex-end;
      gap: 3px;
      flex: 0 0 auto;
      padding: 12px 14px;
      border: 1px solid var(--line);
      border-radius: 14px;
      background: rgba(18, 24, 38, 0.68);
      box-shadow: inset 0 1px 0 rgba(255,255,255,.035);
      backdrop-filter: blur(14px);
    }

    .rate-chip span {
      color: var(--muted);
      font-size: 0.68rem;
      font-weight: 850;
      letter-spacing: 0.11em;
      text-transform: uppercase;
    }

    .rate-chip strong {
      font-size: 0.92rem;
      font-variant-numeric: tabular-nums;
    }

    .panel {
      border: 1px solid var(--line);
      border-radius: var(--radius-xl);
      background:
        linear-gradient(145deg, rgba(255,255,255,.025), transparent 38%),
        var(--surface);
      box-shadow:
        var(--shadow),
        inset 0 1px 0 rgba(255, 255, 255, 0.035);
      backdrop-filter: blur(20px);
    }

    .entry-panel {
      position: relative;
      overflow: hidden;
      padding: 24px;
      margin-bottom: 20px;
    }

    .entry-panel::after {
      content: "";
      position: absolute;
      width: 210px;
      height: 210px;
      top: -130px;
      right: -100px;
      border-radius: 50%;
      background: rgba(139, 92, 246, 0.22);
      filter: blur(42px);
      pointer-events: none;
    }

    .panel-title-row {
      position: relative;
      z-index: 1;
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 12px;
      margin-bottom: 20px;
    }

    .panel-title {
      margin: 0;
      font-size: 1rem;
      font-weight: 850;
      letter-spacing: -0.015em;
    }

    .edit-badge {
      display: none;
      padding: 6px 10px;
      border: 1px solid var(--accent-line);
      border-radius: 999px;
      background: var(--accent-soft);
      color: #ddd6fe;
      font-size: 0.72rem;
      font-weight: 850;
    }

    .edit-badge.visible {
      display: inline-flex;
    }

    .form-grid {
      position: relative;
      z-index: 1;
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 20px;
    }

    .field {
      display: flex;
      flex-direction: column;
      gap: 9px;
      min-width: 0;
    }

    .field.full {
      grid-column: 1 / -1;
    }

    label[for],
    .field-label {
      color: var(--text-soft);
      font-size: 0.78rem;
      font-weight: 850;
      letter-spacing: 0.035em;
    }

    input[type="text"],
    input[type="number"] {
      width: 100%;
      min-height: 52px;
      border: 1px solid var(--line-strong);
      border-radius: var(--radius-md);
      padding: 12px 14px;
      outline: none;
      background: rgba(5, 8, 15, 0.66);
      color: var(--text);
      caret-color: var(--accent-2);
      box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.28);
      transition:
        border-color 150ms ease,
        box-shadow 150ms ease,
        background 150ms ease;
    }

    input::placeholder {
      color: #566176;
    }

    input[type="text"]:hover,
    input[type="number"]:hover {
      border-color: rgba(148, 163, 184, 0.35);
      background: rgba(8, 12, 21, 0.83);
    }

    input[type="text"]:focus,
    input[type="number"]:focus {
      border-color: rgba(139, 92, 246, 0.75);
      background: rgba(8, 12, 21, 0.94);
      box-shadow:
        0 0 0 4px rgba(139, 92, 246, 0.13),
        0 0 32px rgba(139, 92, 246, 0.08);
    }

    .amount-hint {
      margin: -2px 1px 0;
      color: var(--muted);
      font-size: 0.72rem;
      line-height: 1.4;
    }

    fieldset {
      min-width: 0;
      margin: 0;
      padding: 0;
      border: 0;
    }

    legend {
      margin: 0 0 9px;
      padding: 0;
    }

    .segment {
      display: grid;
      grid-auto-flow: column;
      grid-auto-columns: 1fr;
      gap: 5px;
      padding: 5px;
      border: 1px solid var(--line);
      border-radius: 15px;
      background: rgba(5, 8, 15, 0.56);
    }

    .segment-option {
      position: relative;
      min-width: 0;
    }

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

    .segment-option label {
      display: flex;
      align-items: center;
      justify-content: center;
      min-height: 42px;
      padding: 8px 10px;
      border: 1px solid transparent;
      border-radius: 10px;
      color: var(--muted);
      font-size: 0.82rem;
      font-weight: 850;
      cursor: pointer;
      user-select: none;
      white-space: nowrap;
      transition:
        color 140ms ease,
        background 140ms ease,
        border-color 140ms ease,
        transform 100ms ease;
    }

    .segment-option input:checked + label {
      color: white;
      border-color: rgba(139, 92, 246, 0.34);
      background:
        linear-gradient(135deg, rgba(139, 92, 246, 0.24), rgba(34, 211, 238, 0.09)),
        #171d2b;
      box-shadow:
        0 6px 18px rgba(0, 0, 0, 0.24),
        inset 0 1px 0 rgba(255,255,255,.055);
    }

    .segment-option input:focus-visible + label {
      outline: 3px solid rgba(139, 92, 246, 0.28);
      outline-offset: 2px;
    }

    .segment-option label:active {
      transform: scale(0.98);
    }

    .form-actions {
      position: relative;
      z-index: 1;
      display: flex;
      align-items: center;
      gap: 10px;
      margin-top: 22px;
      flex-wrap: wrap;
    }

    button {
      min-height: 46px;
      border: 0;
      border-radius: 12px;
      padding: 10px 16px;
      font-weight: 850;
      cursor: pointer;
      transition:
        transform 100ms ease,
        background 150ms ease,
        border-color 150ms ease,
        opacity 150ms ease,
        box-shadow 150ms ease;
    }

    button:active {
      transform: translateY(1px) scale(0.99);
    }

    button:disabled {
      cursor: not-allowed;
      opacity: 0.45;
    }

    .button-primary {
      position: relative;
      overflow: hidden;
      color: white;
      background: linear-gradient(135deg, #7c3aed 0%, #8b5cf6 48%, #0891b2 125%);
      box-shadow:
        0 12px 28px rgba(124, 58, 237, 0.24),
        inset 0 1px 0 rgba(255,255,255,.16);
    }

    .button-primary:hover:not(:disabled) {
      box-shadow:
        0 15px 36px rgba(124, 58, 237, 0.33),
        inset 0 1px 0 rgba(255,255,255,.18);
    }

    .button-secondary {
      color: var(--text-soft);
      border: 1px solid var(--line);
      background: var(--surface-soft);
    }

    .button-secondary:hover:not(:disabled) {
      color: white;
      border-color: var(--line-strong);
      background: var(--surface-hover);
    }

    .button-danger {
      color: #fecdd3;
      border: 1px solid rgba(251, 113, 133, 0.22);
      background: var(--danger-soft);
    }

    .button-danger:hover:not(:disabled) {
      color: white;
      border-color: rgba(251, 113, 133, 0.4);
      background: rgba(251, 113, 133, 0.18);
    }

    .status {
      flex: 1 1 250px;
      min-height: 1.2em;
      color: var(--muted);
      font-size: 0.82rem;
      line-height: 1.45;
    }

    .status.success {
      color: var(--positive);
    }

    .status.error {
      color: var(--negative);
    }

    .summary-panel {
      overflow: hidden;
    }

    .summary-head {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 18px;
      padding: 22px 24px;
      border-bottom: 1px solid var(--line);
    }

    .summary-head h2 {
      margin: 0;
      font-size: 1.05rem;
      letter-spacing: -0.02em;
    }

    .total-box {
      text-align: right;
    }

    .total-label {
      display: block;
      margin-bottom: 3px;
      color: var(--muted);
      font-size: 0.65rem;
      font-weight: 900;
      letter-spacing: 0.13em;
      text-transform: uppercase;
    }

    .total-value {
      display: block;
      font-size: clamp(1.25rem, 4vw, 1.75rem);
      font-weight: 900;
      letter-spacing: -0.035em;
      font-variant-numeric: tabular-nums;
    }

    .total-value.negative,
    .amount-nok.negative {
      color: var(--negative);
    }

    .empty-state {
      display: grid;
      place-items: center;
      min-height: 240px;
      padding: 38px 24px;
      text-align: center;
    }

    .empty-icon {
      display: grid;
      place-items: center;
      width: 62px;
      height: 62px;
      margin-bottom: 16px;
      border: 1px solid var(--line);
      border-radius: 20px;
      background:
        linear-gradient(145deg, rgba(139,92,246,.12), rgba(34,211,238,.04)),
        var(--surface-soft);
      color: #c4b5fd;
      font-size: 1.5rem;
      box-shadow: inset 0 1px 0 rgba(255,255,255,.045);
    }

    .empty-state h3 {
      margin: 0;
      font-size: 1rem;
    }

    .empty-state p {
      margin: 8px 0 0;
      color: var(--muted);
      font-size: 0.86rem;
      line-height: 1.5;
    }

    .payer-group {
      padding: 0 24px;
    }

    .payer-group + .payer-group {
      border-top: 1px solid var(--line);
    }

    .payer-head {
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      gap: 16px;
      padding: 22px 0 10px;
    }

    .payer-name {
      display: flex;
      align-items: center;
      gap: 10px;
      margin: 0;
      font-size: 0.92rem;
      font-weight: 900;
    }

    .payer-avatar {
      display: grid;
      place-items: center;
      width: 30px;
      height: 30px;
      border: 1px solid var(--accent-line);
      border-radius: 10px;
      background: var(--accent-soft);
      color: #ddd6fe;
      font-size: 0.72rem;
      font-weight: 950;
    }

    .payer-total {
      color: var(--text-soft);
      font-size: 0.9rem;
      font-weight: 900;
      font-variant-numeric: tabular-nums;
    }

    .payer-total.negative {
      color: var(--negative);
    }

    .expense-row {
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto auto;
      align-items: center;
      gap: 16px;
      padding: 16px 0;
      border-top: 1px solid rgba(148, 163, 184, 0.09);
    }

    .expense-main {
      min-width: 0;
    }

    .expense-description {
      margin: 0;
      overflow-wrap: anywhere;
      font-size: 0.93rem;
      font-weight: 830;
      letter-spacing: -0.01em;
    }

    .expense-meta {
      display: flex;
      align-items: center;
      gap: 7px 10px;
      flex-wrap: wrap;
      margin-top: 7px;
      color: var(--muted);
      font-size: 0.73rem;
    }

    .category-tag {
      display: inline-flex;
      align-items: center;
      min-height: 23px;
      padding: 3px 8px;
      border: 1px solid var(--line);
      border-radius: 999px;
      background: rgba(255,255,255,.025);
      color: var(--text-soft);
      font-weight: 760;
    }

    .expense-amount {
      min-width: 112px;
      text-align: right;
      white-space: nowrap;
    }

    .amount-nok {
      display: block;
      font-size: 0.96rem;
      font-weight: 900;
      font-variant-numeric: tabular-nums;
    }

    .amount-original {
      display: block;
      margin-top: 4px;
      color: var(--muted);
      font-size: 0.71rem;
      font-variant-numeric: tabular-nums;
    }

    .row-actions {
      display: flex;
      gap: 7px;
    }

    .icon-button {
      display: grid;
      place-items: center;
      width: 38px;
      min-height: 38px;
      padding: 0;
      border: 1px solid var(--line);
      border-radius: 11px;
      background: rgba(255, 255, 255, 0.025);
      color: var(--muted);
    }

    .icon-button:hover {
      border-color: var(--line-strong);
      background: var(--surface-hover);
      color: white;
    }

    .icon-button.delete:hover {
      border-color: rgba(251, 113, 133, 0.34);
      background: var(--danger-soft);
      color: var(--negative);
    }

    .icon-button svg {
      width: 17px;
      height: 17px;
      fill: none;
      stroke: currentColor;
      stroke-linecap: round;
      stroke-linejoin: round;
      stroke-width: 1.8;
    }

    .utility-bar {
      display: grid;
      grid-template-columns: repeat(4, minmax(0, 1fr));
      gap: 10px;
      margin-top: 14px;
    }

    .utility-button {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      min-width: 0;
      padding: 10px 12px;
      font-size: 0.78rem;
      white-space: nowrap;
    }

    .utility-button svg {
      flex: 0 0 auto;
      width: 16px;
      height: 16px;
      fill: none;
      stroke: currentColor;
      stroke-linecap: round;
      stroke-linejoin: round;
      stroke-width: 1.9;
    }

    .footnote {
      margin: 17px 4px 0;
      color: #667085;
      font-size: 0.72rem;
      line-height: 1.55;
    }

    dialog {
      width: min(calc(100% - 32px), 430px);
      padding: 0;
      border: 1px solid var(--line-strong);
      border-radius: 20px;
      background: #111725;
      color: var(--text);
      box-shadow: 0 28px 90px rgba(0, 0, 0, 0.72);
    }

    dialog::backdrop {
      background: rgba(2, 4, 9, 0.76);
      backdrop-filter: blur(7px);
    }

    .dialog-body {
      padding: 23px 23px 18px;
    }

    .dialog-icon {
      display: grid;
      place-items: center;
      width: 44px;
      height: 44px;
      margin-bottom: 16px;
      border: 1px solid rgba(251, 113, 133, 0.25);
      border-radius: 14px;
      background: var(--danger-soft);
      color: var(--danger);
    }

    .dialog-icon svg {
      width: 21px;
      height: 21px;
      fill: none;
      stroke: currentColor;
      stroke-linecap: round;
      stroke-linejoin: round;
      stroke-width: 1.9;
    }

    .dialog-title {
      margin: 0;
      font-size: 1.12rem;
      letter-spacing: -0.02em;
    }

    .dialog-message {
      margin: 9px 0 0;
      color: var(--muted);
      font-size: 0.86rem;
      line-height: 1.55;
    }

    .dialog-actions {
      display: flex;
      justify-content: flex-end;
      gap: 9px;
      padding: 0 23px 23px;
    }

    .toast-stack {
      position: fixed;
      z-index: 50;
      right: max(18px, env(safe-area-inset-right));
      bottom: max(18px, calc(18px + env(safe-area-inset-bottom)));
      display: grid;
      gap: 10px;
      width: min(calc(100% - 36px), 390px);
      pointer-events: none;
    }

    .toast {
      display: flex;
      align-items: flex-start;
      gap: 10px;
      padding: 13px 14px;
      border: 1px solid var(--line-strong);
      border-radius: 14px;
      background: rgba(17, 23, 37, 0.96);
      color: var(--text-soft);
      box-shadow: 0 18px 50px rgba(0,0,0,.44);
      backdrop-filter: blur(16px);
      font-size: 0.82rem;
      line-height: 1.45;
      animation: toast-in 180ms ease-out;
    }

    .toast.success {
      border-color: rgba(52, 211, 153, 0.28);
    }

    .toast.error {
      border-color: rgba(251, 113, 133, 0.3);
    }

    .toast-dot {
      width: 8px;
      height: 8px;
      flex: 0 0 auto;
      margin-top: 5px;
      border-radius: 999px;
      background: var(--accent);
      box-shadow: 0 0 14px currentColor;
    }

    .toast.success .toast-dot {
      background: var(--positive);
    }

    .toast.error .toast-dot {
      background: var(--negative);
    }

    @keyframes toast-in {
      from {
        opacity: 0;
        transform: translateY(8px) scale(.98);
      }
      to {
        opacity: 1;
        transform: none;
      }
    }

    [hidden] {
      display: none !important;
    }

    @media (max-width: 760px) {
      .hero {
        align-items: flex-start;
        flex-direction: column;
      }

      .rate-chip {
        align-items: flex-start;
      }

      .form-grid {
        grid-template-columns: 1fr;
      }

      .field.full {
        grid-column: auto;
      }

      .utility-bar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }

      .expense-row {
        grid-template-columns: minmax(0, 1fr) auto;
      }

      .row-actions {
        grid-column: 1 / -1;
      }
    }

    @media (max-width: 470px) {
      .app {
        width: min(100% - 20px, 980px);
        padding-top: 20px;
      }

      .entry-panel,
      .summary-head {
        padding-left: 17px;
        padding-right: 17px;
      }

      .payer-group {
        padding: 0 17px;
      }

      .segment-option label {
        padding-inline: 7px;
        font-size: 0.76rem;
      }

      .expense-row {
        grid-template-columns: 1fr;
        gap: 9px;
      }

      .expense-amount {
        min-width: 0;
        text-align: left;
      }

      .amount-original {
        display: inline;
        margin-left: 8px;
      }

      .row-actions {
        grid-column: auto;
      }

      .utility-bar {
        grid-template-columns: 1fr;
      }

      .utility-button {
        justify-content: flex-start;
      }

      .form-actions > button {
        flex: 1 1 135px;
      }
    }

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