:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #697386;
  --soft: #f4f6f8;
  --line: #e6e9ee;
  --paper: #ffffff;
  --navy: #101827;
  --navy-soft: #1c2940;
  --gold: #c69a4b;
  --gold-soft: #f4ead8;
  --green: #168467;
  --green-soft: #e5f5ef;
  --red: #c24444;
  --red-soft: #fbeaea;
  --shadow: 0 16px 40px rgba(16, 24, 39, 0.1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--soft);
  color: var(--ink);
}

body { -webkit-font-smoothing: antialiased; }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--soft);
  padding-bottom: calc(82px + var(--safe-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 18px 10px;
  color: white;
  background: rgba(16, 24, 39, 0.96);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0;
  color: inherit;
  border: 0;
  background: transparent;
  text-align: left;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 43px;
  height: 43px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: -0.04em;
}
.brand-mark b { color: #e2b965; }
.brand-copy { font-size: 15px; font-weight: 700; }
.operator { max-width: 42%; color: #aeb8c8; font-size: 12px; text-align: right; }

.content { padding: 22px 16px 26px; }
.page-head { margin-bottom: 18px; }
.page-head h1 { margin: 3px 0 5px; font-size: 29px; line-height: 1.08; letter-spacing: -0.04em; }
.page-head p { margin: 0; color: var(--muted); font-size: 14px; }
.eyebrow { margin: 0; color: var(--gold); font-size: 11px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}

.summary-card {
  min-height: 123px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 8px 26px rgba(16, 24, 39, 0.04);
}
.summary-card.is-dark { color: white; border-color: var(--navy); background: var(--navy); }
.summary-card.is-alert { border-color: #f3d4d4; background: var(--red-soft); }
.summary-label { display: block; min-height: 34px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.is-dark .summary-label { color: #aeb8c8; }
.summary-value { display: block; margin-top: 8px; font-size: 25px; font-weight: 800; letter-spacing: -0.045em; }
.summary-meta { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }

.section { margin-top: 23px; }
.section-title { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-title h2 { margin: 0; font-size: 18px; letter-spacing: -0.025em; }
.section-title span { color: var(--muted); font-size: 12px; }

.item-list { display: grid; gap: 9px; }
.list-card {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--paper);
  text-align: left;
  color: inherit;
}
.list-card:active { transform: scale(0.988); }
.list-main { min-width: 0; }
.list-main strong { display: block; overflow: hidden; font-size: 14px; white-space: nowrap; text-overflow: ellipsis; }
.list-main small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.list-value { flex: 0 0 auto; text-align: right; }
.list-value b { display: block; font-size: 14px; }
.list-value small { color: var(--red); font-size: 10px; }

.search-box { position: sticky; top: 72px; z-index: 10; margin: -3px 0 15px; padding: 3px 0 8px; background: var(--soft); }
.search-box input {
  width: 100%;
  height: 49px;
  padding: 0 16px 0 43px;
  border: 1px solid var(--line);
  border-radius: 16px;
  outline: 0;
  background: var(--paper);
  color: var(--ink);
}
.search-box input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.search-box::before { content: "⌕"; position: absolute; left: 16px; top: 13px; color: var(--muted); font-size: 24px; }

.client-list { display: grid; gap: 10px; }
.client-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 7px 22px rgba(16, 24, 39, 0.035);
  cursor: pointer;
}
.client-card:active { transform: scale(0.992); }
.client-row { display: flex; justify-content: space-between; gap: 12px; }
.client-name { margin: 0; font-size: 15px; line-height: 1.3; }
.contract-tag { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.progress { height: 6px; margin: 14px 0 9px; overflow: hidden; border-radius: 10px; background: #edf0f3; }
.progress span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold), #dfbd79); }
.client-stats { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.client-stats b { color: var(--ink); font-size: 12px; }
.next-line { margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.next-line.is-overdue { color: var(--red); }

.detail-hero {
  padding: 21px;
  border-radius: 24px;
  color: white;
  background: linear-gradient(145deg, var(--navy), var(--navy-soft));
  box-shadow: var(--shadow);
}
.back-link { margin: 0 0 13px; padding: 0; border: 0; color: #bac4d3; background: none; font-size: 13px; }
.detail-hero h1 { margin: 0; font-size: 22px; line-height: 1.18; letter-spacing: -0.035em; }
.detail-contract { margin: 7px 0 20px; color: #aeb8c8; font-size: 12px; }
.detail-balance { display: grid; grid-template-columns: 1.15fr 1fr; gap: 12px; }
.detail-balance div { padding: 13px; border-radius: 15px; background: rgba(255, 255, 255, 0.075); }
.detail-balance span { display: block; color: #aeb8c8; font-size: 10px; }
.detail-balance b { display: block; margin-top: 5px; font-size: 18px; letter-spacing: -0.03em; }

.primary-button, .secondary-button, .danger-button {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: 16px;
  font-weight: 750;
}
.primary-button { color: white; background: var(--navy); }
.primary-button.gold { margin-top: 15px; color: #17120a; background: linear-gradient(135deg, #d4aa5b, #e8c77f); }
.secondary-button { color: var(--ink); background: var(--soft); }
.danger-button { color: var(--red); background: var(--red-soft); }
.primary-button:disabled { opacity: 0.55; }

.tabs { display: flex; gap: 6px; margin: 20px 0 11px; padding: 4px; border-radius: 15px; background: #e9ecf0; }
.tab { flex: 1; height: 38px; border: 0; border-radius: 12px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 700; }
.tab.is-active { color: var(--ink); background: var(--paper); box-shadow: 0 3px 10px rgba(16,24,39,.07); }
.timeline { display: grid; gap: 8px; }
.timeline-row { display: grid; grid-template-columns: 76px 1fr auto; align-items: center; gap: 9px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); }
.timeline-date { color: var(--muted); font-size: 11px; }
.timeline-name { font-size: 12px; }
.timeline-name small { display: block; margin-top: 3px; color: var(--muted); }
.timeline-amount { font-size: 12px; font-weight: 800; }
.timeline-row.is-paid .timeline-amount { color: var(--green); }
.timeline-row.is-overdue { border-color: #f1cece; background: #fffafa; }
.timeline-row.is-overdue .timeline-amount { color: var(--red); }

.empty-state { padding: 34px 20px; border: 1px dashed #d7dce3; border-radius: 20px; color: var(--muted); text-align: center; }
.empty-state b { display: block; margin-bottom: 5px; color: var(--ink); }
.error-state { margin-top: 30px; padding: 26px 18px; border-radius: 22px; background: var(--paper); text-align: center; }
.error-state h2 { margin: 0 0 8px; }
.error-state p { margin: 0; color: var(--muted); line-height: 1.5; }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  width: min(100%, 720px);
  padding: 8px 18px calc(8px + var(--safe-bottom));
  transform: translateX(-50%);
  border-top: 1px solid rgba(230, 233, 238, 0.95);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(20px);
}
.nav-item { display: grid; justify-items: center; gap: 2px; min-height: 48px; padding: 4px; border: 0; color: #8891a0; background: transparent; font-size: 10px; }
.nav-item.is-active { color: var(--navy); font-weight: 800; }
.nav-icon { font-size: 23px; line-height: 1; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: flex; align-items: end; justify-content: center; padding: 18px 0 0; background: rgba(4, 10, 19, 0.5); backdrop-filter: blur(5px); }
.modal-backdrop[hidden] { display: none; }
.modal-sheet { width: min(100%, 720px); max-height: 92vh; overflow-y: auto; padding: 9px 18px calc(22px + var(--safe-bottom)); border-radius: 27px 27px 0 0; background: var(--paper); box-shadow: 0 -20px 60px rgba(0,0,0,.2); }
.sheet-handle { width: 42px; height: 5px; margin: 0 auto 14px; border-radius: 4px; background: #d9dde3; }
.modal-head { display: flex; align-items: start; justify-content: space-between; margin-bottom: 17px; }
.modal-head h2 { margin: 3px 0 0; font-size: 23px; letter-spacing: -0.035em; }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 13px; background: var(--soft); color: var(--muted); font-size: 25px; }
.payment-form { display: grid; gap: 14px; }
.selected-client { padding: 13px 14px; border-radius: 15px; background: var(--gold-soft); font-size: 13px; font-weight: 700; }
.selected-client small { display: block; margin-top: 3px; color: #806631; font-weight: 500; }
.field { display: grid; gap: 7px; color: var(--ink); font-size: 12px; font-weight: 700; }
.field small { color: var(--muted); font-weight: 400; }
.field input { width: 100%; height: 50px; padding: 0 14px; border: 1px solid var(--line); border-radius: 14px; outline: 0; background: var(--paper); }
.field input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.money-input { position: relative; }
.money-input input { padding-right: 43px; font-size: 22px; font-weight: 800; }
.money-input b { position: absolute; right: 16px; top: 12px; color: var(--muted); font-size: 19px; }
.payment-preview { display: grid; gap: 13px; }
.preview-card { padding: 17px; border-radius: 18px; background: var(--soft); }
.preview-card h3 { margin: 0 0 12px; font-size: 17px; }
.preview-row { display: flex; justify-content: space-between; gap: 14px; padding: 8px 0; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.preview-row:last-child { border-bottom: 0; }
.preview-row b { color: var(--ink); text-align: right; }
.preview-warning { padding: 13px; border-radius: 14px; color: #8e3131; background: var(--red-soft); font-size: 12px; line-height: 1.45; }
.button-stack { display: grid; gap: 8px; }

.toast { position: fixed; left: 50%; bottom: calc(84px + var(--safe-bottom)); z-index: 150; width: min(calc(100% - 32px), 500px); padding: 13px 16px; transform: translateX(-50%); border-radius: 15px; color: white; background: rgba(16, 24, 39, 0.94); box-shadow: var(--shadow); text-align: center; font-size: 12px; }
.toast[hidden] { display: none; }
.loading { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; background: rgba(244,246,248,.68); backdrop-filter: blur(2px); }
.loading[hidden] { display: none; }
.loading span { width: 35px; height: 35px; border: 3px solid #dfe3e9; border-top-color: var(--gold); border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 620px) {
  .content { padding-inline: 24px; }
  .summary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .summary-card { min-height: 135px; }
}
