:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --panel: #ffffff;
  --panel-soft: #f2f7f5;
  --ink: #1d2428;
  --muted: #68727a;
  --line: #dce3df;
  --teal: #0f766e;
  --teal-dark: #0a5c57;
  --coral: #c2412d;
  --amber: #c7861d;
  --mint: #dff3ea;
  --rose: #ffe4df;
  --shadow: 0 18px 45px rgba(30, 40, 36, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(115deg, rgba(15, 118, 110, 0.12), transparent 36%),
    linear-gradient(285deg, rgba(194, 65, 45, 0.09), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.icon-sprite {
  display: none;
}

.hidden {
  display: none !important;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(520px, 100%);
  padding: 24px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(220, 227, 223, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-card .brand {
  align-items: flex-start;
  margin-bottom: 22px;
}

.auth-card h1 {
  font-size: clamp(2.2rem, 12vw, 3.4rem);
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 5px;
  margin-bottom: 18px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.tab-button {
  min-height: 40px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-weight: 850;
}

.tab-button.active {
  color: var(--teal-dark);
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(30, 40, 36, 0.08);
}

.language-field {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
}

.language-field.compact {
  min-width: 132px;
  margin-bottom: 0;
}

.language-field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.language-field select {
  min-height: 44px;
  font-weight: 800;
}

.auth-form {
  display: grid;
  gap: 13px;
}

.link-button {
  width: fit-content;
  padding: 0;
  color: var(--teal-dark);
  background: transparent;
  border: 0;
  font-weight: 850;
  text-align: left;
}

.link-button:hover {
  text-decoration: underline;
}

.form-note {
  color: var(--muted);
  font-size: 0.92rem;
}

.reset-code-box {
  padding: 12px;
  background: #fff9ec;
  border: 1px solid rgba(199, 134, 29, 0.35);
  border-radius: var(--radius);
}

.reset-code-box span,
.reset-code-box strong {
  display: block;
}

.reset-code-box span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.reset-code-box strong {
  margin-top: 4px;
  font-size: 1.35rem;
  letter-spacing: 0.06em;
}

.secondary-submit {
  background: #17414d;
  border-color: #17414d;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 0 24px;
}

.profile-panel {
  margin-bottom: 18px;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.profile-form {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.profile-form h3 {
  margin: 0;
  font-size: 1rem;
}

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

.brand-mark {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  color: #ffffff;
  background: linear-gradient(145deg, var(--teal), #17414d);
  border-radius: 8px;
  box-shadow: 0 14px 28px rgba(15, 118, 110, 0.24);
}

.brand-mark svg {
  width: 28px;
  height: 28px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 4.4rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.brand p {
  max-width: 560px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 1rem;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.user-chip {
  display: grid;
  min-height: 44px;
  min-width: 190px;
  align-content: center;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.user-chip strong,
.user-chip span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip strong {
  line-height: 1.1;
}

.user-chip span {
  color: var(--muted);
  font-size: 0.78rem;
}

.icon-button,
.small-button,
.submit-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.icon-button {
  width: 44px;
  height: 44px;
  color: var(--ink);
  background: var(--panel);
  border-color: var(--line);
}

.icon-button:hover,
.small-button:hover,
.submit-button:hover {
  transform: translateY(-1px);
}

.icon-button.primary,
.submit-button {
  color: #ffffff;
  background: var(--teal);
  border-color: var(--teal);
}

.icon-button.primary:hover,
.submit-button:hover {
  background: var(--teal-dark);
}

.icon-button.subtle:hover {
  border-color: rgba(15, 118, 110, 0.5);
  color: var(--teal-dark);
}

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

.icon-button.danger:hover {
  background: var(--rose);
  border-color: rgba(194, 65, 45, 0.35);
}

.file-trigger {
  position: relative;
}

.file-trigger input {
  position: absolute;
  inset: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.workspace {
  display: grid;
  grid-template-columns: 0.85fr 1.2fr 1fr;
  gap: 18px;
  align-items: start;
}

.panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(220, 227, 223, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.paid-totals-panel,
.ledger-panel {
  grid-column: 1 / -1;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.eyebrow {
  display: block;
  margin-bottom: 3px;
  color: var(--teal-dark);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h2 {
  font-size: 1.1rem;
  letter-spacing: 0;
}

.count-pill {
  min-width: 34px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--mint);
  color: var(--teal-dark);
  font-weight: 800;
  text-align: center;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

input[inputmode="email"],
#currentUserEmail {
  direction: ltr;
  text-align: left;
}

.person-list {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.person-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 9px 10px 9px 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

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

.mini-icon {
  width: 34px;
  height: 34px;
  color: var(--muted);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.mini-icon:hover {
  color: var(--coral);
  border-color: rgba(194, 65, 45, 0.4);
}

.expense-form {
  display: grid;
  gap: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 12px;
}

label span,
legend {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 750;
}

.split-box {
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

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

.small-button {
  min-height: 34px;
  gap: 6px;
  padding: 7px 11px;
  color: var(--teal-dark);
  background: var(--mint);
  border-color: rgba(15, 118, 110, 0.22);
  font-size: 0.9rem;
  font-weight: 800;
}

.small-button.danger-soft {
  color: var(--coral);
  background: var(--rose);
  border-color: rgba(194, 65, 45, 0.25);
}

.app-layout {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.sidebar {
  display: grid;
  gap: 14px;
}

.activity-workspace {
  min-width: 0;
}

.activity-view {
  display: grid;
  gap: 18px;
}

.empty-activity {
  min-height: 220px;
}

.empty-activity p {
  margin-top: 8px;
  color: var(--muted);
}

.activity-list,
.invitation-list,
.pending-list {
  display: grid;
  gap: 8px;
}

.activity-card {
  display: grid;
  width: 100%;
  gap: 5px;
  padding: 12px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: left;
}

.activity-card.active {
  border-color: rgba(15, 118, 110, 0.55);
  box-shadow: inset 4px 0 0 var(--teal);
}

.activity-card-title {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 850;
}

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

.invitation-item {
  display: grid;
  gap: 7px;
  padding: 12px;
  background: #fff9ec;
  border: 1px solid rgba(199, 134, 29, 0.35);
  border-radius: var(--radius);
}

.invitation-item span {
  color: var(--muted);
  font-size: 0.84rem;
}

.row-actions,
.activity-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.activity-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.activity-hero h2 {
  font-size: 1.45rem;
}

.activity-hero p {
  margin-top: 5px;
  color: var(--muted);
}

.activity-actions {
  justify-content: flex-end;
}

.status-pill,
.role-tag,
.pending-invite {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 850;
}

.status-pill {
  color: var(--muted);
  background: #eef1ef;
}

.status-pill.draft {
  color: #7c570f;
  background: #fff2cc;
}

.status-pill.active {
  color: var(--teal-dark);
  background: var(--mint);
}

.status-pill.closed {
  color: var(--coral);
  background: var(--rose);
}

.role-tag.admin {
  color: var(--teal-dark);
  background: var(--mint);
}

.role-tag.member {
  color: var(--muted);
  background: #edf1f4;
}

.pending-invite {
  color: #7c570f;
  background: #fff2cc;
}

.split-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.split-option {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 40px;
  padding: 8px 10px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.split-option input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--teal);
}

.split-option span {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 0.95rem;
}

.submit-button {
  min-height: 48px;
  gap: 8px;
  padding: 12px 14px;
  font-weight: 850;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.metric {
  min-width: 0;
  padding: 13px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.metric strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-size: 1.08rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.paid-totals-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.paid-total-card {
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.paid-total-card.tone-1 {
  background: #eef8f4;
}

.paid-total-card.tone-2 {
  background: #fff6de;
}

.paid-total-card.tone-3 {
  background: #f1f4fb;
}

.paid-total-card.tone-4 {
  background: #ffecea;
}

.paid-total-name,
.calculation-row span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.paid-total-name {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.calculation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(104, 114, 122, 0.18);
}

.calculation-row span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.calculation-row strong {
  font-size: 0.95rem;
  text-align: right;
  white-space: nowrap;
}

.calculation-row.net strong {
  font-size: 1rem;
}

.balance-list,
.settlement-list {
  display: grid;
  gap: 8px;
}

.settlement-list {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.balance-row,
.settlement-row {
  display: grid;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.balance-row {
  grid-template-columns: 1fr;
}

.settlement-row {
  grid-template-columns: 1fr auto;
  background: #fff9ec;
}

.balance-name,
.settlement-text {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 750;
}

.balance-amount,
.settlement-amount {
  font-weight: 850;
  text-align: right;
  white-space: nowrap;
}

.balance-amount {
  text-align: left;
}

.positive {
  color: var(--teal-dark);
}

.negative {
  color: var(--coral);
}

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

.ledger-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

td {
  font-size: 0.95rem;
}

.amount-cell {
  font-weight: 850;
  text-align: right;
  white-space: nowrap;
}

.action-cell {
  width: 48px;
  text-align: right;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tag {
  max-width: 150px;
  padding: 4px 8px;
  overflow: hidden;
  color: var(--teal-dark);
  background: var(--mint);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  display: none;
  color: var(--muted);
}

.empty-state.visible {
  display: block;
  margin-top: 12px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(360px, calc(100% - 36px));
  padding: 12px 14px;
  color: #ffffff;
  background: #223036;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.print-report {
  display: none;
}

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

@media (max-width: 980px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

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

  .summary-panel,
  .paid-totals-panel,
  .ledger-panel {
    grid-column: 1 / -1;
  }
}

@media print {
  @page {
    margin: 14mm;
  }

  body {
    background: #ffffff;
    color: #111111;
    font-size: 11pt;
  }

  .app-shell,
  .toast {
    display: none !important;
  }

  .print-report {
    display: block;
  }

  .print-report header {
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 2px solid #111111;
  }

  .print-report h1 {
    margin: 0 0 6px;
    color: #111111;
    font-size: 24pt;
    line-height: 1.1;
  }

  .print-report h2 {
    margin: 18px 0 8px;
    color: #111111;
    font-size: 14pt;
  }

  .print-report p {
    color: #444444;
  }

  .print-metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 14px;
  }

  .print-metrics div {
    padding: 9px 10px;
    border: 1px solid #777777;
  }

  .print-metrics span {
    display: block;
    color: #555555;
    font-size: 9pt;
    font-weight: 700;
  }

  .print-metrics strong {
    display: block;
    margin-top: 4px;
    font-size: 13pt;
  }

  .print-report table {
    width: 100%;
    min-width: 0;
    margin-bottom: 8px;
    border-collapse: collapse;
    page-break-inside: auto;
  }

  .print-report tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }

  .print-report th,
  .print-report td {
    padding: 7px 6px;
    border: 1px solid #9a9a9a;
    color: #111111;
    font-size: 10pt;
    text-align: left;
    vertical-align: top;
  }

  .print-report th {
    background: #eeeeee !important;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: none;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 22px, 1180px);
    padding-top: 12px;
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .user-chip {
    min-width: min(100%, 230px);
  }

  h1 {
    font-size: clamp(2.2rem, 14vw, 3.4rem);
  }

  .workspace,
  .form-grid,
  .split-options,
  .metric-grid,
  .paid-totals-grid,
  .profile-grid {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 14px;
  }

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

  .activity-hero {
    align-items: flex-start;
    flex-direction: column;
  }
}

html[dir="rtl"] body {
  direction: rtl;
}

html[dir="rtl"] .brand,
html[dir="rtl"] .app-header,
html[dir="rtl"] .activity-hero,
html[dir="rtl"] .panel-heading,
html[dir="rtl"] .row-actions,
html[dir="rtl"] .activity-actions,
html[dir="rtl"] .header-actions {
  direction: rtl;
}

html[dir="rtl"] .activity-card {
  text-align: right;
}

html[dir="rtl"] .activity-card.active {
  box-shadow: inset -4px 0 0 var(--teal);
}

html[dir="rtl"] .amount-cell,
html[dir="rtl"] .balance-amount,
html[dir="rtl"] .settlement-amount,
html[dir="rtl"] .calculation-row strong {
  text-align: left;
}

html[dir="rtl"] input[type="date"],
html[dir="rtl"] #expenseAmount {
  direction: ltr;
  text-align: left;
}
