:root {
  color-scheme: light;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: #f3f5f0;
  color: #1e241f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: minmax(210px, 230px) minmax(430px, 500px) minmax(0, 1fr);
  grid-template-rows: minmax(330px, 42vh) minmax(0, 1fr);
  gap: 12px;
  height: 100vh;
  padding: 12px;
  overflow: hidden;
}

.results {
  min-height: 0;
  grid-column: 3;
  grid-row: 2;
}

.result-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

#resultSummary {
  min-width: 0;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#exportBtn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.table-wrap {
  overflow: auto;
  height: calc(100% - 62px);
  max-height: none;
  border: 1px solid #e0e7dc;
  border-radius: 8px;
  max-width: 100%;
}

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

th,
td {
  border-bottom: 1px solid #e9efe5;
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  background: #f5faee;
  color: #314421;
  z-index: 1;
}

tr.active-result {
  background: #f6fbef;
}

td {
  overflow-wrap: anywhere;
}

.panel {
  background: #ffffff;
  border: 1px solid #dce4d7;
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.left {
  display: flex;
  flex-direction: column;
  grid-column: 1;
  grid-row: 1;
  overflow: auto;
}

.topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  min-width: 0;
}

h1,
h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
}

.file-picker {
  display: block;
  border: 1px dashed #91ad78;
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  text-align: center;
  color: #336018;
  background: #f7fbf0;
}

.file-picker input {
  display: none;
}

.job-box {
  border: 1px solid #dfe9d7;
  border-radius: 8px;
  padding: 9px;
  background: #fbfdf8;
}

.sample,
.hint,
.status {
  color: #607060;
  font-size: 12px;
  line-height: 1.5;
  margin: 8px 0;
}

.utility-hidden {
  display: none !important;
}

.current-card {
  border: 1px solid #e0e7dc;
  border-radius: 8px;
  padding: 14px;
  margin: 14px 0;
  background: #fbfdf8;
}

.settings-menu {
  border: 1px solid #dfe9d7;
  border-radius: 8px;
  margin: 8px 0;
  background: #f7fbf0;
}

.settings-menu summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 3px;
  padding: 8px 9px;
  cursor: pointer;
  font-weight: 700;
}

.settings-menu summary::marker {
  color: #77a817;
}

.settings-menu small {
  color: #607060;
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-menu small[data-state="online"]::before {
  content: "พร้อม: ";
}

.settings-menu small[data-state="offline"]::before {
  content: "ไม่พร้อม: ";
}

.settings-menu small[data-state="checking"]::before {
  content: "ตรวจสอบ: ";
}

.agent-card {
  border-top: 1px solid #dfe9d7;
  padding: 8px;
}

.agent-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.button-link {
  display: inline-grid;
  place-items: center;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid #77a817;
  border-radius: 8px;
  background: #77a817;
  color: #fff;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}

.label {
  color: #607060;
  font-size: 13px;
}

.install-no {
  font-size: 24px;
  font-weight: 700;
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.customer {
  color: #485447;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

button {
  border: 1px solid #cbd8c2;
  background: #fff;
  color: #1e241f;
  border-radius: 8px;
  min-height: 34px;
  padding: 6px 9px;
  cursor: pointer;
}

button.primary {
  background: #77a817;
  border-color: #77a817;
  color: #fff;
  font-weight: 700;
}

button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.list {
  display: grid;
  gap: 6px;
  min-height: 120px;
  max-height: none;
  flex: 1;
  overflow: auto;
  padding-right: 4px;
}

.row {
  display: grid;
  gap: 2px;
  border: 1px solid #e4eadf;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
}

.row.active {
  border-color: #77a817;
  background: #f5faee;
}

.row.done {
  border-color: #b7cab0;
}

.row strong,
.row span {
  overflow-wrap: anywhere;
}

.row span {
  color: #687266;
  font-size: 12px;
}

.workspace {
  display: contents;
}

.webcam-section,
.step-panel,
.results {
  min-height: 0;
  min-width: 0;
}

.step-panel {
  display: flex;
  flex-direction: column;
  grid-column: 2 / -1;
  grid-row: 1;
}

.webcam-section {
  display: flex;
  flex-direction: column;
  grid-column: 1 / 3;
  grid-row: 2;
  align-items: stretch;
  overflow: hidden;
}

.step-split {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
  flex: 1;
}

.step-editor,
.screen-column {
  min-width: 0;
  min-height: 0;
}

.step-editor {
  display: flex;
  flex-direction: column;
}

.screen-column {
  display: flex;
  flex-direction: column;
}

.screen-note {
  color: #607060;
  font-size: 12px;
  line-height: 1.4;
  margin-bottom: 8px;
}

.screen-wrap {
  position: relative;
  flex: 1;
  min-height: 220px;
  background: #151a18;
  border-radius: 8px;
  overflow: hidden;
}

.step-toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  margin-bottom: 8px;
}

.step-list {
  display: grid;
  gap: 6px;
  flex: 1;
  min-height: 120px;
  max-height: none;
  overflow: auto;
  margin: 8px 0 10px;
  padding-right: 4px;
}

.step-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto auto;
  gap: 6px;
  align-items: center;
  border: 1px solid #e0e7dc;
  border-radius: 8px;
  padding: 8px;
  background: #fbfdf8;
}

.step-item.active {
  border-color: #77a817;
  background: #f5faee;
}

.step-item .step-pick {
  min-height: 34px;
  padding: 0;
  font-weight: 700;
}

.step-name-edit {
  min-height: 34px;
  padding: 7px 9px;
}

.step-point {
  grid-column: 2 / 3;
  color: #9a3b22;
  font-size: 12px;
}

.step-point.ready {
  color: #336018;
  font-weight: 700;
}

.step-item button[data-step-action="test"],
.step-item button[data-step-action="delete"] {
  min-height: 34px;
  padding: 6px 8px;
}

.step-item button[data-step-action="test"] {
  grid-column: 3 / 4;
  grid-row: 1 / 3;
}

.step-item button[data-step-action="delete"] {
  grid-column: 4 / 5;
  grid-row: 1 / 3;
}

.step-markers {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.step-marker {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid #f2c94c;
  border-radius: 50%;
  background: rgba(119, 168, 23, .22);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .3);
}

.step-marker.active {
  border-color: #ffffff;
  background: #77a817;
}

.step-marker span {
  position: absolute;
  left: 18px;
  top: -8px;
  white-space: nowrap;
  background: rgba(0, 0, 0, .76);
  color: #fff;
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 11px;
}

#screenVideo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  cursor: crosshair;
}

.video-wrap {
  position: relative;
  background: #151a18;
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
  height: auto;
  max-height: calc(100% - 154px);
  min-height: 260px;
  display: grid;
  place-items: center;
  margin: 0;
  aspect-ratio: 16 / 9;
}

video {
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: contain;
}

.webcam-section .actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 10px 0 6px;
}

.webcam-section .actions button {
  padding: 7px 8px;
}

.preview {
  width: 100%;
  max-height: 44px;
  object-fit: contain;
  border: 1px solid #dce4d7;
  border-radius: 8px;
  background: #f8faf6;
}

.phone-hint,
.step-guide {
  color: #607060;
  font-size: 12px;
  line-height: 1.4;
  margin: -6px 0 8px;
}

.step-guide {
  margin-top: -4px;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  font-weight: 700;
}

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

.bill-box {
  border: 1px solid #e0e7dc;
  border-radius: 8px;
  padding: 12px;
  background: #fbfdf8;
}

.bill-box h3 {
  margin: 0 0 10px;
  font-size: 15px;
  letter-spacing: 0;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
}

.checkline input {
  width: 18px;
  height: 18px;
}

input,
select,
textarea {
  min-width: 0;
  width: 100%;
  border: 1px solid #cbd8c2;
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

textarea {
  resize: vertical;
}

@media (max-width: 1100px) {
  .app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .workspace {
    display: contents;
  }

  .left,
  .step-panel,
  .webcam-section,
  .results {
    grid-column: auto;
    grid-row: auto;
  }

  .list {
    max-height: 260px;
  }

  .step-split {
    grid-template-columns: 1fr;
  }

  .utility-hidden {
    display: none !important;
  }
}
