:root {
  --bg: #f3f3f3;
  --panel: #ffffff;
  --side: #ececec;
  --line: #e6e6e6;
  --line-strong: #d4d4d8;
  --text: #111827;
  --muted: #6b7280;
  --soft: #f8fafc;
  --teal: #0f766e;
  --teal-dark: #0b5f58;
  --blue: #2563eb;
  --ml-yellow: #fff159;
  --amber: #f59e0b;
  --green: #16a34a;
  --danger: #b91c1c;
  --shadow: 0 18px 42px rgba(17, 24, 39, .12);
  --radius: 10px;
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 86% 12%, rgba(37, 99, 235, .08), transparent 24%),
    radial-gradient(circle at 18% 8%, rgba(15, 118, 110, .08), transparent 22%),
    var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

input,
select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #64748b 50%),
    linear-gradient(135deg, #64748b 50%, transparent 50%);
  background-position:
    calc(100% - 17px) 16px,
    calc(100% - 12px) 16px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

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

.boot-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
}

.boot-logo {
  width: min(260px, 68vw);
}

.auth-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.brand-panel {
  width: min(470px, 100%);
  border: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  padding: 22px;
  background: var(--side);
  box-shadow: var(--shadow);
}

.brand-logo {
  display: block;
  width: min(300px, 78vw);
  height: 92px;
  object-fit: contain;
  margin: 0 auto 14px;
  mix-blend-mode: multiply;
}

.brand-panel h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.08;
}

.lead {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.auth-card {
  width: min(470px, 100%);
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 12px 12px;
  padding: 20px;
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(17, 24, 39, .10);
}

.stacked-form {
  width: 100%;
  display: grid;
  gap: 14px;
}

.stacked-form label {
  display: grid;
  gap: 7px;
  color: #374151;
  font-size: 13px;
  font-weight: 700;
}

.stacked-form h2 {
  margin-bottom: 2px;
  font-size: 22px;
}

.eyebrow,
.form-kicker {
  margin: 0 0 7px;
  color: var(--teal-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.form-divider {
  height: 1px;
  background: var(--line);
}

.form-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.primary-button,
.soft-button,
.ghost-button,
.danger-button,
.row-button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  transition: background .15s ease, transform .15s ease, box-shadow .15s ease;
}

.primary-button {
  background: var(--teal);
  color: #fff;
  box-shadow: 0 12px 24px rgba(15, 118, 110, .18);
}

.primary-button:hover,
.soft-button:hover,
.danger-button:hover,
.row-button:hover {
  transform: translateY(-1px);
}

.soft-button {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #111827;
}

.ghost-button {
  background: transparent;
  color: #4b5563;
}

.ghost-button:hover {
  background: #fff;
  color: var(--text);
}

.danger-button {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.row-button {
  min-height: 32px;
  background: #111827;
  color: #fff;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 16px;
  background: var(--side);
  border-right: 1px solid #d9d9d9;
}

.sidebar-brand {
  height: 82px;
  display: grid;
  place-items: center;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.sidebar-brand img {
  width: 216px;
  height: 66px;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.sidebar-nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 10px;
  padding: 0 10px;
  background: transparent;
  color: #222;
  text-align: left;
  font-size: 15px;
  font-weight: 700;
}

.nav-item:hover,
.nav-item.is-active {
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--line);
}

.nav-item.is-active {
  color: var(--teal-dark);
}

.nav-icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--teal-dark);
  font-size: 13px;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.status-pill {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 7px;
  background: #9ca3af;
}

.status-pill.live {
  background: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}

.status-pill.live::before {
  background: var(--green);
}

.status-pill.offline {
  background: #fef2f2;
  color: var(--danger);
  border-color: #fecaca;
}

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

.content {
  min-width: 0;
  padding: 18px 20px 24px;
}

.topbar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  background:
    linear-gradient(90deg, rgba(255, 241, 89, .24), transparent 46%),
    #fff;
  box-shadow: 0 12px 30px rgba(17, 24, 39, .06);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 2.7vw, 34px);
  line-height: 1.08;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

#connect-button {
  background: var(--blue);
  box-shadow: 0 12px 24px rgba(37, 99, 235, .18);
}

.alert-area {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.alert {
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 12px 14px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 13px;
  font-weight: 700;
}

.alert.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--danger);
}

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

.metric-grid.is-hidden {
  display: none;
}

.metric-card {
  min-height: 96px;
  display: grid;
  align-content: space-between;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(17, 24, 39, .06);
}

.metric-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-card strong {
  color: #111;
  font-size: clamp(22px, 2.2vw, 30px);
  letter-spacing: 0;
}

.metric-card:nth-child(2) {
  border-color: rgba(15, 118, 110, .22);
  background: linear-gradient(180deg, #fff, #f0fdfa);
}

.metric-card:nth-child(2) strong {
  color: var(--teal-dark);
}

.metric-card.warning strong {
  color: var(--amber);
}

.section-panel {
  display: none;
}

.section-panel.is-visible {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(310px, 390px);
  gap: 12px;
  align-items: start;
}

.reports-section.is-visible {
  grid-template-columns: 1fr;
}

.center-menu,
.receipt-panel,
.wide-panel,
.settings-panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(17, 24, 39, .08);
}

.center-menu {
  overflow: hidden;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.section-heading h2,
.receipt-toolbar h2,
.wide-panel h2,
.settings-panel h2 {
  margin: 0;
  font-size: 20px;
}

.filter-bar {
  width: min(500px, 100%);
  display: grid;
  grid-template-columns: minmax(190px, 1fr) 170px;
  gap: 10px;
}

.advanced-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.advanced-filters label {
  display: grid;
  gap: 6px;
  color: #374151;
  font-size: 12px;
  font-weight: 800;
}

.advanced-filters [hidden] {
  display: none !important;
}

#search-input {
  border: 2px dashed #cfcfcf;
  border-radius: 10px;
}

.table-shell {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  table-layout: fixed;
}

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

th {
  height: 42px;
  background: #fafafa;
  color: #000;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

td {
  color: #222;
  font-weight: 700;
}

tbody tr {
  transition: background .12s ease;
}

tbody tr:hover {
  background: #f8fafc;
}

tr.is-selected {
  background: #ecfdf5;
}

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

.situation-pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 0 9px;
  background: #fff;
  color: #334155;
  font-size: 12px;
  font-weight: 800;
}

.empty-row {
  height: 78px;
  color: var(--muted);
  text-align: center;
}

.batch-print {
  display: none;
}

.monthly-report-content {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.monthly-report-content[hidden] {
  display: none;
}

.report-empty,
.report-note {
  margin: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.report-empty[hidden] {
  display: none;
}

.report-note {
  margin: 0;
  border-color: #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
}

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

.report-kpi-grid .metric-card:nth-child(3) {
  border-color: rgba(4, 120, 87, .24);
  background: linear-gradient(180deg, #fff, #ecfdf5);
}

.report-kpi-grid .metric-card:nth-child(3) strong,
#report-profit {
  color: #047857;
}

#report-profit.negative {
  color: var(--danger);
}

.report-breakdown {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.report-line {
  display: grid;
  gap: 8px;
  min-height: 76px;
  padding: 14px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.report-line span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.report-line strong {
  color: #111827;
  font-size: 18px;
}

.report-line.total {
  background: #f0fdfa;
}

.report-line.total strong {
  color: var(--teal-dark);
}

.receipt-panel {
  position: sticky;
  top: 18px;
  padding: 14px;
}

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

.cost-editor {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #f8fafc;
}

.cost-editor label {
  display: grid;
  gap: 6px;
  color: #374151;
  font-size: 12px;
  font-weight: 800;
}

.field-hint {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
}

.cost-editor p {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.receipt {
  position: relative;
  overflow: hidden;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 16px;
  background:
    linear-gradient(180deg, #fff 0%, #f8fafc 100%);
}

.receipt::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 6px;
  background: linear-gradient(90deg, var(--ml-yellow), var(--blue), var(--teal));
}

.receipt-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 0 14px;
  border-bottom: 2px solid #111827;
}

.receipt-header img {
  width: 126px;
  height: 48px;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.receipt-header h3 {
  margin: 0 0 4px;
  font-size: 18px;
}

.receipt-header p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.receipt-lines {
  display: grid;
  gap: 0;
  margin: 14px 0 0;
}

.receipt-lines div {
  display: grid;
  gap: 5px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.receipt-lines div:last-child {
  border-bottom: 0;
}

.receipt-lines dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.receipt-lines dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  font-weight: 800;
}

#receipt-net {
  color: var(--teal-dark);
  font-size: 22px;
}

#receipt-profit {
  color: #047857;
  font-size: 22px;
}

#receipt-profit.negative {
  color: var(--danger);
}

.period-summary {
  max-width: 720px;
}

.period-summary .receipt-lines {
  margin-top: 10px;
}

.period-summary .receipt-lines div {
  grid-template-columns: minmax(140px, 1fr) auto;
  align-items: end;
  gap: 12px;
  padding: 9px 0;
}

.period-summary .receipt-lines dd {
  text-align: right;
}

.summary-profit {
  color: #047857;
  font-size: 22px !important;
}

.summary-profit.negative {
  color: var(--danger);
}

.wide-panel {
  grid-column: 1 / -1;
  overflow: hidden;
}

.costs-section.is-visible {
  grid-template-columns: 1fr;
}

.cost-presets-form {
  display: grid;
  gap: 0;
}

.preset-base-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.preset-base-grid label {
  display: grid;
  gap: 7px;
  color: #374151;
  font-size: 12px;
  font-weight: 800;
}

.preset-table-shell {
  overflow-x: auto;
}

.preset-table {
  min-width: 720px;
}

.preset-table input {
  width: 180px;
}

.connection-section.is-visible {
  grid-template-columns: 1fr;
}

.ml-connection-page {
  grid-column: 1 / -1;
  padding: 0 0 4px;
}

.ml-connection-page h2 {
  margin: 0 0 12px;
  color: #020617;
  font-size: 24px;
  line-height: 1.15;
}

.ml-connection-page > p {
  margin: 0 0 16px;
  color: #475569;
  font-size: 13px;
}

.ml-connect-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 12px;
}

.ml-connect-card {
  min-height: 144px;
  border: 1px solid #d9dde3;
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

.ml-connect-card h3 {
  margin: 0 0 12px;
  color: #020617;
  font-size: 16px;
}

.ml-connect-card p {
  margin: 0 0 14px;
  max-width: 520px;
  color: #475569;
  font-size: 13px;
  line-height: 1.38;
}

.ml-connect-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ml-blue-button,
.ml-remove-button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0 11px;
  font-size: 13px;
  font-weight: 800;
}

.ml-blue-button {
  background: #3483fa;
  color: #fff;
}

.ml-blue-button:hover,
.ml-remove-button:hover {
  transform: translateY(-1px);
}

.ml-remove-button {
  border: 1px solid #fecaca;
  background: #fff;
  color: #b91c1c;
}

.ml-callback-input {
  height: 36px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #f3f4f6;
  color: #020617;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.permissions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
  padding: 14px;
}

.permission-card {
  min-height: 170px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: linear-gradient(180deg, #fff, #f8fafc);
}

.permission-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.permission-card p {
  color: var(--muted);
  line-height: 1.45;
}

.permission-card code {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 0 9px;
  background: #fff;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
}

.settings-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(320px, 560px) minmax(300px, 1fr);
  gap: 12px;
}

.settings-panel {
  padding: 16px;
}

.copy-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin: 14px 0 12px;
}

@media (max-width: 1080px) {
  .dashboard {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
  }

  .sidebar-brand {
    width: 160px;
    height: 64px;
    border-bottom: 0;
  }

  .sidebar-brand img {
    width: 150px;
  }

  .sidebar-nav {
    grid-auto-flow: column;
    overflow-x: auto;
  }

  .sidebar-footer {
    min-width: 150px;
  }

  .section-panel.is-visible {
    grid-template-columns: 1fr;
  }

  .receipt-panel {
    position: static;
  }

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

@media (max-width: 760px) {
  .auth-layout {
    padding: 14px;
  }

  .brand-panel,
  .auth-card {
    padding: 16px;
  }

  .brand-panel h1 {
    font-size: 24px;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .sidebar-brand {
    width: 100%;
  }

  .sidebar-nav {
    grid-auto-flow: row;
  }

  .content {
    padding: 12px;
  }

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

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions button {
    flex: 1 1 150px;
  }

  .metric-grid,
  .settings-grid,
  .preset-base-grid,
  .report-kpi-grid,
  .report-breakdown {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-bar,
  .copy-field,
  .cost-editor,
  .advanced-filters,
  .ml-connect-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    margin: 10mm;
  }

  html,
  body {
    background: #fff;
    margin: 0;
  }

  .sidebar,
  .topbar,
  .alert-area,
  .metric-grid,
  .center-menu,
  .receipt-toolbar,
  .cost-editor,
  .wide-panel,
  .settings-grid,
  .section-panel,
  .section-panel.is-visible {
    display: none !important;
  }

  .dashboard,
  .content,
  .section-panel[data-panel="sales"],
  .receipt-panel {
    display: block !important;
    min-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    border: 0 !important;
    background: #fff !important;
  }

  .section-panel[data-panel="sales"] > :not(.receipt-panel) {
    display: none !important;
  }

  body.is-batch-printing .section-panel[data-panel="sales"],
  body.is-batch-printing .receipt-panel {
    display: none !important;
  }

  body.is-batch-printing .batch-print {
    display: block !important;
  }

  .receipt {
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    border: 2px solid #111;
    box-shadow: none;
    page-break-inside: avoid;
  }

  .batch-receipt {
    margin-bottom: 10mm;
    page-break-after: always;
  }

  .batch-receipt:last-child {
    page-break-after: auto;
  }

  .period-summary {
    max-width: 720px;
    padding: 14px 18px;
  }

  .period-summary .receipt-header {
    padding: 6px 0 10px;
  }

  .period-summary .receipt-lines div {
    padding: 7px 0;
  }

  .period-summary .receipt-lines dt {
    font-size: 10px;
  }

  .period-summary .receipt-lines dd {
    font-size: 13px;
  }

  .period-summary .summary-profit {
    font-size: 20px !important;
  }
}
