:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --ink: #101318;
  --muted: #667085;
  --line: #e3e6eb;
  --panel-soft: #f8fbff;
  --accent: #0e8f78;
  --accent-dark: #0c6f5f;
  --danger: #c2413a;
  --gold: #c98718;
  --blue: #3267e3;
  --violet: #6557d2;
  --shadow: 0 14px 34px rgba(16, 19, 24, 0.08);
  --soft-shadow: 0 8px 22px rgba(16, 19, 24, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(50, 103, 227, 0.08), transparent 260px),
    linear-gradient(135deg, rgba(14, 143, 120, 0.1), transparent 340px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.home-view {
  display: grid;
  gap: 16px;
}

.home-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 420px);
  gap: 24px;
  align-items: end;
  min-height: 260px;
  padding: 18px 0 24px;
}

.home-hero h1 {
  font-size: clamp(2.8rem, 7vw, 6rem);
}

.home-hero p {
  margin: 0;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.6;
}

.home-create-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 16px 18px 18px;
}

.home-create-form label span,
.session-owner-field span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.home-create-form .primary-button {
  width: auto;
  min-height: 46px;
  white-space: nowrap;
}

.trip-directory {
  display: grid;
  gap: 10px;
  padding: 0 18px 18px;
}

.trip-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.trip-card-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}

.trip-card h3 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 1.02rem;
}

.trip-owner-badge,
.trip-status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid rgba(50, 103, 227, 0.18);
  border-radius: 999px;
  background: rgba(50, 103, 227, 0.08);
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 900;
}

.trip-status-badge {
  border-color: rgba(15, 159, 122, 0.22);
  background: rgba(15, 159, 122, 0.09);
  color: var(--accent-dark);
}

.trip-card-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 86px;
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--soft-shadow);
  color: var(--ink);
}

.brand-lockup {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  color: #fff;
  font-weight: 900;
  box-shadow: none;
}

.header-trip-controls {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(190px, 1fr) minmax(170px, 0.75fr) auto;
  gap: 12px;
  align-items: end;
  width: min(860px, 62vw);
}

.header-trip-controls label span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.75rem, 4vw, 3rem);
  line-height: 1;
}

h2 {
  font-size: 1.02rem;
}

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

.trip-total {
  position: relative;
  z-index: 1;
  min-width: 180px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #fff, var(--panel-soft));
}

.trip-total span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.trip-total strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 1.45rem;
}

.session-bar {
  display: grid;
  grid-template-columns: auto minmax(320px, 1fr);
  gap: 12px;
  align-items: end;
  margin-bottom: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--soft-shadow);
}

.session-bar label span,
.share-link-field span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.session-actions {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 8px;
}

.session-actions .primary-button {
  width: auto;
  min-height: 42px;
}

.database-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  min-height: 34px;
  margin: 0 0 18px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.workflow-guide {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -8px 0 18px;
}

.workflow-guide span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.workflow-guide strong,
.step-badge {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  color: #fff;
  font-size: 0.74rem;
  font-weight: 900;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 135, 24, 0.14);
}

.database-status.connected {
  color: var(--accent-dark);
}

.database-status.connected .status-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 159, 122, 0.16);
}

.database-status.disconnected,
.database-status.error {
  color: var(--danger);
}

.database-status.disconnected .status-dot,
.database-status.error .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(220, 79, 69, 0.14);
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  box-shadow: none;
}

.danger-button {
  color: var(--danger);
}

.header-delete-button {
  min-height: 46px;
  white-space: nowrap;
}

.compact-button {
  min-height: 38px;
  padding: 0 12px;
  white-space: nowrap;
}

.share-link-field input {
  color: var(--muted);
  font-size: 0.86rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(250px, 0.78fr) minmax(390px, 1.35fr) minmax(310px, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--soft-shadow);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.section-title h2 {
  overflow-wrap: anywhere;
}

.add-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 16px 18px;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid #d6dde6;
  border-radius: 9px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.1);
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 9px;
  padding: 0 16px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  box-shadow: none;
}

.primary-button {
  width: 100%;
  min-height: 50px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
}

.primary-button:hover,
button:hover {
  filter: brightness(0.96);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  min-width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 1.35rem;
  line-height: 1;
  box-shadow: none;
}

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

.text-button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--accent-dark);
  font-size: 0.78rem;
  box-shadow: none;
}

.people-list,
.settlement-list {
  list-style: none;
  margin: 0;
  padding: 0 18px 18px;
}

.people-list li {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  border-top: 1px solid var(--line);
}

.people-list li:first-child {
  border-top: 0;
}

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(50, 103, 227, 0.08);
  border: 1px solid rgba(50, 103, 227, 0.18);
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 900;
}

.person-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.expense-form {
  display: grid;
  grid-template-columns: 1.25fr 0.75fr 1fr;
  gap: 12px;
  padding: 16px 18px 18px;
}

.expense-form label span,
legend {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

fieldset {
  grid-column: 1 / -1;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
}

legend {
  padding: 0 6px;
}

.split-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.split-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.split-list label {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-weight: 800;
}

.split-list input {
  width: 18px;
  min-height: 18px;
}

.expense-list {
  display: grid;
  gap: 10px;
  padding: 0 18px 18px;
}

.expense-item {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.expense-editor {
  display: grid;
  grid-template-columns: 1.25fr 0.75fr 1fr;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.expense-editor label span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.expense-editor fieldset {
  grid-column: 1 / -1;
}

.expense-editor-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.expense-editor-actions .primary-button {
  width: auto;
  min-height: 42px;
}

.expense-name {
  display: block;
  overflow-wrap: anywhere;
}

.expense-meta {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.expense-amount {
  color: var(--accent-dark);
  font-size: 1rem;
  font-weight: 900;
  white-space: nowrap;
}

.balances {
  display: grid;
  gap: 8px;
  padding: 16px 18px 0;
}

.settled-banner {
  margin: 16px 18px 0;
  padding: 12px;
  border: 1px solid rgba(15, 159, 122, 0.22);
  border-radius: 12px;
  background: rgba(15, 159, 122, 0.09);
  color: var(--accent-dark);
  font-weight: 900;
}

.balance-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 40px;
  padding: 0 2px;
  font-weight: 800;
}

.balance-row span:first-child {
  overflow-wrap: anywhere;
}

.balance-row.positive span:last-child {
  color: var(--accent-dark);
}

.balance-row.negative span:last-child {
  color: var(--danger);
}

.divider {
  height: 1px;
  margin: 16px 18px;
  background: var(--line);
}

.settlement-list {
  display: grid;
  gap: 10px;
}

.settlement-list li {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--danger);
  border-radius: 10px;
  background: #fff;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.settlement-list li.paid {
  border-left-color: var(--accent);
}

.settlement-list li input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.settlement-list li.paid span {
  color: var(--accent-dark);
}

.empty-state {
  margin: 0 18px 18px;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: rgba(248, 250, 252, 0.7);
  color: var(--muted);
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1060px) {
  .topbar {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .header-trip-controls {
    order: 3;
    width: 100%;
  }

  .home-hero,
  .home-create-form {
    grid-template-columns: 1fr;
  }

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

  .share-link-field {
    grid-column: 1 / -1;
  }

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

  .settlement-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 18px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    min-height: 0;
    padding: 20px;
  }

  .brand-lockup {
    align-items: flex-start;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
    flex-basis: 48px;
    border-radius: 12px;
  }

  .workspace,
  .expense-form,
  .session-bar {
    grid-template-columns: 1fr;
  }

  .header-trip-controls {
    grid-template-columns: 1fr;
  }

  .trip-card {
    grid-template-columns: 1fr;
  }

  .session-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .trip-total {
    min-width: 0;
  }

  .expense-item {
    grid-template-columns: 1fr auto;
  }

  .expense-editor {
    grid-template-columns: 1fr;
  }

  .expense-editor-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .expense-amount {
    grid-column: 1;
    grid-row: 2;
  }
}
