* { box-sizing: border-box; }

:root {
  font-family: Inter, Arial, sans-serif;
  background: #f5f7fb;
  color: #182033;
}

body {
  margin: 0;
  min-height: 100vh;
}

body.cloud-initializing .app-content,
body.cloud-initializing .login-screen { display: none !important; }
body:not(.cloud-initializing) .boot-screen { display: none; }
body.cloud-locked .app-content { display: none !important; }
body:not(.cloud-locked) .login-screen { display: none; }
.boot-screen { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 12px; background: #f5f7fb; color: #182033; }
.boot-screen img { border-radius: 18px; box-shadow: 0 12px 30px rgba(31,94,255,.2); }
.boot-screen strong { font-size: 24px; }
.boot-screen span { color: #667085; font-size: 14px; }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: #f5f7fb; }
.login-card { width: min(420px, 100%); display: grid; gap: 16px; padding: 30px; border-radius: 16px; background: white; box-shadow: 0 18px 50px rgba(20,30,55,.12); }
.login-card h1, .login-card p { margin: 0; }
.topbar-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.cloud-status { font-size: 13px; color: #667085; }
.cloud-status.syncing { color: #9a6700; }
.cloud-status.error { color: #a51d1d; }
.cloud-status.online { color: #17683a; }

button, input, select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  cursor: pointer;
  background: #1f5eff;
  color: white;
  font-weight: 700;
}

button:hover { opacity: 0.92; }
button:disabled { cursor: not-allowed; opacity: .5; }

button.secondary {
  background: #e9eefc;
  color: #203052;
}

button.whatsapp {
  background: #128c7e;
}

button.danger {
  background: #ffe8e8;
  color: #a51d1d;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px clamp(18px, 5vw, 70px);
  background: white;
  border-bottom: 1px solid #e4e8f0;
}

.topbar h1 { margin: 0; }
.topbar p { margin: 4px 0 0; color: #6b7280; }

.layout {
  width: min(1100px, calc(100% - 28px));
  margin: 28px auto 60px;
  display: grid;
  gap: 20px;
}

.panel {
  background: white;
  padding: 24px;
  border-radius: 16px;
  box-shadow: 0 8px 25px rgba(20, 30, 55, 0.07);
}

.panel h2 {
  margin-top: 0;
}

.section-heading,
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

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

.form-grid .wide { grid-column: 1 / -1; }

label {
  display: grid;
  gap: 7px;
  font-size: 14px;
  font-weight: 700;
  color: #3b455d;
}

input, select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #ccd3e0;
  border-radius: 9px;
  background: white;
}

.add-item-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 130px 160px auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 18px;
}

.product-filters, .manager-toolbar { display: grid; grid-template-columns: minmax(0, 2fr) minmax(180px, 1fr); gap: 10px; margin-bottom: 12px; }
.manager-toolbar { margin-top: 20px; margin-bottom: 0; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.product-category { display: inline-block; margin-top: 5px; padding: 3px 8px; border-radius: 999px; background: #eef3ff; color: #3157a4; font-size: 12px; font-weight: 700; }
.empty-state { padding: 22px 0; text-align: center; color: #6b7280; }
.import-preview { margin-top: 16px; padding: 16px; border-radius: 10px; background: #f4f7fc; }
.import-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.import-summary div { padding: 12px; border-radius: 9px; background: white; text-align: center; }
.danger-zone { margin-top: 24px; padding-top: 20px; border-top: 1px solid #e8ebf1; }
.danger-zone h3 { color: #9d2424; }
.danger-zone input { margin-bottom: 10px; }

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

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid #e8ebf1;
}

th {
  color: #667085;
  font-size: 13px;
}

.totals-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 20px;
}

.summary {
  width: min(390px, 100%);
  margin: 22px 0 0 auto;
  display: grid;
  gap: 10px;
}

.summary div,
.receipt-totals p {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin: 0;
}

.grand-total,
.receipt-total {
  font-size: 20px;
  border-top: 2px solid #182033;
  padding-top: 12px;
}

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

.customer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.customer-picker-label { margin-top: 16px; }
.customer-picker { min-height: 132px; padding: 6px; }
.customer-picker option { padding: 9px 10px; border-radius: 6px; }
.customer-picker option:checked { background: #1f5eff linear-gradient(0deg, #1f5eff 0%, #1f5eff 100%); color: white; }

.notice.success { background: #eaf8f0; color: #17683a; }
.notice.error { background: #fff0f0; color: #9d2424; }

.customer-stats, .dashboard-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 16px; }
.customer-stats div, .dashboard-stats div { padding: 15px; border-radius: 11px; background: #f4f7fc; }
.customer-stats span, .dashboard-stats span { display: block; color: #667085; font-size: 12px; margin-bottom: 6px; }
.customer-stats strong, .dashboard-stats strong { font-size: 19px; }
.dashboard-filters { display: grid; grid-template-columns: repeat(2, minmax(160px, 220px)); gap: 10px; }
.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 20px; }
.dashboard-grid > div { padding: 16px; border: 1px solid #e5eaf2; border-radius: 12px; }
.dashboard-grid h3 { margin-top: 0; }
.report-list { display: grid; gap: 9px; }
.report-row { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 8px; border-bottom: 1px solid #edf0f5; }
.bar-chart { min-height: 190px; display: flex; align-items: end; gap: 7px; overflow-x: auto; padding-top: 12px; }
.bar-column { min-width: 42px; flex: 1; display: grid; align-content: end; gap: 5px; text-align: center; }
.bar-value { font-size: 10px; color: #667085; }
.bar-fill { min-height: 3px; border-radius: 6px 6px 2px 2px; background: #1f5eff; }
.bar-label { font-size: 10px; color: #667085; }

.muted {
  color: #6b7280;
  font-size: 14px;
  line-height: 1.5;
}

.notice {
  margin-top: 15px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #edf4ff;
  color: #1f4c9a;
}

.hidden { display: none !important; }

.history {
  margin-top: 16px;
  border-top: 1px solid #e8ebf1;
  padding-top: 14px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 8px;
  scrollbar-gutter: stable;
}

.history h3 {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding: 4px 0 12px;
  background: white;
}

.history-card,
.receipt-card,
.manager-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid #e8ebf1;
}

.receipt-card-actions,
.manager-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.receipt-filters {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) repeat(2, minmax(145px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin-top: 16px;
}

.receipt-results { margin: 12px 0 0; }
.receipt-card.cancelled { opacity: .72; background: #fff7f7; }
.status-badge { display: inline-block; margin-left: 7px; padding: 3px 7px; border-radius: 999px; font-size: 11px; text-transform: uppercase; }
.status-badge.cancelled { background: #ffe1e1; color: #9d2424; }

dialog {
  width: min(760px, calc(100% - 24px));
  border: 0;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 24px 70px rgba(0,0,0,.25);
}

dialog::backdrop {
  background: rgba(10, 18, 35, 0.55);
}

.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  font-size: 25px;
  background: #eef1f6;
  color: #25304a;
}

.manager-list { margin-top: 18px; }

.receipt {
  width: min(700px, 100%);
  margin: 0 auto;
  color: #111;
  background: white;
  padding: 30px;
  font-family: Arial, sans-serif;
}

.receipt-brand {
  text-align: center;
}

.cancelled-banner { margin-bottom: 16px; padding: 10px; border: 2px solid #b42318; color: #b42318; text-align: center; font-weight: 800; letter-spacing: .08em; }

.receipt-brand h1 {
  margin: 0 0 7px;
}

.receipt-brand p,
.receipt-meta p {
  margin: 4px 0;
}

.receipt-meta p {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  align-items: baseline;
  gap: 6px;
}

.receipt-table {
  margin: 20px 0;
}

.receipt-totals {
  width: min(360px, 100%);
  margin-left: auto;
  display: grid;
  gap: 8px;
}

.receipt-footer {
  text-align: center;
  margin-top: 18px;
}

.signature-settings-preview { display: flex; align-items: end; gap: 16px; }
.signature-settings-preview img { width: 180px; height: 80px; object-fit: contain; border: 1px solid #e1e6ef; border-radius: 8px; background: white; }
.receipt-signature { width: 190px; margin: 22px 0 12px auto; text-align: center; }
.receipt-signature img { display: block; width: 170px; height: 70px; margin: 0 auto 5px; object-fit: contain; }
.receipt-signature span { display: block; padding-top: 5px; border-top: 1px solid #222; font-size: 12px; }
.receipt-terms { margin-top: 18px; font-size: 11px; line-height: 1.45; text-align: center; color: #333; }
.receipt-terms p { margin: 5px 0; }

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    gap: 15px;
    flex-direction: column;
  }

  .form-grid,
  .totals-form,
  .add-item-row,
  .product-filters,
  .manager-toolbar,
  .receipt-filters {
    grid-template-columns: 1fr;
  }

  .import-summary { grid-template-columns: 1fr; }
  .customer-stats, .dashboard-stats, .dashboard-grid, .dashboard-filters { grid-template-columns: 1fr; }

  .panel { padding: 18px; }

  .history-card,
  .receipt-card,
  .manager-row {
    flex-direction: column;
  }
}

@media print {
  body * { visibility: hidden; }
  #receiptPreview, #receiptPreview * { visibility: visible; }
  #receiptPreview {
    position: absolute;
    inset: 0;
    width: 100%;
  }
  dialog {
    position: static;
    width: 100%;
    box-shadow: none;
    padding: 0;
  }
  .dialog-header { display: none; }
}


.phone-field {
  display: flex;
  align-items: stretch;
}

.phone-prefix {
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid #ccd3e0;
  border-right: 0;
  border-radius: 9px 0 0 9px;
  background: #f4f6fa;
  color: #3b455d;
  font-weight: 700;
}

.phone-field input {
  border-radius: 0 9px 9px 0;
}

.field-help {
  color: #6b7280;
  font-weight: 400;
  margin-top: -2px;
}
