:root {
  --bg: #e8f2f8;
  --bg-soft: #d8eaf4;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-soft: rgba(255, 255, 255, 0.82);
  --border: rgba(0, 87, 137, 0.19);
  --text: #142235;
  --muted: #587083;
  --blue: #006cae;
  --blue-soft: #dff1fb;
  --red: #d30a24;
  --red-soft: #ffe5e8;
  --gold: #d9a64a;
  --gold-soft: #fff1ce;
  --green: #188553;
  --green-soft: #dff5e9;
  --danger: #b82036;
  --shadow: 0 14px 38px rgba(0, 55, 92, 0.13);
  --header-height: 72px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; }

body {
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(0, 108, 174, 0.16), transparent 28%),
    radial-gradient(circle at top right, rgba(211, 10, 36, 0.08), transparent 24%),
    linear-gradient(180deg, #f5f9fc 0%, var(--bg) 100%);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  font-size: 16px;
}

button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.button,
.tool-button,
.icon-button {
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.button:hover,
.tool-button:hover,
.icon-button:hover { transform: translateY(-1px); }

.button:focus-visible,
.tool-button:focus-visible,
.icon-button:focus-visible,
input:focus-visible,
textarea:focus-visible,
.project-button:focus-visible,
.board-button:focus-visible,
.canvas-item:focus-visible {
  outline: 3px solid rgba(0, 108, 174, 0.28);
  outline-offset: 2px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 14px;
  color: var(--text);
  text-decoration: none;
  background: var(--panel);
}

.button-primary { color: #fff; background: var(--blue); border-color: var(--blue); }
.button-secondary { color: var(--blue); background: var(--blue-soft); }
.button-ghost { background: transparent; }

.login-page { min-height: 100vh; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px 16px; }
.login-card {
  width: min(460px, 100%);
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-logo { display: block; width: 76px; height: 80px; object-fit: contain; margin-bottom: 18px; }
.eyebrow, .panel-kicker {
  display: block;
  margin: 0 0 5px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.login-card h1 { margin: 0; font-size: clamp(34px, 8vw, 48px); }
.login-intro { margin: 12px 0 24px; color: var(--muted); line-height: 1.6; }
.login-form { display: grid; gap: 16px; }
.login-form label, .inspector-form label { display: grid; gap: 7px; font-weight: 700; }
input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--text);
  background: #fff;
}
textarea { resize: vertical; min-height: 100px; line-height: 1.5; }
.notice { padding: 11px 13px; border-radius: 10px; }
.notice-error { color: #861828; background: var(--red-soft); border: 1px solid rgba(211, 10, 36, 0.22); }
.back-link { display: inline-block; margin-top: 22px; color: var(--blue); font-weight: 700; text-decoration: none; }

.workspace-page { height: 100vh; overflow: hidden; }
.app-shell { height: 100vh; display: grid; grid-template-rows: var(--header-height) minmax(0, 1fr); }
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 0 4px 18px rgba(0, 55, 92, 0.08);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { width: 42px; height: 46px; object-fit: contain; }
.brand strong { display: block; font-size: 20px; }
.brand span { display: block; color: var(--muted); font-size: 13px; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.header-actions form { margin: 0; }

.workspace-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 300px;
}
.sidebar, .inspector {
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  background: var(--panel-soft);
}
.sidebar { border-right: 1px solid var(--border); }
.inspector { border-left: 1px solid var(--border); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-heading h2 { margin: 0; font-size: 19px; overflow-wrap: anywhere; }
.icon-button {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
  font-size: 22px;
}
.project-list, .board-list { display: grid; gap: 7px; margin-top: 12px; }
.project-button, .board-button {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 11px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  background: transparent;
}
.project-button strong, .board-button strong { display: block; }
.project-button span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; line-height: 1.35; }
.project-button:hover, .board-button:hover { background: rgba(0, 108, 174, 0.07); }
.project-button.is-active, .board-button.is-active { border-color: var(--border); background: var(--blue-soft); color: var(--blue); }
.board-heading { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--border); }
.sidebar-action { width: 100%; margin-top: 18px; }

.canvas-column { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; background: #edf5fa; }
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.88);
}
.tool-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tool-button { min-height: 38px; padding: 8px 11px; color: var(--text); background: #fff; }
.tool-button.is-active { color: #fff; background: var(--blue); border-color: var(--blue); }
.tool-button:disabled { cursor: not-allowed; opacity: 0.45; transform: none; }
.tool-danger:not(:disabled) { color: var(--danger); border-color: rgba(184, 32, 54, 0.26); background: var(--red-soft); }
.zoom-value { min-width: 58px; color: var(--muted); text-align: center; font-size: 14px; font-weight: 800; }

.canvas-viewport {
  position: relative;
  min-height: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  background-color: #f8fbfd;
  background-image:
    linear-gradient(to right, rgba(0, 87, 137, 0.10) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(0, 87, 137, 0.10) 1px, transparent 1px);
  background-size: 24px 24px;
}
.canvas-viewport.is-panning { cursor: grabbing; }
.canvas-viewport.mode-note, .canvas-viewport.mode-code { cursor: crosshair; }
.canvas-viewport.mode-draw { cursor: crosshair; }
.canvas-viewport.mode-connect { cursor: alias; }
.canvas-world { position: absolute; inset: 0 auto auto 0; width: 6000px; height: 4000px; transform-origin: 0 0; }
.connection-layer { position: absolute; left: -3000px; top: -2000px; width: 12000px; height: 8000px; overflow: visible; pointer-events: none; }
.connection-path {
  fill: none;
  stroke: #698090;
  stroke-width: 2.2;
  marker-end: url(#arrow-head);
}
#arrow-head path { fill: #698090; }
.connection-label { fill: #4b6476; font-size: 13px; font-weight: 700; paint-order: stroke; stroke: #f8fbfd; stroke-width: 5px; stroke-linejoin: round; }
.drawing-path { fill: none; stroke: var(--blue); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.drawing-preview { stroke: var(--red); stroke-dasharray: 7 5; }
.item-layer { position: absolute; inset: 0; }

.canvas-item {
  position: absolute;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 130px;
  min-height: 75px;
  padding: 12px 13px;
  border: 1px solid rgba(0, 87, 137, 0.20);
  border-radius: 12px;
  color: var(--text);
  text-align: left;
  cursor: grab;
  overflow: hidden;
  box-shadow: 0 8px 22px rgba(0, 55, 92, 0.14);
  touch-action: none;
}
.canvas-item:hover { border-color: rgba(0, 108, 174, 0.42); }
.canvas-item.is-selected { outline: 3px solid rgba(0, 108, 174, 0.36); outline-offset: 2px; }
.canvas-item.is-connect-source { outline: 3px solid rgba(211, 10, 36, 0.42); outline-offset: 3px; }
.canvas-item.color-blue { background: #e4f3fb; }
.canvas-item.color-gold { background: var(--gold-soft); }
.canvas-item.color-red { background: var(--red-soft); }
.canvas-item.color-green { background: var(--green-soft); }
.canvas-item.item-code { font-family: Consolas, "Courier New", monospace; }
.item-title { display: block; margin-bottom: 7px; font-weight: 800; overflow-wrap: anywhere; }
.item-content { display: -webkit-box; overflow: hidden; color: #30485c; font-size: 14px; line-height: 1.42; white-space: pre-wrap; overflow-wrap: anywhere; -webkit-line-clamp: 5; -webkit-box-orient: vertical; }
.item-code .item-content { color: #24394a; }
.resize-handle {
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 18px;
  height: 18px;
  border: 0;
  background: linear-gradient(135deg, transparent 48%, rgba(0, 108, 174, 0.5) 49%, rgba(0, 108, 174, 0.5) 58%, transparent 59%, transparent 68%, rgba(0, 108, 174, 0.5) 69%, rgba(0, 108, 174, 0.5) 78%, transparent 79%);
  cursor: nwse-resize;
}
.drawing-select {
  position: absolute;
  min-width: 24px;
  min-height: 24px;
  border: 1px dashed transparent;
  border-radius: 8px;
  cursor: grab;
  background: transparent;
  touch-action: none;
}
.drawing-select:hover { border-color: rgba(0, 108, 174, 0.45); background: rgba(0, 108, 174, 0.04); }
.drawing-select.is-selected { border-color: var(--blue); background: rgba(0, 108, 174, 0.07); }

.canvas-empty {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  gap: 5px;
  max-width: 320px;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
  background: rgba(255,255,255,0.88);
  pointer-events: none;
}
.canvas-empty strong { color: var(--text); }
.canvas-hint { padding: 7px 12px; border-top: 1px solid var(--border); color: var(--muted); background: rgba(255,255,255,0.88); font-size: 13px; }

.inspector-empty h2 { margin: 0; font-size: 20px; }
.inspector-empty p { color: var(--muted); line-height: 1.55; }
.inspector-form { display: grid; gap: 17px; }
.inspector-heading { margin-bottom: 2px; }
.inspector-form fieldset { margin: 0; padding: 0; border: 0; }
.inspector-form legend { margin-bottom: 8px; font-weight: 700; }
.color-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.color-choices label { display: block; cursor: pointer; }
.color-choices input { position: absolute; opacity: 0; pointer-events: none; }
.swatch { display: block; padding: 9px; border: 2px solid transparent; border-radius: 9px; text-align: center; font-size: 13px; }
.swatch-blue { background: #e4f3fb; }
.swatch-gold { background: var(--gold-soft); }
.swatch-red { background: var(--red-soft); }
.swatch-green { background: var(--green-soft); }
.color-choices input:checked + .swatch { border-color: var(--blue); }
.connection-list { display: grid; gap: 8px; padding-top: 14px; border-top: 1px solid var(--border); }
.connection-list:empty { display: none; }
.connection-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
.connection-row button { border: 0; color: var(--danger); cursor: pointer; background: transparent; font-weight: 800; }

@media (min-width: 1600px) {
  .workspace-layout { grid-template-columns: 300px minmax(0, 1fr) 340px; }
  .sidebar, .inspector { padding: 22px; }
  .tool-button { min-height: 42px; padding-inline: 14px; }
}

@media (max-width: 1080px) {
  .workspace-layout { grid-template-columns: 220px minmax(0, 1fr) 260px; }
  .sidebar, .inspector { padding: 14px; }
  .toolbar { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 780px) {
  .workspace-page { height: auto; min-height: 100vh; overflow: auto; }
  .app-shell { height: auto; min-height: 100vh; display: block; }
  .app-header { position: sticky; top: 0; min-height: var(--header-height); }
  .header-actions .button-secondary { display: none; }
  .workspace-layout { display: grid; grid-template-columns: 1fr; }
  .sidebar, .inspector { overflow: visible; border: 0; border-bottom: 1px solid var(--border); }
  .project-list, .board-list { display: flex; overflow-x: auto; padding-bottom: 4px; }
  .project-button, .board-button { width: auto; min-width: 150px; }
  .board-heading { margin-top: 16px; padding-top: 14px; }
  .sidebar-action { width: auto; }
  .canvas-column { height: 68vh; min-height: 520px; order: 2; }
  .inspector { order: 3; border-top: 1px solid var(--border); }
  .toolbar { position: relative; flex-direction: row; align-items: center; overflow-x: auto; }
  .tool-group { flex-wrap: nowrap; }
  .tool-button { white-space: nowrap; }
}

@media (max-width: 520px) {
  body { font-size: 15px; }
  .app-header { padding-inline: 10px; }
  .brand img { width: 34px; height: 38px; }
  .brand strong { font-size: 17px; }
  .header-actions .button { min-height: 38px; padding: 7px 9px; font-size: 13px; }
  .login-card { padding: 24px 20px; }
  .canvas-column { min-height: 500px; }
  .color-choices { grid-template-columns: 1fr; }
}
