* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #e9edf3;
  --card: #f8fbff;
  --border: #b7c4d3;
  --text: #1f2937;
  --title: #1b2c44;
  --hint: #64778d;
  --accent: #2f6fb3;
  --danger: #d64545;
  --ok: #1f8b4c;
  --warn: #f0a020;
}

html, body { height: 100%; }
body {
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

header.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
}
header.topbar h1 { font-size: 17px; color: var(--title); }
header.topbar .spacer { flex: 1; }
header.topbar .who { color: var(--hint); font-size: 13px; }

main.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 290px 1fr 360px;
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}
.panel h2 { font-size: 14px; color: var(--title); }
.panel .scroll { flex: 1; overflow-y: auto; min-height: 0; }

.filters { display: flex; flex-direction: column; gap: 8px; }
.filters .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.filters label { font-size: 12px; color: var(--hint); }

select, input[type="text"], input[type="password"], textarea {
  border: 1px solid #aebccc;
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
select:focus, input:focus, textarea:focus { outline: none; border-color: #6f9ad1; }
textarea { resize: vertical; }

button {
  border: 1px solid #9caec2;
  border-radius: 5px;
  background: linear-gradient(#ffffff, #dfe7f0);
  color: var(--text);
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
button:hover { border-color: #7f98b3; background: linear-gradient(#ffffff, #d6e0eb); }
button:disabled { color: #93a1b2; background: #eef2f6; cursor: not-allowed; }
button.primary { background: linear-gradient(#4a86c8, #2f6fb3); border-color: #2a629f; color: #fff; }
button.primary:hover { background: linear-gradient(#3f7cbf, #275e99); }
button.danger { background: linear-gradient(#e06a6a, #c94444); border-color: #b23a3a; color: #fff; }
button.small { padding: 3px 8px; font-size: 12px; }

/* image list */
.img-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: #fff;
  cursor: pointer;
}
.img-item:hover { border-color: #7f98b3; }
.img-item.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(47,111,179,.25); }
.img-item .name { font-weight: 700; font-size: 13px; color: var(--title); }
.img-item .meta { font-size: 12px; color: var(--hint); margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.badge {
  display: inline-block;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}
.badge.gray { background: #8a9bb0; }
.badge.green { background: var(--ok); }
.badge.orange { background: var(--warn); }
.badge.red { background: var(--danger); }
.badge.blue { background: var(--accent); }

/* canvas area */
.canvas-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}
.toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.toolbar .zoom-label { font-size: 12px; color: var(--hint); min-width: 46px; text-align: center; }
.canvas-holder {
  flex: 1;
  min-height: 0;
  background: #1f242b;
  border-radius: 10px;
  position: relative;
  overflow: hidden;
}
.canvas-holder canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.canvas-holder .empty-hint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #9aa7b5; font-size: 15px; pointer-events: none;
}
.legend { font-size: 12px; color: var(--hint); display: flex; gap: 12px; flex-wrap: wrap; }
.legend .key { display: inline-flex; align-items: center; gap: 4px; }
.legend .swatch { width: 14px; height: 10px; border: 2px solid; display: inline-block; }

/* annotation list & form */
.ann-item {
  display: flex; gap: 8px; align-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  padding: 6px 8px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 13px;
}
.ann-item:hover { border-color: #7f98b3; }
.ann-item.active { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(214,69,69,.2); }
.ann-item .idx { font-weight: 700; color: var(--hint); width: 18px; }
.ann-item .cls { font-weight: 700; flex: 1; }

.form-grid { display: grid; grid-template-columns: 72px 1fr; gap: 8px 10px; align-items: center; }
.form-grid .lbl { font-size: 12.5px; font-weight: 600; color: #31465f; text-align: right; }
.radio-row { display: flex; gap: 14px; }
.radio-row label { display: inline-flex; gap: 5px; align-items: center; font-size: 13px; cursor: pointer; }

.hintbox {
  background: #eef4fb;
  border: 1px solid #c9d9ec;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12.5px;
  color: #33516f;
  line-height: 1.55;
}
.hintbox b { color: var(--title); }

.meta-line { font-size: 12.5px; color: var(--hint); line-height: 1.5; word-break: break-all; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .grow { flex: 1; }

/* login overlay */
.overlay {
  position: fixed; inset: 0;
  background: rgba(27, 44, 68, .55);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.overlay.hidden { display: none; }
.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 28px 30px;
  width: 360px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.login-card h2 { color: var(--title); font-size: 19px; }
.login-card p { font-size: 13px; color: var(--hint); }
.login-card input { font-size: 15px; padding: 8px 10px; }
.login-card .err { color: var(--danger); font-size: 13px; min-height: 18px; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #1b2c44; color: #fff;
  padding: 10px 18px; border-radius: 8px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .25s;
  z-index: 60; max-width: 80vw;
}
#toast.show { opacity: .96; }
#toast.error { background: #a53232; }

/* admin table */
table.sub-table { width: 100%; border-collapse: collapse; font-size: 13px; background: #fff; }
table.sub-table th, table.sub-table td { border-bottom: 1px solid #d4dce6; padding: 6px 8px; text-align: left; }
table.sub-table th { background: #dfe7f1; font-size: 12px; color: var(--title); position: sticky; top: 0; }
table.sub-table tr.row { cursor: pointer; }
table.sub-table tr.row:hover { background: #f0f5fa; }
table.sub-table tr.row.active { background: #e2edf8; }

@media (max-width: 1100px) {
  main.layout { grid-template-columns: 240px 1fr; }
  .panel.right { grid-column: 1 / -1; max-height: 40vh; }
}
