:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --ink: #1e2528;
  --muted: #687174;
  --line: #dfe4df;
  --green: #1f8a5b;
  --green-soft: #e6f4ec;
  --gold: #c17a20;
  --blue: #2f6f9f;
  --danger: #c94c4c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(244, 245, 242, 0.96);
}

.auth-gate.hidden {
  display: none;
}

.auth-card {
  width: min(460px, 100%);
  display: grid;
  gap: 12px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 18px 45px rgba(30, 37, 40, 0.16);
}

.auth-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.auth-card input {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  color: var(--ink);
}

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

button,
input,
.import-btn {
  font: inherit;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 340px 1fr;
}

.sidebar {
  padding: 20px;
  border-right: 1px solid var(--line);
  background: #fbfcfa;
  overflow-y: auto;
}

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

.mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--green);
  color: white;
  font-weight: 800;
  font-size: 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
}

.brand p,
.eyebrow,
.balance span,
.totals span {
  color: var(--muted);
  font-size: 13px;
}

.panel,
.order-area,
.preview-area {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel {
  padding: 14px;
  margin-bottom: 14px;
}

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

.section-head h2 {
  font-size: 16px;
}

.icon-btn,
.add-text-btn,
.ghost-btn,
.primary-btn,
.secondary-btn,
.import-btn {
  min-height: 36px;
  border-radius: 7px;
  border: 1px solid var(--line);
  cursor: pointer;
}

.icon-btn {
  width: 36px;
  background: var(--green);
  color: white;
  border-color: var(--green);
  font-size: 22px;
  line-height: 1;
}

.add-text-btn {
  background: var(--green);
  color: white;
  border-color: var(--green);
  padding: 0 12px;
  font-weight: 700;
}

.ghost-btn {
  background: white;
  color: var(--ink);
  padding: 0 12px;
}

.primary-btn {
  background: var(--green);
  color: white;
  border-color: var(--green);
  padding: 0 16px;
}

.secondary-btn {
  background: var(--green-soft);
  color: var(--green);
  border-color: #b6dec8;
  padding: 0 16px;
}

.import-btn {
  display: inline-flex;
  align-items: center;
  background: white;
  color: var(--ink);
  padding: 0 14px;
}

.import-btn input {
  display: none;
}

.customer-card,
.product-card,
.history-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  background: white;
}

.customer-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.customer-card.active {
  border-color: var(--green);
  background: var(--green-soft);
}

.customer-card strong,
.product-card strong {
  font-size: 15px;
}

.customer-card span,
.product-card span,
.history-card span {
  color: var(--muted);
  font-size: 13px;
}

.customer-main {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
  min-height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.customer-actions {
  display: flex;
  gap: 8px;
}

.mini-btn.danger {
  color: var(--danger);
  border-color: #efc7c7;
  background: #fffafa;
}

.product-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.product-card div {
  display: grid;
  gap: 3px;
}

.product-card small {
  color: var(--muted);
  font-size: 12px;
}

.product-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-btn {
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid #cbded4;
  border-radius: 6px;
  background: #f8fbf9;
  color: var(--green);
  cursor: pointer;
  font-size: 12px;
}

.workspace {
  padding: 20px;
  overflow: hidden;
}

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

.topbar-side {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.cloud-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.topbar h2 {
  font-size: 28px;
}

.balance {
  text-align: right;
}

.balance strong {
  display: block;
  color: var(--gold);
  font-size: 28px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(520px, 1.05fr) minmax(420px, 0.95fr);
  gap: 16px;
  height: calc(100vh - 110px);
}

.order-area,
.preview-area {
  padding: 16px;
  overflow-y: auto;
}

.quick-products {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.quick-products button {
  border: 1px solid #cbded4;
  background: #f8fbf9;
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 7px;
  cursor: pointer;
}

.empty-products {
  width: 100%;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--muted);
  background: #fbfcfa;
  font-size: 13px;
}

.ocr-panel {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.ocr-upload {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px dashed #a8c5b5;
  border-radius: 8px;
  background: white;
  color: var(--green);
  cursor: pointer;
  font-weight: 650;
}

.ocr-upload input {
  display: none;
}

#ocrTextInput {
  width: 100%;
  min-height: 92px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  resize: vertical;
  color: var(--ink);
  font: inherit;
  line-height: 1.5;
}

.ocr-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.order-table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

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

.order-table th,
.order-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
}

.order-table th {
  background: #f6f7f5;
  color: var(--muted);
  font-size: 13px;
}

.order-table input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
}

.remove-btn {
  color: var(--danger);
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 18px;
}

.note-row {
  margin: 14px 0;
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 12px;
}

.settle-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 14px;
}

.mode-btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  cursor: pointer;
}

.mode-btn.active {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
  font-weight: 800;
}

.note-row label,
.dialog-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.note-row input,
.dialog-form input,
.dialog-form select,
#historySearch {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: white;
  color: var(--ink);
}

.note-row input:disabled {
  background: #eef3ef;
  color: var(--muted);
}

.totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.totals div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.totals strong {
  display: block;
  margin-top: 4px;
  font-size: 26px;
}

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

.data-dock {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(30, 37, 40, 0.12);
}

.message-preview {
  white-space: pre-wrap;
  min-height: 260px;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid #ccd9d1;
  background: #fbfdf9;
  color: #18241c;
  font-size: 17px;
  line-height: 1.75;
}

.history-head {
  margin-top: 18px;
}

#historySearch {
  min-width: 180px;
}

.history-card {
  display: grid;
  gap: 6px;
}

.history-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.history-card strong {
  color: var(--blue);
}

.history-actions {
  display: flex;
  gap: 8px;
  margin-top: 2px;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

.dialog-form {
  width: min(360px, 90vw);
  padding: 18px;
  display: grid;
  gap: 12px;
}

.dialog-form menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0;
  margin: 4px 0 0;
}

.status {
  min-height: 20px;
  color: var(--green);
  font-size: 13px;
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .content-grid {
    grid-template-columns: 1fr;
    height: auto;
  }

  .note-row,
  .totals {
    grid-template-columns: 1fr;
  }

  .actions {
    position: sticky;
    bottom: 0;
    padding: 10px 0;
    background: var(--panel);
  }

  .actions button {
    flex: 1 1 140px;
  }

  .data-dock {
    position: static;
    margin: 12px;
    justify-content: stretch;
  }

  .data-dock button,
  .data-dock label {
    flex: 1;
    justify-content: center;
  }
}
