:root {
  --bg: #f8f9fd;
  --panel: #ffffff;
  --panel-2: #f2f5ff;
  --text: #111111;
  --muted: #59627a;
  --green: #16a66a;
  --green-dark: #e6f7ef;
  --gold: #d99500;
  --red: #ff2f52;
  --blue: #563bff;
  --blue-2: #2979ff;
  --cyan: #00e5ff;
  --pink: #ff40df;
  --line: rgba(17,17,17,.08);
  --white: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ui-heading: 23px;
  --ui-body: 15px;
}

* { box-sizing: border-box; }

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 0%, rgba(86,59,255,.12), transparent 28%),
    radial-gradient(circle at 88% 8%, rgba(0,229,255,.13), transparent 24%),
    var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  font-size: var(--ui-body);
}

.hidden { display: none !important; }
.main-only-hidden { display: none !important; }

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(145deg, #f5f7ff, #ffffff 52%, #eefbff);
}

.auth-card {
  width: min(100%, 420px);
  padding: 30px 24px 24px;
  border: 1px solid rgba(17,17,17,.07);
  border-radius: 28px;
  background: rgba(255,255,255,.96);
  box-shadow: 0 24px 70px rgba(18,25,60,.14);
}

.auth-logo {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  object-fit: cover;
  box-shadow: 0 8px 20px rgba(86,59,255,.22);
}

.auth-card h1 { margin: 4px 0 8px; font-size: 28px; }
.auth-subtitle, .auth-footnote { color: var(--muted); line-height: 1.45; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 22px 0 18px; padding: 4px; border-radius: 14px; background: #f1f3fa; }
.auth-tabs button { border: 0; border-radius: 10px; padding: 10px; background: transparent; color: var(--muted); font-weight: 700; cursor: pointer; }
.auth-tabs button.active { background: #fff; color: var(--blue); box-shadow: 0 3px 10px rgba(18,25,60,.08); }
.auth-field { display: grid; gap: 7px; margin: 12px 0; color: #30384e; font-size: 13px; font-weight: 700; }
.auth-field input { width: 100%; padding: 13px 14px; border: 1px solid #dfe4f0; border-radius: 13px; font: inherit; font-weight: 400; outline: none; }
.auth-field input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(86,59,255,.12); }
.auth-submit { width: 100%; margin-top: 16px; }
.auth-resend { width: 100%; margin-top: 10px; padding: 10px; border: 0; border-radius: 12px; background: #f1f3ff; color: var(--blue); font-weight: 700; cursor: pointer; }
.auth-status { min-height: 20px; margin: 12px 0 0; color: var(--red); font-size: 13px; }
.auth-footnote { margin: 18px 0 0; font-size: 11px; }

.phone-shell {
  position: relative;
  width: min(100%, 440px);
  max-width: 100%;
  min-height: 100vh;
  padding: 18px 14px 96px;
  overflow-x: hidden;
}

.app-header, .section-title, .chart-head, .brand, .bottom-tabs {
  display: flex;
  align-items: center;
}

.app-header, .section-title, .chart-head {
  justify-content: space-between;
  gap: 14px;
}

.app-header {
  margin: -18px -14px 18px;
  padding: 38px 18px 16px;
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid rgba(17,17,17,.06);
  border-bottom-left-radius: 24px;
  border-bottom-right-radius: 24px;
  position: relative;
  justify-content: space-between;
  box-shadow: 0 14px 30px rgba(18,25,60,.07);
}

.refresh-box {
  display: grid;
  justify-items: end;
  gap: 5px;
}

.refresh-box p {
  max-width: 150px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
  text-align: right;
}

.api-debug {
  max-width: 190px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.api-debug pre {
  max-height: 120px;
  overflow: auto;
  padding: 8px;
  border-radius: 12px;
  background: #f5f7fb;
  color: var(--text);
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
}

.top-sync-status {
  display: grid;
  gap: 8px;
  margin: -4px 0 14px;
  padding: 12px 14px;
  border-radius: 20px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(18,25,60,.06);
  text-align: center;
}

.top-sync-status p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  font-weight: 700;
}

.top-sync-status .api-debug {
  max-width: none;
  text-align: center;
}

.brand {
  gap: 10px;
  justify-content: flex-start;
  text-align: left;
  min-width: 0;
}

.brand img {
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  box-shadow: 0 0 18px rgba(86,59,255,.38);
  flex: 0 0 auto;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 24px; letter-spacing: -.6px; font-weight: 900; }
h2 { font-size: 25px; letter-spacing: -.7px; font-weight: 900; }
h3 { font-size: 17px; font-weight: 900; }

.eyebrow {
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
}

.icon-button, .refresh-button, .primary-button, .secondary-button, .period-switch button, .bottom-tabs button, .export-buttons button {
  border: 0;
  color: var(--text);
  cursor: pointer;
}

.icon-button {
  position: absolute;
  right: 18px;
  top: 32px;
  width: 48px;
  height: 48px;
  border-radius: 18px;
  background: #f7f8fc;
  color: var(--blue);
  font-size: 20px;
  box-shadow: 0 8px 18px rgba(18,25,60,.08);
}

.cabinet-card, .api-panel, .mode-card, .chart-card, .report-list, .actions-card, .fbo-item, .loss-card {
  background: var(--panel);
  border: 0;
  border-radius: 22px;
  box-shadow: 0 8px 26px rgba(18,25,60,.06);
}

.cabinet-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: stretch;
  margin: 0 0 22px;
  padding: 18px;
  max-width: 100%;
  overflow: hidden;
}

.cabinet-card > :first-child label {
  display: block;
  color: var(--text);
  font-weight: 800;
}

.cabinet-card > :first-child .small { margin-top: 5px; }

.cabinet-card > :first-child,
.api-panel > :first-child {
  text-align: center;
  grid-column: 1 / -1;
}

.cabinet-card > :first-child label,
.api-panel > :first-child h2 {
  font-size: var(--ui-heading) !important;
}

.cabinet-controls {
  grid-column: 1 / -1;
  max-width: 620px;
  margin: 0 auto;
}

.cabinet-controls select,
.marketplace-switch select {
  min-height: 48px;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  text-align-last: center;
}

.marketplace-switch {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  max-width: 620px;
  width: 100%;
  margin: 0 auto;
}

.marketplace-switch label {
  color: var(--text);
  font-weight: 800;
  text-align: center;
  font-size: var(--ui-body);
}

.marketplace-fields {
  display: grid;
  gap: 10px;
  grid-column: 1 / -1;
  width: min(100%, 760px);
  margin: 0 auto;
  text-align: center;
}

.marketplace-fields p {
  margin: 0 auto;
  max-width: 700px;
}

.credentials-save-button {
  grid-column: 1 / -1;
  width: min(100%, 760px);
  margin: 0 auto 4px;
  min-height: 48px;
}

.marketplace-banner {
  margin: 8px auto 0;
  max-width: 760px;
  padding: 10px 14px;
  border-radius: 14px;
  background: #fff4dc;
  color: #76520c;
  font-size: var(--ui-body);
  font-weight: 700;
  line-height: 1.35;
}

.marketplace-fields > h3 {
  margin: 4px 0 0;
}

label, .chart-head p, .api-panel p, .small {
  color: var(--muted);
  font-size: 13px;
}

select, input {
  width: 100%;
  border: 0;
  background: #f6f7fb;
  color: var(--text);
  border-radius: 14px;
  padding: 14px;
  outline: none;
}

textarea {
  width: 100%;
  min-height: 92px;
  border: 0;
  background: #f6f7fb;
  color: var(--text);
  border-radius: 14px;
  padding: 12px;
  outline: none;
  resize: vertical;
  font-family: inherit;
}

.cabinet-card select { max-width: none; }

.cabinet-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px 40px;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-width: 0;
}

.cabinet-controls select {
  max-width: none;
  min-width: 0;
}

.cabinet-controls button {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.cabinet-controls .cabinet-settings-button {
  width: 40px;
  min-width: 40px;
  padding: 0;
  font-size: 18px;
  white-space: nowrap;
}

.cabinet-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  min-width: 0;
  margin-top: 10px;
  max-width: 620px;
  margin-left: auto;
  margin-right: auto;
}

.cabinet-actions button {
  min-width: 0;
  white-space: normal;
  min-height: 48px;
  font-size: var(--ui-body);
  font-weight: 800;
}

.tax-settings {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 0;
  border-radius: 18px;
  background: #f7f8fc;
}

.telegram-settings {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 18px;
  background: linear-gradient(145deg, #ffffff 0%, #f3f5ff 100%);
  border: 1px solid rgba(86,59,255,.10);
}

.telegram-settings label {
  display: grid;
  gap: 7px;
}

.toggle-row {
  display: flex !important;
  grid-template-columns: none;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  color: var(--text);
  font-weight: 800;
}

.toggle-row input {
  width: 20px;
  height: 20px;
  padding: 0;
  accent-color: var(--blue);
}

.telegram-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

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

.tax-grid label {
  display: grid;
  gap: 7px;
}

.api-panel {
  display: none;
  gap: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

/* Единая типографика кабинета: один размер заголовков и один размер основного текста. */
.phone-shell h1,
.phone-shell h2,
.phone-shell h3,
.phone-shell .app-header h1,
.phone-shell .cabinet-card > :first-child label,
.phone-shell .api-panel h2,
.phone-shell .telegram-settings h3,
.phone-shell .tax-settings h3,
.phone-shell .subscription-card h3,
.phone-shell .section-title h2,
.phone-shell .insight-head h3,
.phone-shell .chart-head h3,
.phone-shell .report-head h3 {
  font-size: var(--ui-heading) !important;
  line-height: 1.15;
}
label, .chart-head p, .api-panel p, .small { font-size: var(--ui-body); line-height: 1.35; }
.kpi-label, .kpi-delta, .report-row, .action-row, .brief-row, .alert-row, .profit-row { font-size: var(--ui-body); }

.api-panel.visible { display: grid; }

.mode-card {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.primary-button, .refresh-button {
  background: linear-gradient(135deg, var(--blue), #6f3bff);
  color: #fff;
  font-weight: 800;
  border-radius: 18px;
  padding: 14px 16px;
}

.secondary-button, .export-buttons button {
  background: #f1f3ff;
  color: var(--blue);
  font-weight: 800;
  border-radius: 18px;
  padding: 10px 12px;
}

.subscription-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 0;
  border-radius: 18px;
  background: #eef4ff;
}

.content { display: none; }
.content.active { display: block; }

.section-title { margin: 22px 0 14px; }

#reportsTab > .section-title {
  justify-content: center;
  text-align: center;
  margin-top: 6px;
}

#reportsTab > .section-title h2 {
  font-size: 29px;
}

#reportsTab > .section-title .eyebrow {
  font-size: 14px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

.period-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 5px;
  border-radius: 18px;
  background: #f0f2f8;
  margin-bottom: 16px;
}

.period-switch button {
  padding: 14px 11px;
  border-radius: 14px;
  background: transparent;
  font-weight: 700;
}

.period-switch button.active {
  background: linear-gradient(135deg, var(--blue), #6f3bff);
  color: var(--blue);
  color: #fff;
  box-shadow: 0 8px 16px rgba(86,59,255,.24);
}

.day-picker {
  display: grid;
  gap: 7px;
  margin: 0 0 14px;
  padding: 14px;
  border: 0;
  border-radius: 24px;
  background: #fff;
}

.day-picker.hidden { display: none; }

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

.kpi-card {
  min-height: 118px;
  padding: 18px;
  border-radius: 22px;
  background: var(--panel);
  border: 0;
  box-shadow: 0 8px 26px rgba(18,25,60,.06);
}

.kpi-card.primary {
  grid-column: span 2;
  background: linear-gradient(155deg, #ffffff 0%, #f5f2ff 100%);
  color: var(--text);
}

.kpi-card.primary .kpi-label,
.kpi-card.primary .kpi-delta {
  color: var(--muted);
}

.kpi-label {
  color: var(--muted);
  font-size: 13px;
}

.kpi-value {
  margin-top: 10px;
  font-size: 25px;
  font-weight: 900;
  letter-spacing: -.5px;
}

.kpi-card.primary .kpi-value { font-size: 34px; }

.kpi-delta {
  margin-top: 8px;
  color: var(--blue);
  font-size: 13px;
}

.chart-card, .report-list, .actions-card, .insight-card {
  margin-top: 14px;
  padding: 18px;
}

.insight-card {
  border-radius: 22px;
  background: var(--panel);
  border: 0;
  box-shadow: 0 8px 26px rgba(18,25,60,.06);
}

.insight-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.insight-head h3 {
  margin: 2px 0 0;
}

.daily-brief, .app-alerts, .profit-products {
  display: grid;
  gap: 10px;
}

.brief-row, .alert-row, .profit-row {
  padding: 14px;
  border-radius: 18px;
  background: #f8f9fd;
  border: 0;
}

.brief-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.brief-icon {
  font-size: 20px;
  line-height: 1;
}

.profit-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
}

.profit-row h4 {
  margin: 0;
  font-size: 15px;
}

.profit-row strong {
  font-size: 18px;
}

.profit-row small, .brief-row small, .alert-row small {
  color: var(--muted);
  line-height: 1.35;
}

.profit-bar {
  grid-column: span 2;
  height: 8px;
  border-radius: 999px;
  background: #e8eef7;
  overflow: hidden;
}

.profit-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--cyan));
}

.alert-row.critical {
  border-color: rgba(255, 91, 91, .45);
}

.alert-row.warning {
  border-color: rgba(246, 200, 95, .45);
}

.chart-head { margin-bottom: 10px; }
.chart-head select { max-width: 130px; padding: 9px; }

.chart-head select { font-size: var(--ui-body); }

#salesChart {
  width: 100%;
  max-width: 100%;
  height: 230px;
  overflow: hidden;
}

.report-row, .action-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.report-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.export-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.export-buttons button {
  padding: 8px 10px;
  font-size: 12px;
}

.cost-form {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.cost-tools {
  display: grid;
  gap: 9px;
  margin: 12px 0 4px;
  position: sticky;
  top: 0;
  z-index: 3;
  padding: 8px 0;
  background: var(--surface, #fff);
}

.cost-filter-buttons {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.cost-filter-buttons button {
  border: 0;
  border-radius: 12px;
  padding: 9px 12px;
  background: var(--soft, #f2f3f7);
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.cost-filter-buttons button.active {
  color: #fff;
  background: var(--primary, #5b35f5);
}

.cost-hint {
  margin: 5px 0 12px;
}

.cost-row {
  gap: 10px;
}

.cost-row-missing {
  border: 1px solid rgba(91, 53, 245, .18);
  background: rgba(91, 53, 245, .035);
}

.inline-cost-editor {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  min-width: 0;
}

.inline-cost-editor input {
  width: 112px;
  min-width: 0;
  padding: 9px 10px;
}

.compact-button {
  padding: 9px 10px;
  white-space: nowrap;
}

.cost-csv {
  margin: 12px 0 10px;
}

.cost-row-actions {
  display: flex;
  justify-content: flex-end;
}

.danger-button {
  border: 0;
  color: var(--red);
  background: rgba(230,70,70,.10);
  border-radius: 12px;
  padding: 8px 10px;
  font-weight: 800;
}

.report-row:last-child, .action-row:last-child { border-bottom: 0; }

.report-row span:first-child, .action-row span:first-child {
  color: var(--muted);
  min-width: 0;
}

.report-row strong, .action-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
}
.money-positive { color: var(--green); font-weight: 800; }
.money-negative { color: var(--red); font-weight: 800; }

.money-accuracy {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  padding: 15px 17px;
  border-radius: 22px;
  background: #fff;
  border-left: 5px solid var(--green);
}

.money-accuracy.warning { border-left-color: var(--gold); }
.money-accuracy.error { border-left-color: var(--red); }
.money-accuracy strong { font-size: 15px; }
.money-accuracy small { color: var(--muted); line-height: 1.4; }

.money-flow {
  display: grid;
  gap: 8px;
  padding: 18px;
  border-radius: 26px;
  background: #fff;
}

.money-flow-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.money-flow-row:last-child { border-bottom: 0; }
.money-flow-row .sign {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 12px;
  background: #eef4ff;
  color: var(--blue);
  font-weight: 900;
}
.money-flow-row.cost .sign { background: #fff1f1; color: var(--red); }
.money-flow-row.result {
  margin: 5px -6px -4px;
  padding: 15px 8px;
  border-radius: 20px;
  border-bottom: 0;
  background: #eaf8f1;
}
.money-flow-row.result.negative { background: #fff1f1; }
.money-flow-row span:not(.sign) { color: var(--muted); font-size: 13px; }
.money-flow-row strong { text-align: right; font-size: 18px; }
.money-flow-row.result strong { color: var(--green); font-size: 24px; }
.money-flow-row.result.negative strong { color: var(--red); }

.money-details-card { margin-bottom: 14px; }
.share-results-card {
  display: grid;
  gap: 14px;
  margin-top: 14px;
  padding: 18px;
  border-radius: 22px;
  background: linear-gradient(145deg, #ffffff 0%, #f2f0ff 100%);
}
.share-results-card h3 { margin-top: 3px; }
.share-period-switch {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 5px;
  border-radius: 19px;
  background: #e4ebf7;
}
.share-period-switch button {
  border: 0;
  border-radius: 15px;
  padding: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}
.share-period-switch button.active {
  background: #fff;
  color: var(--blue);
  box-shadow: 0 5px 14px rgba(34,57,101,.10);
}
.share-button {
  border: 0;
  border-radius: 18px;
  padding: 15px 18px;
  background: linear-gradient(135deg, var(--blue), #6f3bff);
  color: #fff;
  font-size: 16px;
  font-weight: 900;
}
.share-status { text-align: center; }
.money-detail {
  border-bottom: 1px solid var(--line);
}
.money-detail:last-child { border-bottom: 0; }
.money-detail summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 15px 0;
  cursor: pointer;
  list-style: none;
}
.money-detail summary::-webkit-details-marker { display: none; }
.money-detail summary span { color: var(--text); font-weight: 750; }
.money-detail summary strong { text-align: right; }
.money-detail-body {
  margin: -5px 0 14px;
  padding: 12px;
  border-radius: 16px;
  background: #f4f6f9;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.money-detail-body b { color: var(--text); }

.pill {
  padding: 8px 11px;
  border-radius: 999px;
  color: var(--gold);
  background: rgba(217,149,0,.12);
  font-weight: 800;
  font-size: 12px;
}

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

.fbo-summary,
.losses-summary {
  margin-bottom: 12px;
  display: grid;
  gap: 10px;
}

.fbo-summary-card,
.loss-summary-card {
  padding: 18px;
  border-radius: 22px;
  background: #fff;
  border: 0;
  box-shadow: 0 8px 26px rgba(18,25,60,.06);
}

.fbo-summary-card span,
.fbo-summary-card small,
.loss-summary-card span,
.loss-summary-card small {
  display: block;
  color: var(--muted);
}

.fbo-summary-card strong,
.loss-summary-card strong {
  display: block;
  margin: 8px 0 6px;
  color: var(--text);
  font-size: 34px;
  line-height: 1;
}

.fbo-item { padding: 15px; }

.loss-card {
  display: grid;
  gap: 10px;
  padding: 15px;
  margin-bottom: 10px;
}

.loss-card.critical {
  border-color: rgba(230,70,70,.32);
  background: #fff;
}

.loss-card.warning {
  border-color: rgba(217,149,0,.30);
  background: #fff;
}

.loss-card.good {
  border-color: rgba(22,166,106,.25);
  background: #fff;
}

.loss-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.loss-badge {
  border-radius: 999px;
  padding: 5px 9px;
  background: #f2f5fa;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.loss-card.critical .loss-badge { color: var(--red); background: #fff1f1; }
.loss-card.warning .loss-badge { color: var(--gold); background: #fff7e3; }
.loss-card.good .loss-badge { color: var(--green); background: #eaf8f1; }

.loss-money {
  font-size: 24px;
  font-weight: 900;
  color: var(--red);
}

.loss-action {
  color: var(--green);
  font-size: 13px;
  line-height: 1.35;
}

.loss-details {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.fbo-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.priority {
  color: #ffffff;
  background: var(--gold);
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.stock-line {
  height: 8px;
  background: #e8eef7;
  border-radius: 999px;
  overflow: hidden;
  margin: 12px 0;
}

.stock-line div {
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--gold), var(--green));
}

.bottom-tabs {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 440px);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-radius: 0;
  background: rgba(255,255,255,.96);
  border: 0;
  border-top: 1px solid #e3e8f0;
  backdrop-filter: blur(18px);
  box-shadow: none;
  gap: 8px;
  overflow: hidden;
}

.bottom-tabs button {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 3px;
  justify-items: center;
  padding: 8px 3px 7px;
  border-radius: 18px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  font-size: 10px;
}

.bottom-tabs button.active {
  background: transparent;
  color: var(--blue);
}

.bottom-tabs button.active span {
  filter: drop-shadow(0 0 7px rgba(86,59,255,.35));
}

@media (min-width: 860px) {
  .phone-shell {
    width: min(1240px, calc(100vw - 56px));
    min-height: calc(100vh - 56px);
    margin: 28px auto 108px;
    padding: 24px 30px 118px;
    border: 1px solid var(--line);
    border-radius: 30px;
    background: rgba(255,255,255,.86);
    overflow: visible;
    box-shadow: 0 24px 80px rgba(32, 42, 90, .12);
  }

  .app-header {
    margin: -24px -30px 22px;
    padding: 24px 30px 18px;
    border-radius: 30px 30px 0 0;
  }

  .cabinet-card,
  .api-panel {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(280px, 1.35fr);
    align-items: center;
    gap: 14px 20px;
  }

  .cabinet-card > :first-child,
  .api-panel > :first-child,
  .api-panel .telegram-settings,
  .api-panel .tax-settings,
  .api-panel .subscription-card,
  .api-panel > #saveApiButton {
    grid-column: 1 / -1;
  }

  .cabinet-card > :first-child,
  .api-panel > :first-child {
    text-align: center;
    grid-column: 1 / -1;
  }

  .cabinet-card .cabinet-controls,
  .cabinet-card .marketplace-switch,
  .cabinet-card .cabinet-actions {
    grid-column: 1 / -1;
  }

  .cabinet-card .cabinet-controls,
  .cabinet-card .marketplace-switch {
    margin-left: auto;
    margin-right: auto;
  }

  .api-panel > input {
    width: 100%;
  }

  .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .chart-card,
  .report-list,
  .actions-card,
  .insight-card {
    margin-top: 18px;
  }

  .reports-layout,
  .money-layout,
  .fbo-layout,
  .losses-layout,
  .costs-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(300px, .65fr);
    gap: 18px;
    align-items: start;
  }

  .reports-layout > *,
  .money-layout > *,
  .fbo-layout > *,
  .losses-layout > *,
  .costs-layout > * {
    min-width: 0;
  }

  .bottom-tabs {
    width: min(1180px, calc(100vw - 56px));
    bottom: 18px;
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: 0 14px 35px rgba(32, 42, 90, .14);
  }

  .bottom-tabs button {
    font-size: 12px;
  }
}

/* Компьютерная версия: веб-кабинет занимает весь экран, мобильный вид сохраняется на телефоне. */
@media (min-width: 860px) {
  body { display: block; }
  .phone-shell {
    width: min(1180px, calc(100vw - 120px));
    max-width: 1180px;
    min-height: calc(100vh - 56px);
    margin: 28px auto 108px;
    padding: 24px 30px 124px;
    border: 1px solid var(--line);
    border-radius: 30px;
    box-shadow: 0 24px 80px rgba(32, 42, 90, .12);
  }
  .app-header {
    margin: -24px -30px 22px;
    padding-left: 30px;
    padding-right: 30px;
    border-radius: 30px 30px 0 0;
  }

  /* Настольный кабинет: компактная рабочая область с отдельными карточками. */
  #reportsTab.active {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 16px;
    align-items: start;
  }

  #reportsTab > .section-title,
  #reportsTab > .period-switch,
  #reportsTab > .day-picker,
  #reportsTab > .kpi-grid {
    grid-column: 1 / -1;
  }

  #reportsTab > .section-title {
    margin: 4px 0 0;
    padding: 4px 2px 0;
  }

  #reportsTab > .period-switch {
    width: min(480px, 100%);
    margin: 0;
  }

  #reportsTab > .day-picker {
    margin: 0;
    padding: 12px 14px;
    border: 1px solid var(--line);
    box-shadow: none;
  }

  #reportsTab > .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
  }

  #reportsTab > #dailyBriefCard {
    grid-column: span 7;
    margin-top: 0;
  }

  #reportsTab > #profitProductsCard {
    grid-column: span 5;
    margin-top: 0;
  }

  #reportsTab > #alertsCard {
    grid-column: 1 / -1;
    margin-top: 0;
  }

  #reportsTab > #salesChartCard {
    grid-column: span 8;
    margin-top: 0;
  }

  #reportsTab > #reportDetailsCard {
    grid-column: span 4;
    margin-top: 0;
  }

  .kpi-card,
  .insight-card,
  .chart-card,
  .report-list,
  .actions-card,
  .money-flow,
  .money-accuracy,
  .share-results-card {
    border: 1px solid var(--line);
    box-shadow: 0 4px 15px rgba(18,25,60,.045);
  }

  .kpi-card {
    min-height: 112px;
    padding: 16px;
    border-radius: 16px;
  }

  .kpi-card.primary {
    grid-column: span 2;
  }

  .insight-card,
  .chart-card,
  .report-list {
    border-radius: 18px;
    padding: 16px;
  }

  .insight-head h3,
  .chart-head h3,
  .report-head h3 {
    font-size: 15px;
  }

  .brief-row,
  .alert-row,
  .profit-row {
    padding: 12px;
    border: 1px solid #edf0f6;
    border-radius: 13px;
    background: #fbfcfe;
  }

  .bottom-tabs {
    width: min(1120px, calc(100vw - 120px));
  }

  .bottom-tabs button {
    padding: 11px 12px;
    border-radius: 13px;
    font-size: 14px;
  }

  .bottom-tabs button.active {
    background: #eef1ff;
  }
}
