:root {
  color-scheme: light;
  --bg: #f3f5f0;
  --surface: #ffffff;
  --soft: #f8faf7;
  --ink: #17211c;
  --muted: #5e6a63;
  --line: #d8ded7;
  --brand: #176f5d;
  --brand-dark: #0e4f43;
  --accent: #d99235;
  --danger: #b94335;
  --warn: #c88719;
  --ok: #16804f;
  --shadow: 0 18px 50px rgba(30, 43, 37, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.45;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 50px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  padding: 0 22px;
  font-weight: 800;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

button:hover {
  background: var(--brand-dark);
  box-shadow: 0 8px 18px rgba(23, 111, 93, 0.18);
  transform: translateY(-1px);
}

button.ghost,
.tabs button,
.segmented button {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.ghost.dark {
  background: #fff;
  color: var(--ink);
}

button.small {
  min-height: 42px;
  padding: 0 14px;
}

.primary-action {
  min-height: 58px;
  padding: 0 28px;
  font-size: 1.05rem;
}

.quick-submit {
  width: 100%;
  min-height: 66px;
  margin-top: 16px;
  font-size: 1.16rem;
}

.mobile-main {
  width: 100%;
  margin-top: 16px;
}

.app-header {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px;
  background: #17211c;
  color: #fff;
}

.app-header h1 {
  max-width: 920px;
  margin: 6px 0 0;
  font-size: clamp(2rem, 7vw, 4.4rem);
  line-height: 1;
  letter-spacing: 0;
}

.hero-copy {
  max-width: 760px;
  margin: 14px 0 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: clamp(1rem, 2.5vw, 1.25rem);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.language-switcher {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  padding: 4px;
}

.language-switcher button {
  min-height: 34px;
  border-radius: 6px;
  background: transparent;
  color: #fff;
  padding: 0 10px;
  font-size: 0.85rem;
  box-shadow: none;
}

.language-switcher button.active {
  background: #fff;
  color: var(--ink);
}

.language-switcher button:hover {
  transform: none;
  box-shadow: none;
}

.action-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.header-actions .ghost {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.25);
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-shell {
  width: min(1220px, 100%);
  margin: 0 auto;
  padding: 12px;
}

.welcome-panel,
.usage-guide,
.setup-wizard {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.welcome-panel {
  display: grid;
  gap: 16px;
  margin-bottom: 12px;
  padding: 18px;
}

.welcome-copy {
  max-width: 760px;
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.welcome-points {
  display: grid;
  gap: 8px;
}

.welcome-points p {
  margin: 0;
  border-left: 4px solid var(--brand);
  padding-left: 12px;
  font-weight: 750;
}

.welcome-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.link-button {
  min-height: 38px;
  border: 0;
  background: transparent;
  color: var(--brand-dark);
  padding: 0;
  box-shadow: none;
  text-decoration: underline;
}

.link-button:hover {
  background: transparent;
  box-shadow: none;
  color: var(--brand);
  transform: none;
}

.usage-guide {
  margin-bottom: 12px;
  padding: 14px 16px;
}

.usage-guide summary {
  cursor: pointer;
  color: var(--brand-dark);
  font-weight: 950;
}

.guide-body {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.guide-body p {
  margin: 0;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  padding: 10px 0;
  background: var(--bg);
}

.tabs button {
  min-height: 48px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  white-space: nowrap;
  font-size: 0.95rem;
}

.tabs button.active,
.segmented button.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel.active {
  display: block;
}

.section-head,
.subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h2 {
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  line-height: 1.08;
}

h3 {
  font-size: 1.12rem;
}

.save-state,
.muted {
  color: var(--muted);
}

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

.grid.two,
.grid.three,
.grid.four {
  grid-template-columns: 1fr;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.98rem;
  font-weight: 800;
}

.field-hint,
.section-hint,
.metric-hint {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.35;
}

.section-hint {
  margin: -8px 0 14px;
}

.simple-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 750;
}

input,
select {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  padding: 12px 14px;
  font-size: 1.04rem;
  max-width: 100%;
}

select[multiple] {
  min-height: 108px;
}

.check {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
}

.check input {
  width: 22px;
  min-height: 22px;
}

.wide {
  align-self: end;
}

.quick-card,
.settings-card,
.advanced-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 16px;
}

.advanced-box {
  margin-top: 16px;
}

.advanced-box summary {
  cursor: pointer;
  color: var(--brand-dark);
  font-weight: 900;
}

.advanced-box .grid {
  margin-top: 16px;
}

.form-errors {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  border: 1px solid #e7b4aa;
  border-left: 5px solid var(--danger);
  border-radius: 8px;
  background: #fff4f2;
  color: #75261c;
  padding: 12px 14px;
  font-weight: 850;
}

.settings-card {
  display: grid;
  gap: 16px;
  margin-bottom: 22px;
}

.setup-wizard {
  display: grid;
  gap: 16px;
  margin-bottom: 24px;
  padding: 16px;
  background: var(--soft);
}

.wizard-steps {
  display: grid;
  gap: 14px;
}

.wizard-steps article {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.wizard-steps h4,
.wizard-steps p {
  margin: 0;
}

.step-label {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 950;
  text-transform: uppercase;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

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

th {
  background: #eef2ef;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

td input,
td select {
  min-height: 42px;
  padding: 7px 9px;
  font-size: 0.96rem;
}

.icon-btn {
  min-width: 42px;
  min-height: 42px;
  padding: 0;
  background: #f4e9e5;
  color: var(--danger);
}

.template-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.template-card {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfb;
}

.template-card header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.template-card h3 {
  font-size: 1.16rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  background: #e8f2ef;
  color: var(--brand-dark);
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 900;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  width: min(100%, 410px);
}

.result-layout {
  display: grid;
  gap: 16px;
}

.summary {
  border-radius: 8px;
  background: #17211c;
  color: #fff;
  padding: 20px;
}

.status {
  display: inline-flex;
  border-radius: 999px;
  padding: 7px 12px;
  background: #4d5a53;
  color: #fff;
  font-weight: 900;
  font-size: 0.9rem;
}

.status.ok {
  background: var(--ok);
}

.status.warn {
  background: var(--warn);
}

.status.danger {
  background: var(--danger);
}

.total {
  margin: 18px 0 6px;
  font-size: clamp(2.7rem, 13vw, 5.2rem);
  line-height: 0.96;
  font-weight: 950;
}

.result-view {
  display: none;
}

.result-view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.metric-card {
  display: grid;
  gap: 8px;
  min-height: 118px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 16px;
}

.metric-card span {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 800;
}

.metric-card strong {
  align-self: end;
  font-size: clamp(1.7rem, 6vw, 2.7rem);
  line-height: 1;
  overflow-wrap: anywhere;
}

.metric-card.main {
  background: #e8f2ef;
  border-color: #bfd8d0;
}

.metric-card.danger-note {
  background: #fff3ef;
  border-color: #ecc6bc;
}

.metric-hint {
  margin: 0;
}

.status-explain {
  margin: 16px 0;
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: #fff8ed;
  padding: 14px 16px;
  color: #3f3324;
  font-size: 1.04rem;
  font-weight: 750;
}

.order-check,
.manual-price,
.send-card {
  display: grid;
  gap: 12px;
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 16px;
}

.next-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 16px 0;
}

.order-check h3,
.manual-price h3,
.send-card h3 {
  margin: 0;
}

.order-check.ok {
  border-left: 5px solid var(--ok);
}

.order-check.warn {
  border-left: 5px solid var(--warn);
}

.order-check.danger {
  border-left: 5px solid var(--danger);
}

.order-check p,
.manual-result {
  margin: 0;
  font-weight: 850;
}

.manual-result {
  border-radius: 8px;
  background: #eef2ef;
  padding: 12px 14px;
}

.manual-result.ok {
  background: #e8f5ee;
  color: #0f623c;
}

.manual-result.warn {
  background: #fff8e8;
  color: #74500f;
}

.manual-result.danger {
  background: #fff0ed;
  color: #8b2e22;
}

.warnings {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.warning-item {
  border: 1px solid #eed2a5;
  border-left: 5px solid var(--warn);
  border-radius: 8px;
  background: #fff9ef;
  color: #4a3211;
  padding: 13px 15px;
  font-weight: 800;
}

.calculation-details {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.detail-toggle {
  width: 100%;
}

.breakdown-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 16px;
}

.breakdown-panel h3 {
  margin-bottom: 8px;
}

.breakdown {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.line-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 52px;
  border-bottom: 1px solid var(--line);
}

.line-item strong {
  text-align: right;
}

.customer-card {
  display: grid;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.customer-card button {
  width: 100%;
}

.customer-text {
  display: grid;
  gap: 12px;
}

.lang-block {
  padding: 16px;
  border-radius: 8px;
  background: #f5f7f5;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.lang-block.compact {
  background: #eef6f3;
}

.text-details {
  display: grid;
  gap: 10px;
}

.text-details summary {
  cursor: pointer;
  color: var(--brand-dark);
  font-weight: 900;
}

.text-details .lang-block {
  margin-top: 10px;
}

.send-card button {
  width: 100%;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: min(1220px, 100%);
  margin: 0 auto;
  padding: 10px 22px 28px;
  color: var(--muted);
  font-size: 0.92rem;
}

@media (min-width: 720px) {
  .app-header {
    flex-direction: row;
    align-items: end;
    justify-content: space-between;
    padding: 38px;
  }

  .app-shell {
    padding: 22px;
  }

  .panel {
    padding: 24px;
  }

  .grid.two {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid.three {
    grid-template-columns: repeat(3, 1fr);
  }

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

  .template-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .result-layout {
    grid-template-columns: 360px 1fr;
  }

  .summary {
    position: sticky;
    top: 82px;
    align-self: start;
  }

  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .metric-card.main {
    grid-column: span 2;
  }

  .next-actions {
    grid-template-columns: 1fr 1fr;
  }

  .mobile-main {
    display: none;
  }
}

@media (max-width: 719px) {
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .section-head > button {
    width: 100%;
  }

  .action-stack,
  .action-stack button,
  .welcome-actions,
  .welcome-actions button {
    width: 100%;
  }

  .quick-submit {
    position: sticky;
    bottom: 10px;
    z-index: 4;
    box-shadow: 0 12px 26px rgba(23, 111, 93, 0.24);
  }

  .app-shell {
    padding-bottom: 26px;
  }
}

@media (max-width: 540px) {
  body {
    font-size: 16px;
  }

  .app-header {
    padding: 22px 16px;
  }

  .app-shell {
    padding: 10px;
  }

  .tabs {
    overflow-x: auto;
    grid-template-columns: repeat(4, minmax(112px, 1fr));
    -webkit-overflow-scrolling: touch;
  }

  .tabs button {
    min-height: 52px;
    font-size: 0.88rem;
  }

  .panel,
  .quick-card,
  .settings-card,
  .advanced-box,
  .welcome-panel,
  .usage-guide,
  .setup-wizard,
  .order-check,
  .manual-price,
  .send-card,
  .breakdown-panel,
  .customer-card {
    padding: 14px;
  }

  .segmented {
    width: 100%;
  }

  .header-actions button {
    flex: 1;
  }

  .language-switcher {
    width: 100%;
  }

  .language-switcher button {
    min-height: 42px;
  }

  .metric-card {
    min-height: 104px;
  }

  .metric-card strong {
    font-size: clamp(1.9rem, 11vw, 2.55rem);
  }

  .line-item {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
    padding: 10px 0;
  }

  .line-item strong {
    text-align: left;
  }

  .app-footer {
    align-items: flex-start;
    flex-direction: column;
    padding: 8px 14px 24px;
  }
}
