:root {
  font-family: "Segoe UI", Arial, sans-serif;
  color: #172033;
  background: #f5f7fa;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; background: #f5f7fa; color: #172033; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { width: min(1440px, 100%); margin: 0 auto; min-height: 100vh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 28px 32px 20px; background: #fff; border-bottom: 1px solid #e7ebf0;
}
.brand-wrap { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark {
  width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center;
  background: #1f5a43; color: #fff; font-weight: 800; letter-spacing: .4px;
}
h1 { font-size: 22px; margin: 0 0 4px; line-height: 1.25; }
.data-date, .muted { margin: 0; color: #6b7280; }
.data-date { font-size: 14px; }
.month-box { display: grid; gap: 5px; min-width: 190px; }
.month-box label, .filters label > span { color: #6b7280; font-size: 13px; font-weight: 600; }
select, input {
  min-height: 42px; border: 1px solid #d7dde5; border-radius: 10px; background: #fff;
  color: #172033; padding: 8px 12px; outline: none;
}
select:focus, input:focus { border-color: #3c7b61; box-shadow: 0 0 0 3px rgba(60,123,97,.12); }

.main-nav {
  display: flex; gap: 8px; padding: 12px 32px; background: #fff; border-bottom: 1px solid #e7ebf0;
  overflow-x: auto; position: sticky; top: 0; z-index: 10;
}
.nav-btn {
  white-space: nowrap; border: 0; background: transparent; color: #5e6675; padding: 10px 14px;
  border-radius: 9px; font-weight: 650;
}
.nav-btn:hover { background: #f2f6f4; color: #1f5a43; }
.nav-btn.active { background: #e9f3ee; color: #164c38; }
.badge { display: inline-grid; place-items: center; margin-left: 5px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 12px; background: #b94a35; color: #fff; font-size: 12px; }

main { padding: 28px 32px 52px; }
.view { display: none; }
.view.active { display: block; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.section-heading h2 { margin: 2px 0 0; font-size: 27px; line-height: 1.25; }
.eyebrow { margin: 0; color: #607266; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .09em; }
.text-btn { border: 0; padding: 8px 0; background: none; color: #1f6b4d; font-weight: 750; }
.text-btn:hover { text-decoration: underline; }
.text-btn.small { font-size: 14px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi-card { background: #fff; border: 1px solid #e4e8ed; border-radius: 15px; padding: 18px; min-height: 130px; display: flex; flex-direction: column; }
.kpi-card.primary { background: #164c38; border-color: #164c38; color: #fff; }
.kpi-label { font-size: 13px; color: #697181; font-weight: 700; }
.kpi-card.primary .kpi-label, .kpi-card.primary small { color: #d8ebe2; }
.kpi-card strong { display: block; font-size: clamp(24px, 2.5vw, 33px); line-height: 1.1; margin: 16px 0 7px; letter-spacing: -.02em; }
.kpi-card small { color: #777f8c; margin-top: auto; line-height: 1.4; }

.overview-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(290px, .9fr); gap: 16px; margin-bottom: 16px; }
.panel { background: #fff; border: 1px solid #e4e8ed; border-radius: 15px; padding: 20px; }
.compact-panel { padding: 14px; }
.panel-title-row { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.panel h3 { margin: 3px 0 0; font-size: 18px; }

.bar-chart { display: grid; grid-template-columns: repeat(12, minmax(36px, 1fr)); gap: 12px; align-items: end; min-height: 245px; margin-top: 18px; overflow-x: auto; padding: 8px 2px 0; }
.bar-item { min-width: 45px; display: grid; grid-template-rows: 1fr auto; gap: 8px; height: 210px; text-align: center; }
.bar-track { display: flex; align-items: end; justify-content: center; min-height: 165px; border-bottom: 1px solid #e6e9ee; position: relative; }
.bar { width: min(38px, 72%); min-height: 3px; border-radius: 8px 8px 3px 3px; background: #4d836c; transition: height .2s ease; position: relative; }
.bar.zero { background: #dfe5e1; }
.bar-value { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(100% + 7px); color: #5d6673; font-size: 11px; white-space: nowrap; font-weight: 650; }
.bar-month { color: #646d7a; font-size: 12px; font-weight: 700; }

.attention-panel { display: flex; flex-direction: column; }
.attention-message { margin-top: 18px; padding: 15px; border-radius: 12px; background: #fff7e8; border: 1px solid #f1dfb9; }
.attention-message.good { background: #edf6f1; border-color: #d2e7dc; }
.attention-message strong { display: block; font-size: 17px; margin-bottom: 5px; }
.attention-message p { margin: 0; color: #606775; line-height: 1.5; }
.attention-action { margin-top: 14px; }

.recent-list { display: grid; gap: 0; margin-top: 10px; }
.recent-row { display: grid; grid-template-columns: 108px minmax(0, 1fr) 150px 120px; gap: 14px; align-items: center; padding: 13px 2px; border-top: 1px solid #edf0f3; }
.recent-row:first-child { border-top: 0; }
.recent-desc { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amount { text-align: right; font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.payment-pill { display: inline-flex; align-items: center; justify-content: center; width: fit-content; max-width: 100%; padding: 5px 9px; border-radius: 999px; background: #edf3f0; color: #2f614d; font-size: 12px; font-weight: 700; white-space: nowrap; }
.payment-pill.missing { background: #fff0e9; color: #a34e34; }
.payment-pill.other { background: #f0f1f4; color: #5f6570; }

.filters { display: grid; grid-template-columns: minmax(280px, 1fr) 220px auto; gap: 12px; align-items: end; margin-bottom: 14px; }
.filters label { display: grid; gap: 5px; }
.secondary-btn { min-height: 42px; border: 1px solid #d7dde5; border-radius: 10px; background: #fff; color: #3f4754; padding: 8px 14px; font-weight: 700; }
.secondary-btn:hover { background: #f7f8fa; }

.table-wrap { padding: 0; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { background: #f8f9fb; color: #646c79; text-align: left; padding: 12px 14px; font-size: 12px; letter-spacing: .02em; border-bottom: 1px solid #e5e9ee; }
td { padding: 13px 14px; border-bottom: 1px solid #edf0f3; vertical-align: middle; font-size: 14px; }
tbody tr:hover { background: #fbfcfc; }
tbody tr:last-child td { border-bottom: 0; }
.money-col { text-align: right; }
.ledger-desc { max-width: 520px; line-height: 1.35; }
.row-action { border: 0; background: none; color: #1f6b4d; font-weight: 700; padding: 7px; }
.row-action:hover { text-decoration: underline; }
.tax-cell { color: #5f6672; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty-state { text-align: center; padding: 46px 20px; color: #68707d; }
.empty-state strong { color: #2b3240; display: block; margin-bottom: 6px; }
.empty-state p { margin: 0; }

.month-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.month-card { background: #fff; border: 1px solid #e4e8ed; border-radius: 14px; padding: 18px; }
.month-card.empty { background: #fafbfc; }
.month-card-head { display: flex; align-items: start; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.month-card h3 { margin: 0; font-size: 17px; }
.month-card .month-total { font-size: 24px; font-weight: 800; margin: 5px 0 4px; }
.trend { font-size: 12px; color: #68707d; }
.trend.up { color: #28704f; }
.trend.down { color: #9a4c3b; }
.month-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; border-top: 1px solid #edf0f3; padding-top: 14px; }
.month-stat span { display: block; color: #777f8b; font-size: 11px; margin-bottom: 3px; }
.month-stat strong { font-size: 14px; }
.no-data { color: #6f7681; margin: 9px 0 18px; }

.check-summary { margin-bottom: 14px; }
.check-banner { background: #fff7e8; border: 1px solid #f1dfb9; border-radius: 14px; padding: 17px 18px; }
.check-banner.good { background: #edf6f1; border-color: #d2e7dc; }
.check-banner strong { display: block; font-size: 18px; margin-bottom: 4px; }
.check-banner p { margin: 0; color: #646b77; }
.check-list { display: grid; gap: 10px; }
.check-item { display: grid; grid-template-columns: 110px minmax(0, 1fr) 145px auto; gap: 14px; align-items: center; background: #fff; border: 1px solid #e4e8ed; border-radius: 12px; padding: 14px 16px; }
.check-item .reason { color: #9a4c3b; font-size: 13px; font-weight: 700; }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 18px 32px 30px; color: #7a818c; font-size: 12px; }

dialog { width: min(620px, calc(100% - 28px)); border: 0; border-radius: 16px; padding: 0; box-shadow: 0 24px 80px rgba(20,31,45,.25); }
dialog::backdrop { background: rgba(20,30,40,.42); }
.dialog-head { display: flex; justify-content: space-between; align-items: start; gap: 20px; padding: 20px 22px 15px; border-bottom: 1px solid #e8ebef; }
.dialog-head h3 { margin: 3px 0 0; font-size: 21px; }
.icon-btn { border: 0; background: #f2f4f6; width: 36px; height: 36px; border-radius: 50%; font-size: 23px; line-height: 1; }
.detail-content { padding: 18px 22px 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.detail-field { border-bottom: 1px solid #edf0f3; padding-bottom: 10px; }
.detail-field.full { grid-column: 1 / -1; }
.detail-field span { display: block; color: #747c88; font-size: 12px; margin-bottom: 4px; }
.detail-field strong, .detail-field p { margin: 0; line-height: 1.45; }
.detail-field p { white-space: pre-wrap; }

@media (max-width: 980px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-grid { grid-template-columns: 1fr; }
  .month-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .recent-row { grid-template-columns: 92px minmax(0, 1fr) 130px; }
  .recent-row .payment-pill { display: none; }
  .check-item { grid-template-columns: 90px minmax(0, 1fr) auto; }
  .check-item .reason { grid-column: 2 / 3; }
}

@media (max-width: 720px) {
  .topbar { align-items: stretch; flex-direction: column; padding: 20px 16px 16px; }
  .main-nav { padding: 10px 16px; }
  main { padding: 22px 16px 42px; }
  .month-box { width: 100%; }
  .section-heading { align-items: start; }
  .section-heading h2 { font-size: 23px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-card { min-height: 116px; padding: 14px; }
  .kpi-card strong { font-size: 23px; }
  .panel { padding: 16px; }
  .filters { grid-template-columns: 1fr; }
  .filters .secondary-btn { width: 100%; }
  .table-wrap { overflow-x: auto; padding: 0; }
  table { min-width: 760px; }
  .month-cards { grid-template-columns: 1fr; }
  .recent-row { grid-template-columns: 84px minmax(0, 1fr) 120px; gap: 9px; }
  .recent-row .amount { font-size: 13px; }
  .check-item { grid-template-columns: 80px minmax(0, 1fr); }
  .check-item .amount, .check-item .row-action { grid-column: 2; text-align: left; justify-self: start; }
  footer { flex-direction: column; padding: 16px; }
  .detail-content { grid-template-columns: 1fr; }
  .detail-field.full { grid-column: auto; }
}

@media (max-width: 460px) {
  .brand-mark { width: 44px; height: 44px; border-radius: 12px; }
  h1 { font-size: 19px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .bar-chart { gap: 8px; }
  .recent-row { grid-template-columns: 80px minmax(0,1fr); }
  .recent-row .amount { grid-column: 2; text-align: left; }
}

/* Order entry + quarterly summary */
.order-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, .8fr); gap: 16px; align-items: start; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid label { display: grid; gap: 6px; min-width: 0; }
.form-grid label > span { color: #646d79; font-size: 13px; font-weight: 700; }
.form-grid .full { grid-column: 1 / -1; }
.tax-preview { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 18px 0; }
.tax-preview > div { background: #f6f8f7; border: 1px solid #e3e9e5; border-radius: 11px; padding: 12px; }
.tax-preview span { display: block; color: #6b7480; font-size: 12px; margin-bottom: 5px; }
.tax-preview strong { font-size: 16px; }
.form-actions { display: flex; gap: 10px; align-items: center; }
.primary-btn { min-height: 42px; border: 0; border-radius: 10px; background: #164c38; color: #fff; padding: 9px 18px; font-weight: 800; }
.primary-btn:hover { background: #0f3d2c; }
.form-note { color: #727a85; font-size: 12px; line-height: 1.5; margin: 14px 0 0; }
.save-notice { background: #eaf5ef; border: 1px solid #cce3d6; color: #225c43; border-radius: 11px; padding: 11px 13px; margin-bottom: 16px; font-weight: 700; }
.local-orders-list { display: grid; gap: 0; margin-top: 10px; }
.local-order-item { display: flex; justify-content: space-between; gap: 12px; padding: 13px 0; border-top: 1px solid #edf0f3; }
.local-order-item:first-child { border-top: 0; }
.local-order-main { display: grid; gap: 3px; min-width: 0; }
.local-order-main span, .local-order-main small { color: #747c87; font-size: 12px; }
.local-order-main strong { overflow: hidden; text-overflow: ellipsis; }
.local-order-side { display: grid; justify-items: end; align-content: start; gap: 5px; white-space: nowrap; }
.delete-local-order { border: 0; background: none; color: #9a4c3b; padding: 2px 0; font-size: 12px; font-weight: 700; }
.empty-mini { padding: 22px 4px; color: #69717d; }
.empty-mini strong { display: block; color: #333b47; margin-bottom: 5px; }
.empty-mini p { margin: 0; line-height: 1.5; }

.quarter-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.quarter-card { background: #fff; border: 1px solid #e4e8ed; border-radius: 15px; padding: 19px; min-width: 0; }
.quarter-card.empty { background: #fafbfc; }
.quarter-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.quarter-head h3 { margin: 4px 0 0; font-size: 20px; }
.quarter-count { background: #edf3f0; color: #2d624d; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 750; white-space: nowrap; }
.quarter-revenue { font-size: clamp(27px, 3vw, 36px); font-weight: 850; letter-spacing: -.03em; margin: 20px 0 6px; }
.quarter-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; margin-top: 18px; }
.quarter-stats > div { border-top: 1px solid #edf0f3; padding-top: 10px; min-width: 0; }
.quarter-stats span, .quarter-months span { display: block; color: #777f8b; font-size: 11px; margin-bottom: 4px; }
.quarter-stats strong { font-size: 14px; overflow-wrap: anywhere; }
.quarter-months { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.quarter-months > div { background: #f7f9f8; border-radius: 9px; padding: 9px; min-width: 0; }
.quarter-months strong { font-size: 13px; overflow-wrap: anywhere; }

@media (max-width: 980px) {
  .order-layout { grid-template-columns: 1fr; }
  .quarter-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .tax-preview { grid-template-columns: 1fr; }
  .form-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .primary-btn, .form-actions .secondary-btn { width: 100%; }
  .quarter-cards { grid-template-columns: 1fr; }
  .quarter-months { grid-template-columns: 1fr; }
}

/* Mobile E2E fix: keep cards and primary navigation inside one screen. */
.overview-grid > *, .panel { min-width: 0; }
.bar-chart { min-width: 0; max-width: 100%; }

@media (max-width: 720px) {
  .main-nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow-x: hidden;
    gap: 8px;
  }
  .nav-btn {
    width: 100%;
    min-width: 0;
    white-space: normal;
    text-align: center;
    padding: 10px 8px;
  }
  .overview-grid, .overview-grid > *, .panel { min-width: 0; max-width: 100%; }
  .bar-chart { width: 100%; min-width: 0; }
}
