@font-face {
  font-family: "Noto Sans Thai";
  src: url("fonts/NotoSansThai-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Noto Sans Thai";
  src: url("fonts/NotoSansThai-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --ink: #1a2b4a;
  --accent: #c0392b;
  --field-idle-border: rgba(21, 101, 192, 0);
  --field-hover-border: rgba(21, 101, 192, 0.55);
  --field-focus-bg: rgba(255, 244, 176, 0.55);
  --field-filled-bg: rgba(255, 255, 255, 0);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  background: #eef0f3;
  color: #222;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: #1a2b4a;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.toolbar-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.save-status {
  font-size: 12px;
  color: #b9c4dd;
  margin-right: 6px;
}

.page-tab {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  padding: 6px 14px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
}

.page-tab.active {
  background: #fff;
  color: #1a2b4a;
  font-weight: 600;
}

.sheet-wrap {
  padding: 24px;
  display: flex;
  justify-content: center;
}

.sheet {
  position: relative;
  width: min(1600px, 100%);
  aspect-ratio: 1190.55 / 841.89;
  background: #fff;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
}

.sheet .bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  user-select: none;
}

.fields-layer {
  position: absolute;
  inset: 0;
}

.wires-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.wires-layer polyline {
  fill: none;
  stroke-width: 1;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.wires-layer polyline.role-I { stroke: #00adef; }
.wires-layer polyline.role-O { stroke: #f46e16; }

.field-outer {
  position: absolute;
}

.field-outer.unused .field-input {
  display: none;
}

.io-toggle {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.io-toggle button {
  pointer-events: auto;
  font-size: 5px;
  font-weight: 700;
  line-height: 1;
  width: 8px;
  height: 8px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #b7bdc9;
  background: #fff;
  color: #b7bdc9;
  cursor: pointer;
  box-shadow: 0 1px 1px rgba(0,0,0,0.2);
}

.io-toggle button:hover {
  border-color: #6b7280;
  color: #4b5563;
}

.io-toggle button.on.role-I { background: #00adef; border-color: #00adef; color: #fff; }
.io-toggle button.on.role-O { background: #f46e16; border-color: #f46e16; color: #fff; }

.field-input {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  resize: none;
  background: var(--field-filled-bg);
  font-family: "Noto Sans Thai", -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  color: #110f0d;
  line-height: 1.05;
  padding: 0 1px;
  box-shadow: 0 0 0 1px var(--field-idle-border) inset;
  border-radius: 2px;
  overflow: hidden;
  white-space: nowrap;
  z-index: 1;
}

.field-input:hover {
  box-shadow: 0 0 0 1px var(--field-hover-border) inset;
  z-index: 2;
}

.field-input.empty {
  outline: 1px dashed #b0b6c2;
  outline-offset: 1px;
  min-width: 10px;
}

.field-input:focus {
  background: var(--field-focus-bg);
  box-shadow: 0 0 0 1.5px var(--accent) inset;
  z-index: 3;
}

.field-input.header-field {
  color: #2e3192;
}

.field-input.rotated {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  text-align: left;
  width: 100%;
  height: 100%;
  white-space: nowrap;
  overflow: hidden;
}

.field-input.multiline {
  width: 100%;
  white-space: pre-line;
  overflow: hidden;
}
