:root {
  font-family: system-ui, "Segoe UI", sans-serif;
  color: #172033;
  background: #f4f6fb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: #f4f6fb;
}

main {
  width: 100%;
  min-height: 100vh;
}

/* แถบเครื่องมือด้านบน */
.toolbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: #fff;
  border-bottom: 1px solid #e0e5ef;
  box-shadow: 0 2px 8px #17203308;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.nav-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: #47536a;
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.nav-button:hover {
  background: #f0f4ff;
  color: #2458c6;
}

.nav-button.active {
  background: #2463eb;
  color: white;
}

.nav-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 23px;
  height: 23px;
  border-radius: 6px;
  background: #e9eef8;
  color: #40516e;
  font-size: 12px;
  font-weight: 750;
}

.nav-button.active .nav-number {
  background: #ffffff30;
  color: white;
}

/* ปุ่มตั้งค่าด้านขวา */
.settings-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid #e0e5ef;
  border-radius: 10px;
  background: white;
  color: #47536a;
  cursor: pointer;
}

.settings-button:hover {
  background: #f0f4ff;
  color: #2463eb;
  border-color: #c9d8ff;
}

.settings-button svg {
  width: 21px;
  height: 21px;
}

/* พื้นที่เนื้อหาหลัก ตั้งใจเว้นว่าง */
.content {
  min-height: calc(100vh - 66px);
  padding: 20px;
}

/* หน้าตั้งค่าการเชื่อมต่อ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: #101827a6;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  width: min(100%, 520px);
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px;
  margin: 0;
  border: 1px solid #e0e5ef;
  border-radius: 16px;
  background: white;
  box-shadow: 0 20px 60px #0003;
}

h2 {
  margin: 0 0 10px;
  font-size: 1.15rem;
}

p {
  line-height: 1.6;
}

.muted, .notice {
  color: #65718a;
  font-size: .9rem;
}

label {
  display: block;
  margin: 14px 0 6px;
  font-weight: 650;
}

input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #ccd4e2;
  border-radius: 9px;
  background: white;
  color: inherit;
  font: inherit;
}

input:focus {
  outline: 2px solid #b8ccff;
  border-color: #2463eb;
}

button {
  font: inherit;
}

.action-button {
  padding: 10px 15px;
  border: 1px solid #ccd4e2;
  border-radius: 9px;
  background: white;
  font-weight: 650;
  cursor: pointer;
}

.action-button.primary {
  border-color: #2463eb;
  background: #2463eb;
  color: white;
}

.action-button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 16px;
}

.modal-actions button {
  flex: 1;
}

.status {
  margin-top: 12px;
  padding: 12px;
  border-radius: 9px;
  background: #f1f4f9;
  overflow-wrap: anywhere;
  font-size: .9rem;
}

.ok { color: #087443; }
.bad { color: #b4232d; }
.wait { color: #8a5700; }

.error {
  margin-top: 8px;
  color: #b4232d;
  font-size: .9rem;
  white-space: pre-wrap;
}

body.modal-open {
  overflow: hidden;
}

@media (max-width: 560px) {
  .toolbar {
    padding: 9px 10px;
    gap: 6px;
  }

  .toolbar-left {
    gap: 3px;
  }

  .nav-button {
    gap: 5px;
    min-height: 38px;
    padding: 7px 8px;
    font-size: 12px;
  }

  .nav-number {
    width: 20px;
    height: 20px;
    font-size: 11px;
  }

  .settings-button {
    width: 38px;
    height: 38px;
  }

  .content {
    padding: 12px;
  }

  .modal-card {
    padding: 17px;
  }
}

@media (max-width: 370px) {
  .nav-button {
    padding: 7px 5px;
    font-size: 11px;
  }
}

/* ให้ Modal ที่มี hidden ไม่แสดงผล */
.modal-backdrop[hidden] {
  display: none !important;
}

/* Modal ใช้พื้นที่เต็มหน้าจอ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  background: rgba(15, 23, 42, 0.58);
}

.modal-card {
  box-sizing: border-box;
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 26px;
  border-radius: 14px;
  background: #fff;
  color: #1e293b;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.modal-card label {
  display: block;
  margin: 14px 0 6px;
  font-weight: 600;
}

.modal-card input {
  box-sizing: border-box;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 16px;
}

.modal-card input:focus {
  outline: 2px solid #93c5fd;
  border-color: #2563eb;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.action-button {
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.action-button.primary {
  background: #2563eb;
  color: #fff;
}

.action-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.muted,
.notice {
  color: #64748b;
  font-size: 14px;
}

.error {
  color: #b91c1c;
  font-size: 14px;
}

.status {
  margin-top: 12px;
  font-size: 14px;
}

@media (max-width: 700px) {
  .toolbar {
    flex-wrap: wrap;
  }

  .toolbar-left {
    flex-wrap: wrap;
    width: 100%;
  }

  .settings-button {
    margin-left: auto;
  }
}
