:root {
  --bg: #f6f5f1;
  --ink: #1d2524;
  --muted: #65706d;
  --line: #d9ddd6;
  --panel: #ffffff;
  --accent: #157f71;
  --accent-2: #c4492d;
  --focus: #f0b429;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}
body.logged-out .sidebar,
body.logged-out main {
  visibility: hidden;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}
.login-screen.hidden { display: none; }
.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}

.sidebar {
  background: #202826;
  color: #fff;
  padding: 22px;
}
.brand { display: grid; gap: 4px; margin-bottom: 28px; }
.brand strong { font-size: 24px; }
.brand span, .eyebrow, small { color: var(--muted); }
.sidebar .brand span { color: #b8c0bd; }
.nav { display: grid; gap: 8px; }
button, input, select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}
button {
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  font-weight: 700;
}
.nav-button {
  background: transparent;
  color: #dce4e1;
  text-align: left;
  padding: 0 12px;
}
.nav-button.active { background: #33403d; color: #fff; }

main { padding: 24px; overflow: auto; }
.view { display: none; }
.view.active { display: block; }
h1, h2, p { margin-top: 0; }
h1 { font-size: 28px; margin-bottom: 0; letter-spacing: 0; }
h2 { font-size: 17px; }
.eyebrow { margin-bottom: 6px; text-transform: uppercase; font-size: 12px; font-weight: 700; }

.tenant-context {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 1fr) minmax(160px, 0.7fr) minmax(180px, auto) auto;
  gap: 12px;
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 18px;
}
.tenant-context strong {
  min-height: 42px;
  display: flex;
  align-items: center;
  color: var(--accent);
}
.session-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}
.session-pill span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.session-pill button {
  min-height: 34px;
  padding: 0 12px;
  background: #4b5653;
}
.inline-control { min-width: 180px; }

.ad-slot {
  min-height: 74px;
  display: grid;
  place-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 18px;
}
.ad-preview {
  width: min(728px, 100%);
  min-height: 50px;
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 10px;
  align-items: center;
  justify-content: center;
  color: #56615e;
  background: #f7f9fc;
  border: 1px dashed #c7d0cc;
  border-radius: 8px;
  padding: 10px 14px;
}
.ad-preview-icon {
  width: 34px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
}
.ad-preview strong { color: var(--ink); }
.ad-preview small { color: var(--muted); }
.cordova-ad-preview {
  border-style: solid;
  background: #eef8f6;
}

.terminal-layout {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) 360px;
  gap: 18px;
}
.terminal-panel, .side-panel, .table-wrap, .cards .card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.terminal-panel, .side-panel { padding: 20px; }
.terminal-head, .section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}
.clock { font-weight: 700; color: var(--accent); }
.operator-card {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 18px;
}
.operator-card img, .employee-photo {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  background: #e4e7e3;
}
.operator-card strong { display: block; font-size: 22px; margin: 4px 0; }
.terminal-form, .form-grid, .withdrawal-form, .tenant-form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-weight: 700; color: #34403d; }
.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}
.check-line input {
  min-height: 0;
  width: 18px;
  height: 18px;
}
input, select { padding: 0 12px; background: #fff; color: var(--ink); }
input:focus, select:focus, button:focus { outline: 3px solid var(--focus); outline-offset: 2px; }
select { width: 100%; }
fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
legend { font-weight: 700; padding: 0 6px; }
.payment-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.payment-grid label {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.payment-grid b { color: var(--accent-2); }
.terminal-actions { display: grid; grid-template-columns: 1fr 160px; gap: 10px; }
#clearTerminal { background: #4b5653; }
.hidden { display: none; }
.confirmation-box {
  margin-top: 16px;
  border: 2px solid var(--focus);
  border-radius: 8px;
  padding: 14px;
  background: #fff9e7;
}
.confirmation-box strong { font-size: 20px; }
.confirmation-box p { margin: 8px 0 14px; line-height: 1.5; }

.summary-grid, .cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.summary-item, .card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfbf8;
}
.summary-item span, .card span { display: block; color: var(--muted); font-size: 13px; }
.summary-item strong, .card strong { font-size: 24px; display: block; margin-top: 5px; }
.summary-item p { margin: 8px 0 0; color: var(--muted); }

.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin: 16px 0 22px;
}
.report-chart {
  display: grid;
  gap: 12px;
  min-height: 230px;
  align-content: start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.report-chart-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}
.report-chart h2 {
  margin: 0;
  font-size: 16px;
}
.bar-row {
  display: grid;
  gap: 6px;
}
.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}
.bar-meta span {
  color: var(--ink);
  overflow-wrap: anywhere;
}
.bar-meta strong {
  white-space: nowrap;
}
.bar-track {
  height: 10px;
  overflow: hidden;
  background: #e8ece6;
  border-radius: 999px;
}
.bar-track span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #42a58c);
  border-radius: inherit;
}
.empty-report {
  margin: 0;
  color: var(--muted);
}
.compact-list { display: grid; gap: 8px; }
.compact-sale {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.compact-sale[data-move-id] { cursor: pointer; }
.compact-sale[data-move-id]:hover { background: #f4f6f1; }
.terminal-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.terminal-tab {
  background: #e8ece6;
  color: var(--ink);
}
.terminal-tab.active {
  background: var(--accent);
  color: #fff;
}
.terminal-tab-panel { display: none; }
.terminal-tab-panel.active { display: block; }
.withdrawal-form {
  grid-template-columns: 1fr 1fr;
  margin-bottom: 12px;
}
.withdrawal-form button { grid-column: 1 / -1; }

.tenant-admin {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.tenant-form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  align-content: start;
}
.tenant-form h2 { margin-bottom: 0; }

.form-grid {
  grid-template-columns: repeat(4, minmax(140px, 1fr)) 160px;
  align-items: end;
  margin-bottom: 18px;
}
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th, td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: #eef1ec; font-size: 13px; text-transform: uppercase; }
td button { min-height: 34px; padding: 0 10px; margin-right: 6px; }
.danger { background: var(--accent-2); }
.muted-button { background: #68736f; }
.toast {
  position: fixed;
  right: 20px;
  top: 20px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(420px, calc(100vw - 32px));
  background: #fff;
  color: var(--ink);
  padding: 14px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: 0 18px 48px rgba(29, 37, 36, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-12px) scale(0.98);
  transition: 0.18s ease;
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); }
.toast-icon {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #fff;
  font-weight: 900;
}
.toast-success .toast-icon { background: #087443; }
.toast-error .toast-icon { background: var(--accent-2); }
.toast-info .toast-icon { background: var(--accent); }

.app-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(18, 24, 23, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.app-dialog-overlay.show {
  opacity: 1;
  pointer-events: auto;
}
.app-dialog {
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
  justify-items: center;
  text-align: center;
  background: #fff;
  border: 1px solid #e3e7e2;
  border-radius: 8px;
  padding: 26px;
  box-shadow: 0 24px 70px rgba(18, 24, 23, 0.28);
  transform: translateY(8px) scale(0.96);
  transition: transform 0.18s ease;
}
.app-dialog-overlay.show .app-dialog { transform: translateY(0) scale(1); }
.app-dialog-icon {
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 34px;
  font-weight: 900;
  border: 3px solid currentColor;
}
.dialog-success { color: #087443; background: #ecfdf3; }
.dialog-info { color: var(--accent); background: #eef8f6; }
.dialog-warning { color: #b7791f; background: #fff7e6; }
.dialog-danger { color: var(--accent-2); background: #fff1ee; }
.app-dialog h2 {
  margin: 0;
  font-size: 24px;
}
.app-dialog p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}
.app-dialog-input {
  width: 100%;
  text-align: left;
}
.app-dialog-actions {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}
.app-dialog-actions.single { grid-template-columns: 1fr; }
.dialog-secondary {
  background: #eef1ec;
  color: var(--ink);
}

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tenant-context, .terminal-layout, .form-grid, .tenant-admin { grid-template-columns: 1fr; }
  .terminal-actions, .payment-grid, .app-dialog-actions { grid-template-columns: 1fr; }
  .section-head { flex-wrap: wrap; }
  .section-head .inline-control { width: 100%; }
  .report-grid { grid-template-columns: 1fr; }
}
