:root {
  --bg: #f1f2f3;
  --surface: #ffffff;
  --surface-soft: #f8f9fa;
  --text: #292b2f;
  --muted: #7d8188;
  --muted-soft: #a6aab0;
  --line: #e5e7e9;
  --line-strong: #d6d9dc;
  --accent: #3f81c6;
  --accent-dark: #2f6eae;
  --accent-soft: #edf5fc;
  --success: #428b6c;
  --danger: #b36c62;
  --shadow: 0 24px 60px rgba(24, 28, 33, 0.14);
  --radius-shell: 28px;
  --radius-card: 14px;
  --radius-large: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.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;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: min(402px, 100%);
  height: min(860px, calc(100vh - 96px));
  min-height: 680px;
  margin: 48px auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-shell);
  box-shadow: var(--shadow);
}

.app-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#app {
  padding: 28px 20px 20px;
}

.page {
  min-height: 100%;
}

.page-kicker {
  margin: 0 0 4px;
  color: #777b82;
  font-size: 13px;
  line-height: 1.3;
}

.page-title {
  margin: 0 0 20px;
  color: var(--text);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.page-heading {
  margin-bottom: 20px;
}

.page-heading-inline {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.page-heading-inline .page-title {
  margin-bottom: 0;
}

.page-copy,
.section-copy {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.loading-page {
  padding-top: 4px;
}

.hero-card {
  margin-bottom: 14px;
  padding: 20px;
  color: #fff;
  background: var(--accent);
  border-radius: var(--radius-large);
}

.hero-label {
  margin-bottom: 6px;
  color: rgba(255, 255, 255, 0.84);
  font-size: 13px;
}

.hero-value {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.stat-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.stat-value {
  display: block;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
}

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

.section-title {
  margin: 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}

.section-heading-spaced {
  margin-top: 24px;
}

.link-action,
.text-action {
  appearance: none;
  padding: 0;
  color: var(--accent);
  background: transparent;
  border: 0;
  font-size: 13px;
  font-weight: 600;
}

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

.record-list,
.clinic-list,
.report-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.record-item {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
}

.record-item-top,
.clinic-card-top,
.report-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.record-clinic,
.clinic-name,
.report-clinic {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.record-date,
.clinic-since,
.report-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.record-result {
  flex: 0 0 auto;
  text-align: right;
}

.record-income,
.report-income {
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.record-total {
  margin-top: 2px;
  color: var(--muted-soft);
  font-size: 11px;
  white-space: nowrap;
}

.record-item-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
}

.empty-state {
  padding: 24px;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-card);
  text-align: center;
  font-size: 13px;
  line-height: 1.45;
}

.feedback {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}

.feedback.ok {
  color: var(--success);
  background: #eef8f2;
}

.feedback.error {
  color: var(--danger);
  background: #fff2f0;
}

.segmented {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  padding: 4px;
  background: var(--bg);
  border-radius: 12px;
}

.segment-btn {
  flex: 1;
  min-width: 0;
  padding: 8px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
}

.segment-btn.is-active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(32, 38, 44, 0.06);
}

.clinic-card {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.clinic-card.is-archived {
  opacity: 0.68;
}

.clinic-rate {
  appearance: none;
  padding: 0;
  color: var(--accent);
  background: transparent;
  border: 0;
  font-size: 13px;
  font-weight: 700;
}

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

.clinic-history {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.history-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #666b72;
  font-size: 12px;
}

.history-row strong {
  color: var(--text);
}

.clinic-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.clinic-actions .text-action {
  font-size: 12px;
}

.inline-form,
.record-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.inline-form {
  margin-top: 10px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.field input,
.field select,
.field textarea,
.inline-form input {
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid #dfe2e5;
  border-radius: 10px;
  outline: none;
  font-size: 14px;
}

.field textarea {
  min-height: 68px;
  resize: vertical;
}

.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible,
.inline-form input:focus-visible,
.btn:focus-visible,
.nav-btn:focus-visible,
.segment-btn:focus-visible,
.text-action:focus-visible,
.link-action:focus-visible,
.clinic-rate:focus-visible {
  outline: 2px solid rgba(63, 129, 198, 0.38);
  outline-offset: 2px;
  border-color: var(--accent);
}

.field-hint {
  color: var(--muted-soft);
  font-size: 11px;
  line-height: 1.4;
}

.form-actions {
  display: flex;
  gap: 8px;
}

.form-actions .btn-primary {
  width: auto;
  flex: 1;
}

.btn {
  appearance: none;
  min-height: 42px;
  padding: 10px 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.btn:hover {
  border-color: #bfc4c9;
  background: var(--surface-soft);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  width: 100%;
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.btn-block {
  width: 100%;
  margin-top: 12px;
}

.btn-primary:hover {
  color: #fff;
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.btn-secondary {
  flex: 1;
}

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

.btn-ghost {
  color: var(--accent);
  background: transparent;
  border-color: transparent;
}

.btn:disabled {
  opacity: 0.45;
  transform: none;
}

.preview-box {
  padding: 14px 16px;
  background: #f6f8fa;
  border-radius: var(--radius-card);
}

.preview-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.preview-row:last-child {
  margin: 8px 0 0;
  padding-top: 8px;
  color: var(--text);
  border-top: 1px solid var(--line);
  font-size: 16px;
  font-weight: 700;
}

.preview-row strong {
  color: var(--text);
  white-space: nowrap;
}

.preview-row:last-child strong {
  color: var(--accent);
}

.form-error {
  color: var(--danger);
  font-size: 13px;
  line-height: 1.4;
}

.month-switcher {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 20px;
}

.month-label {
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
}

.month-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
}

.report-hero {
  margin-bottom: 14px;
  padding: 20px;
  color: #fff;
  background: var(--accent);
  border-radius: var(--radius-large);
}

.report-hero .hero-value {
  font-size: 28px;
}

.report-section-title {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.clinic-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.clinic-bar-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 5px;
  font-size: 13px;
}

.clinic-bar-head strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.clinic-bar-head span {
  color: var(--muted);
  white-space: nowrap;
}

.clinic-bar-track {
  height: 6px;
  overflow: hidden;
  background: #edf0f2;
  border-radius: 4px;
}

.clinic-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

.report-day-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.report-day-label {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 12px;
}

.report-row {
  padding: 10px 12px;
  border: 1px solid #e8eaec;
  border-radius: 12px;
}

.report-meta {
  margin-top: 2px;
}

.report-comment {
  margin-top: 4px;
  color: #92969b;
  font-size: 12px;
  font-style: italic;
  line-height: 1.4;
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
}

.profile-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  color: #fff;
  background: var(--accent);
  border-radius: 50%;
  font-size: 20px;
  font-weight: 700;
}

.profile-name {
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.profile-username {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.profile-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--line);
}

.profile-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  background: var(--surface);
  font-size: 13px;
}

.profile-row span {
  color: var(--muted);
}

.profile-row strong {
  color: var(--text);
  text-align: right;
  overflow-wrap: anywhere;
}

.bottom-nav {
  display: flex;
  flex: 0 0 auto;
  padding: 8px 4px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.nav-btn {
  display: flex;
  align-items: center;
  flex: 1;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  padding: 0 2px;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
}

.nav-btn.is-active {
  color: var(--accent);
}

.nav-dot {
  width: 6px;
  height: 6px;
  background: #d4d8dc;
  border-radius: 50%;
}

.nav-btn.is-active .nav-dot {
  background: var(--accent);
}

.sheet {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(38, 42, 47, 0.42);
}

.sheet-panel {
  width: min(360px, 100%);
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 18px 42px rgba(24, 28, 33, 0.18);
}

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

.sheet-title {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
}

@media (max-width: 480px) {
  .app-shell {
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }
}

@media (max-width: 350px) {
  #app {
    padding-right: 16px;
    padding-left: 16px;
  }

  .nav-btn {
    font-size: 10px;
  }
}
