:root {
  --bg: #f4f5f1;
  --panel: #ffffff;
  --panel-soft: #f8faf7;
  --ink: #16211d;
  --muted: #66736d;
  --line: #dfe5df;
  --green: #176f4d;
  --green-dark: #0f5138;
  --yellow: #f2b705;
  --blue: #1c5f8c;
  --red: #b93834;
  --shadow: 0 14px 34px rgba(23, 37, 31, 0.1);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

body.auth-pending .app-shell,
body.auth-locked .app-shell {
  filter: blur(2px);
  pointer-events: none;
  user-select: none;
}

body.auth-ready .login-screen {
  display: none;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(19, 35, 31, 0.72);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 4px;
  color: var(--ink);
}

.login-error {
  min-height: 20px;
  color: var(--red);
}

.login-help {
  color: var(--muted);
  font-size: 13px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #13231f;
  color: #fff;
  padding: 22px 16px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--yellow);
  color: #1f210f;
  font-weight: 800;
}

.brand span,
.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.sidebar .brand span {
  color: #a8b8b1;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 12px 14px;
  background: transparent;
  color: #d9e4df;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: #203830;
  border-color: #315346;
  color: #fff;
}

.main {
  min-width: 0;
  padding: 24px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 20px;
}

.top-actions,
.button-row,
.dialog-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.rate-pill,
.status-pill {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
}

.cloud-pill.online {
  border-color: #bee1d1;
  background: #eef8f3;
  color: var(--green-dark);
}

.cloud-pill.pending {
  border-color: #f0d98d;
  background: #fff9df;
  color: #735800;
}

.cloud-pill.offline {
  border-color: #efbbb6;
  background: #fff5f4;
  color: var(--red);
}

.user-pill {
  color: var(--ink);
}

.metric-grid,
.report-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  min-height: 90px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(23, 37, 31, 0.05);
}

.metric span {
  display: block;
  color: var(--muted);
  margin-bottom: 10px;
}

.metric strong {
  display: block;
  font-size: 25px;
  line-height: 1.15;
}

.metric.alert strong {
  color: var(--red);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.workspace {
  display: grid;
  gap: 18px;
}

.two-col {
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 0.75fr);
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #edf2ee;
}

.seg-btn {
  border: 0;
  border-radius: 6px;
  padding: 8px 12px;
  background: transparent;
  color: var(--muted);
}

.seg-btn.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 4px 10px rgba(23, 37, 31, 0.08);
}

.catalog-section {
  display: none;
  padding: 18px;
}

.catalog-section.active {
  display: block;
}

.quick-sale,
.search-row,
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.search-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.form-grid {
  padding: 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid.wide {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.settings-hint {
  align-self: end;
  min-height: 43px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid #cfe0ed;
  border-radius: var(--radius);
  background: #f1f7fb;
  color: #24465f;
  font-size: 13px;
  line-height: 1.35;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus {
  outline: 2px solid rgba(23, 111, 77, 0.22);
  border-color: var(--green);
}

.checkbox-line {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  align-self: end;
  min-height: 43px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

.checkbox-line input {
  width: 18px;
  height: 18px;
}

.station-select {
  width: auto;
  min-width: 160px;
  max-width: 220px;
  min-height: 42px;
  font-weight: 700;
}

.primary-button,
.ghost-button,
.danger-button,
.checkout-button {
  min-height: 42px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 10px 14px;
  font-weight: 700;
}

.primary-button {
  background: var(--green);
  color: #fff;
}

.primary-button:hover,
.checkout-button:hover {
  background: var(--green-dark);
}

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

.danger-button {
  background: #fff5f4;
  border-color: #f0c7c3;
  color: var(--red);
}

.checkout-button {
  width: 100%;
  background: var(--green);
  color: #fff;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 12px;
}

.product-card,
.fuel-card,
.pump-card,
.tank-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
}

.product-card h3,
.fuel-card h3,
.pump-card h3,
.tank-card h3 {
  margin: 0 0 8px;
  font-size: 17px;
}

.card-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.fuel-price {
  font-size: 24px;
  font-weight: 800;
  margin: 10px 0;
}

.card-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.card-actions button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.cart-panel {
  position: sticky;
  top: 16px;
}

.cart-list {
  display: grid;
  gap: 10px;
  padding: 16px;
  min-height: 180px;
  max-height: 42vh;
  overflow: auto;
}

.empty-state {
  place-items: center;
  color: var(--muted);
  background: #fbfcfb;
}

.cart-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.cart-item-title {
  font-weight: 700;
}

.qty-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.qty-controls button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.totals,
.payment-box {
  border-top: 1px solid var(--line);
  padding: 16px;
}

.totals {
  display: grid;
  gap: 8px;
}

.totals div,
.change-line,
.variance-box,
.summary-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.grand-total {
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-size: 20px;
}

.payment-box {
  display: grid;
  gap: 12px;
}

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

.change-line {
  padding: 12px;
  border-radius: var(--radius);
  background: #eef6f2;
}

.pump-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
  padding: 18px;
}

.pump-card {
  display: grid;
  gap: 10px;
}

.pump-status {
  display: inline-flex;
  width: max-content;
  padding: 5px 8px;
  border-radius: 999px;
  background: #e8f5ef;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 700;
}

.pump-status.busy {
  background: #fff5d8;
  color: #846000;
}

.tank-list {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.alert-panel {
  display: none;
  margin: 18px 18px 0;
  padding: 14px;
  border: 1px solid #efbbb6;
  border-radius: var(--radius);
  background: #fff5f4;
  color: #7e2622;
}

.alert-panel.active {
  display: grid;
  gap: 10px;
}

.alert-panel strong {
  color: var(--red);
}

.alert-panel ul {
  margin: 0;
  padding-left: 20px;
}

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

.tank-meter {
  height: 13px;
  border-radius: 999px;
  background: #e7ece8;
  overflow: hidden;
  margin: 12px 0;
}

.tank-meter span {
  display: block;
  height: 100%;
  background: var(--blue);
}

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

.table-wrap {
  overflow: auto;
  padding: 0 18px 18px;
}

.bot-layout {
  grid-template-columns: minmax(0, 1fr) 330px;
  align-items: start;
}

.bot-panel {
  min-height: 620px;
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto;
}

.bot-messages {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 18px;
  max-height: 58vh;
  overflow: auto;
  background: #fbfcfb;
}

.bot-message {
  max-width: min(680px, 92%);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  line-height: 1.55;
  white-space: pre-line;
}

.bot-message.user {
  justify-self: end;
  background: #eef6f2;
  border-color: #cce4d8;
}

.bot-message.bot {
  justify-self: start;
}

.bot-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid var(--line);
}

.bot-quick-list {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.bot-quick-list button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  text-align: left;
  padding: 10px 12px;
}

.bot-quick-list button:hover {
  border-color: var(--green);
  background: #eef6f2;
}

.remote-note {
  margin: 0 18px 18px;
  padding: 14px;
  border: 1px solid #cfe0ed;
  border-radius: var(--radius);
  background: #f1f7fb;
  color: #24465f;
  line-height: 1.5;
}

.remote-note p {
  margin-top: 7px;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  background: #fbfcfb;
}

td button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 7px 9px;
}

.summary-list {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.summary-list div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.settlement-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 18px 18px;
}

.counted-cash {
  margin: 0 18px 18px;
}

.variance-box {
  margin: 0 18px 18px;
  padding: 14px;
  border-radius: var(--radius);
  background: #f6f8f6;
  font-size: 20px;
}

.shift-readings-panel {
  grid-column: 1 / -1;
}

.reading-table {
  padding-top: 18px;
}

.reading-table tfoot td {
  font-weight: 800;
  background: #f6f8f6;
}

.reading-table input {
  min-width: 130px;
}

.backup-table {
  padding-top: 18px;
}

.backup-table .danger-button {
  min-height: 34px;
  padding: 6px 10px;
}

.receipt-dialog {
  width: min(420px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.receipt-dialog::backdrop {
  background: rgba(9, 15, 13, 0.45);
}

.receipt-content {
  font-family: "Consolas", "Courier New", monospace;
  white-space: pre-wrap;
  padding: 8px 2px 16px;
  color: #111;
}

.password-dialog {
  width: min(520px, calc(100vw - 28px));
}

.password-form {
  display: grid;
  gap: 14px;
}

.password-form .panel-head {
  padding: 0;
}

.password-hint {
  align-self: stretch;
  min-height: 0;
}

.dialog-actions {
  justify-content: flex-end;
}

@media print {
  body * {
    visibility: hidden;
  }

  .receipt-dialog,
  .receipt-dialog * {
    visibility: visible;
  }

  .receipt-dialog {
    position: absolute;
    inset: 0 auto auto 0;
    width: 80mm;
    border: 0;
    box-shadow: none;
  }

  .dialog-actions {
    display: none;
  }
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    gap: 16px;
    align-items: center;
    overflow-x: auto;
  }

  .brand {
    margin-bottom: 0;
    min-width: 180px;
  }

  .nav {
    display: flex;
  }

  .nav-item {
    white-space: nowrap;
  }

  .two-col,
  .bot-layout,
  .metric-grid,
  .report-grid,
  .quick-sale,
  .form-grid,
  .form-grid.wide {
    grid-template-columns: 1fr 1fr;
  }

  .cart-panel {
    position: static;
  }
}

@media (max-width: 680px) {
  .main {
    padding: 16px;
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .button-row {
    width: 100%;
  }

  .top-actions > *,
  .button-row > * {
    flex: 1;
  }

  .two-col,
  .bot-layout,
  .metric-grid,
  .report-grid,
  .quick-sale,
  .form-grid,
  .form-grid.wide,
  .payment-grid,
  .tank-actions {
    grid-template-columns: 1fr;
  }

  .search-row {
    grid-template-columns: 1fr;
  }

  .bot-composer {
    grid-template-columns: 1fr;
  }
}
