* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
body { background: #f0f3f6; overflow: hidden; }

/* ---------- 登入畫面 ---------- */
.auth-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0d2b45 0%, #15577a 60%, #1b80a8 100%);
}
.auth-card {
  background: #fff; border-radius: 14px; padding: 38px 42px; width: 360px;
  box-shadow: 0 18px 50px rgba(0,0,0,.35);
}
.auth-card h1 { font-size: 22px; color: #14344f; text-align: center; }
.auth-sub { text-align: center; color: #6b7d8c; font-size: 13px; margin: 6px 0 20px; }
.auth-tabs { display: flex; margin-bottom: 18px; border-radius: 8px; overflow: hidden; border: 1px solid #cfd9e2; }
.auth-tabs button {
  flex: 1; padding: 9px; border: 0; background: #f2f6f9; color: #567; cursor: pointer; font-size: 14px;
}
.auth-tabs button.active { background: #1b6fa8; color: #fff; font-weight: bold; }
#authForm input {
  width: 100%; padding: 11px 12px; margin-bottom: 12px; font-size: 14px;
  border: 1px solid #cfd9e2; border-radius: 8px; outline: none;
}
#authForm input:focus { border-color: #1b6fa8; }
#authForm button[type=submit] {
  width: 100%; padding: 11px; font-size: 15px; font-weight: bold; color: #fff;
  background: #1b6fa8; border: 0; border-radius: 8px; cursor: pointer;
}
#authForm button[type=submit]:hover { background: #15577a; }
.auth-error { color: #c0392b; font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* ---------- 版面 ---------- */
#app { display: flex; flex-direction: column; height: 100vh; }
#topbar {
  display: flex; align-items: center; gap: 14px; padding: 8px 14px;
  background: #14344f; color: #fff; flex-wrap: wrap;
}
.brand { font-weight: bold; font-size: 16px; }
.diagram-name { color: #9fc3dc; font-size: 13px; }
.toolbar { display: flex; align-items: center; gap: 6px; flex: 1; flex-wrap: wrap; }
.toolbar button {
  padding: 6px 10px; font-size: 13px; border: 1px solid #3a5e7c; border-radius: 6px;
  background: #1d4566; color: #e8f1f8; cursor: pointer; white-space: nowrap;
}
.toolbar button:hover { background: #2a5a82; }
.toolbar button.tool.active { background: #2e9be0; border-color: #2e9be0; font-weight: bold; }
.toolbar .sep { width: 1px; height: 22px; background: #3a5e7c; margin: 0 4px; }
#zoomLabel { font-size: 12px; min-width: 44px; text-align: center; color: #9fc3dc; }
.user-box { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user-box button {
  padding: 5px 10px; border: 1px solid #3a5e7c; background: transparent; color: #9fc3dc;
  border-radius: 6px; cursor: pointer;
}
.user-box button:hover { background: #1d4566; }

#main { display: flex; flex: 1; min-height: 0; }

/* ---------- 元件庫 ---------- */
#palette {
  width: 190px; background: #fff; border-right: 1px solid #d5dde4; overflow-y: auto; padding: 10px;
}
#palette h2, #props h2 { font-size: 13px; color: #567; margin-bottom: 10px; letter-spacing: 1px; }
#paletteItems { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pal-item {
  border: 1px solid #d5dde4; border-radius: 8px; padding: 6px 4px; text-align: center;
  cursor: grab; background: #fafcfe; user-select: none;
}
.pal-item:hover { border-color: #2e9be0; background: #f0f8fe; }
.pal-item svg { width: 56px; height: 44px; display: block; margin: 0 auto; }
.pal-item span { font-size: 11.5px; color: #345; }

/* ---------- 畫布 ---------- */
#canvasWrap { flex: 1; position: relative; overflow: hidden; background: #e8edf2; }
#canvas { width: 100%; height: 100%; display: block; cursor: default; }
#canvas.tool-pipe { cursor: crosshair; }
#canvas.panning { cursor: grabbing; }
#hint {
  position: absolute; left: 10px; bottom: 8px; font-size: 12px; color: #789;
  background: rgba(255,255,255,.85); padding: 4px 10px; border-radius: 6px; pointer-events: none;
}
.scada-obj { cursor: move; }
.scada-obj text { user-select: none; }
.obj-label { font-size: 13px; fill: #234; text-anchor: middle; }
.pipe { fill: none; cursor: pointer; }
.pipe.flowing { stroke-dasharray: 10 6; animation: flow 1s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -16; } }
.sel-box { fill: none; stroke: #2e9be0; stroke-width: 1.5; stroke-dasharray: 5 4; pointer-events: none; }
.handle { fill: #fff; stroke: #2e9be0; stroke-width: 1.5; cursor: pointer; }
.handle.rotate { cursor: alias; }
.handle.scale { cursor: nwse-resize; }
.pipe-pt { fill: #fff; stroke: #e67e22; stroke-width: 2; cursor: move; }

/* ---------- 屬性面板 ---------- */
#props {
  width: 230px; background: #fff; border-left: 1px solid #d5dde4; overflow-y: auto; padding: 12px;
}
#props .muted { color: #9ab; font-size: 13px; }
.prop-row { margin-bottom: 10px; }
.prop-row label { display: block; font-size: 12px; color: #567; margin-bottom: 3px; }
.prop-row input[type=text], .prop-row input[type=number], .prop-row select {
  width: 100%; padding: 6px 8px; font-size: 13px; border: 1px solid #cfd9e2; border-radius: 6px;
}
.prop-row input[type=color] { width: 100%; height: 30px; border: 1px solid #cfd9e2; border-radius: 6px; padding: 1px; }
.prop-row input[type=range] { width: 100%; }
.prop-type { font-size: 14px; font-weight: bold; color: #14344f; margin-bottom: 12px; }

/* ---------- 對話框 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 90; background: rgba(10,30,50,.5);
  display: flex; align-items: center; justify-content: center;
}
.modal-card {
  background: #fff; border-radius: 12px; padding: 24px; width: 460px; max-height: 70vh;
  display: flex; flex-direction: column;
}
.modal-card h2 { font-size: 17px; color: #14344f; margin-bottom: 14px; }
#diagramList { overflow-y: auto; flex: 1; }
.diag-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 6px; border-bottom: 1px solid #eef2f5;
}
.diag-item .nm { flex: 1; font-size: 14px; color: #234; cursor: pointer; }
.diag-item .nm:hover { color: #1b6fa8; text-decoration: underline; }
.diag-item .tm { font-size: 12px; color: #9ab; }
.diag-item button { padding: 4px 8px; font-size: 12px; border: 1px solid #dcc; background: #fff;
  color: #c0392b; border-radius: 6px; cursor: pointer; }
.modal-actions { text-align: right; margin-top: 14px; }
.modal-actions button {
  padding: 7px 16px; border: 1px solid #cfd9e2; background: #f2f6f9; border-radius: 8px; cursor: pointer;
}
