:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-soft: #f8f8fa;
  --text: #15171c;
  --muted: #6d717b;
  --line: #e6e7eb;
  --yellow: #ffcc00;
  --yellow-dark: #e1ae00;
  --green: #12834f;
  --red: #c43e38;
  --blue: #1769e0;
  --shadow: 0 12px 34px rgba(24, 27, 34, 0.08);
  --radius: 20px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 0%, rgba(255, 204, 0, 0.18), transparent 28rem),
    var(--bg);
  font-size: 15px;
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(23, 105, 224, 0.35);
  outline-offset: 2px;
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(20px, 4vw, 26px); line-height: 1.1; }
h2 { font-size: 18px; }

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

.app-shell {
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom));
}

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

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand p { margin-top: 4px; font-size: 13px; overflow-wrap: anywhere; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 15px;
  color: #111318;
  background: var(--yellow);
  box-shadow: 0 8px 22px rgba(184, 139, 0, 0.22);
  font-size: 25px;
  font-weight: 800;
}

.panel,
.metric-card,
.point-card {
  border: 1px solid rgba(21, 23, 28, 0.06);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: clamp(36px, 8vw, 72px) 20px;
  text-align: center;
}

.empty-state p { max-width: 620px; line-height: 1.55; }
.empty-icon {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 24px;
  color: #735900;
  background: #fff3bd;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.08em;
}
.privacy-note { color: var(--muted); font-size: 13px; }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  font-size: 20px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 15px;
  border: 1px solid transparent;
  border-radius: 13px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  font-weight: 650;
  line-height: 1.1;
  text-decoration: none;
}
.button.primary { background: var(--yellow); }
.button.primary:hover { background: #ffd632; }
.button.secondary { border-color: var(--line); background: var(--surface); }
.button:disabled { cursor: not-allowed; opacity: 0.55; }

.button-row { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.button-row.centered { justify-content: center; }

.toolbar {
  display: grid;
  grid-template-columns: auto minmax(145px, 0.7fr) minmax(180px, 1fr) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 15px;
  padding: 12px;
}

.toolbar-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.segmented {
  display: inline-grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 4px;
  border-radius: 13px;
  background: #eceef2;
}
.segmented button {
  min-height: 38px;
  padding: 8px 13px;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.segmented button[aria-pressed="true"] {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(18, 20, 25, 0.08);
  font-weight: 650;
}

.compact-field { display: grid; grid-template-columns: auto minmax(150px, 250px); align-items: center; gap: 8px; }
.compact-field span { color: var(--muted); font-size: 13px; }

select,
input[type="text"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="url"],
input[type="password"] {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #d9dbe0;
  border-radius: 12px;
  color: var(--text);
  background: var(--surface);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}
.metric-card { display: grid; gap: 5px; min-width: 0; padding: 18px; }
.metric-card > span { color: var(--muted); font-size: 13px; }
.metric-card strong { font-size: clamp(22px, 4vw, 34px); line-height: 1.12; overflow-wrap: anywhere; }
.metric-card small { color: var(--muted); line-height: 1.35; }
.metric-card.profit-card { background: linear-gradient(145deg, #17191e, #2a2d34); color: #fff; }
.metric-card.profit-card > span,
.metric-card.profit-card small { color: rgba(255, 255, 255, 0.66); }
.metric-card.profit-card.is-loss { background: linear-gradient(145deg, #632f2d, #9d3833); }

.calculation-line {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  margin-bottom: 26px;
  padding: 13px 16px;
  color: var(--muted);
}
.calculation-line strong { color: var(--text); }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}
.section-heading p { margin-top: 4px; font-size: 13px; }

.points-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 26px;
}
.point-card { display: grid; gap: 15px; padding: 17px; }
.point-title { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.point-title p { margin-top: 3px; color: var(--muted); font-size: 12px; }
.point-profit { color: var(--green); font-size: 21px; white-space: nowrap; }
.point-profit.loss { color: var(--red); }
.point-breakdown {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.point-breakdown span { display: flex; justify-content: space-between; gap: 8px; }
.point-breakdown strong { color: var(--text); }

.operations-section { padding: 17px; }
.operations-heading { margin-bottom: 3px; }
.operations-list { display: grid; }
.operation-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.3fr) minmax(130px, 0.8fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}
.operation-row:last-child { border-bottom: 0; }
.operation-row small { display: block; margin-top: 3px; color: var(--muted); }
.operation-amount { white-space: nowrap; }
.operation-amount.income { color: var(--green); }
.operation-amount.expense { color: var(--red); }
.delete-button {
  min-width: 40px;
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  color: var(--muted);
  background: var(--surface-soft);
  cursor: pointer;
}
.empty-operations { padding: 20px 0 7px; color: var(--muted); text-align: center; }

.notice {
  margin-bottom: 12px;
  padding: 12px 15px;
  border: 1px solid #f0d05c;
  border-radius: 14px;
  color: #5d4900;
  background: #fff7ce;
}

.sync-success { color: var(--green); }
.sync-error { color: var(--red); }
.button.is-loading { position: relative; pointer-events: none; }
.button.is-loading::after {
  width: 15px;
  height: 15px;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  padding: 23px 4px 0;
  color: var(--muted);
  font-size: 12px;
}
.link-button { border: 0; padding: 0; color: var(--blue); background: transparent; cursor: pointer; }

dialog {
  width: min(620px, calc(100% - 24px));
  max-height: min(820px, calc(100% - 24px));
  padding: 0;
  border: 0;
  border-radius: 22px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}
dialog::backdrop { background: rgba(11, 13, 17, 0.54); backdrop-filter: blur(3px); }
.dialog-form { display: grid; gap: 17px; padding: 20px; }
.dialog-title-row { display: flex; justify-content: space-between; align-items: start; gap: 15px; }
.dialog-title-row p { margin-top: 5px; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.dialog-form label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.dialog-form label input,
.dialog-form label select { color: var(--text); font-size: 15px; }
.checkbox-field { display: flex !important; align-items: center; min-height: 44px; gap: 9px !important; color: var(--text) !important; }
.checkbox-field input { width: 20px; height: 20px; }
.form-hint { color: var(--muted); font-size: 12px; line-height: 1.45; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; }
fieldset { display: grid; gap: 12px; margin: 0; padding: 14px; border: 1px solid var(--line); border-radius: 16px; }
legend { padding: 0 6px; font-weight: 700; }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  width: min(460px, calc(100% - 28px));
  transform: translateX(-50%);
  padding: 13px 16px;
  border-radius: 14px;
  color: #fff;
  background: #20232a;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
  text-align: center;
}
.toast.error { background: #9d3833; }

[hidden] { display: none !important; }

@media (max-width: 760px) {
  .app-shell { padding-inline: 12px; }
  .toolbar { grid-template-columns: 1fr; align-items: stretch; }
  .compact-field { grid-template-columns: auto 1fr; }
  .toolbar-actions .button { flex: 1; }
  .metric-grid { grid-template-columns: 1fr; }
  .points-grid { grid-template-columns: 1fr; }
  .operations-heading { align-items: stretch; flex-direction: column; }
  .operations-heading .button-row .button { flex: 1; }
  .operation-row { grid-template-columns: 1fr auto; }
  .operation-meta { grid-column: 1 / -1; grid-row: 2; }
  .delete-button { grid-column: 2; grid-row: 1 / span 2; }
}

@media (max-width: 480px) {
  .brand-mark { width: 43px; height: 43px; border-radius: 13px; }
  .brand p { max-width: 230px; }
  .form-grid { grid-template-columns: 1fr; }
  .segmented button { padding-inline: 8px; font-size: 13px; }
  .point-title { align-items: start; }
  .point-profit { font-size: 18px; }
  .point-breakdown { grid-template-columns: 1fr; }
  .dialog-actions .button { flex: 1; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111318;
    --surface: #1d2026;
    --surface-soft: #242830;
    --text: #f5f5f6;
    --muted: #a4a8b1;
    --line: #31353d;
    --green: #52ca8d;
    --red: #ff8580;
    --blue: #79aaff;
    --shadow: 0 12px 34px rgba(0, 0, 0, 0.24);
  }
  body { background: radial-gradient(circle at 8% 0%, rgba(255, 204, 0, 0.11), transparent 25rem), var(--bg); }
  .panel, .metric-card, .point-card { border-color: rgba(255, 255, 255, 0.06); background: rgba(29, 32, 38, 0.96); }
  .segmented { background: #292d35; }
  .segmented button[aria-pressed="true"] { background: #3a3f49; }
  select, input[type="text"], input[type="number"], input[type="date"], input[type="time"], input[type="url"], input[type="password"] { border-color: #3a3f49; background: #1a1d22; }
  .notice { border-color: #6b5a20; color: #ffe795; background: #3b341d; }
}
