/* Ishikawa — estilos */
:root {
  --bg: #f4f6f8; --surface: #ffffff; --surface2: #f1f5f9; --line: #dde3ea; --ink: #1f2937; --muted: #64748b;
  --accent: #0e7490; --accent-ink: #ffffff; --accent-soft: #e0f2f7; --danger: #dc2626; --canvas: #ffffff; --dots: #e2e8f0;
  --shadow: 0 10px 30px rgba(15, 23, 42, .14);
  font: 14px/1.45 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
}
[data-theme=dark] {
  --bg: #0b1220; --surface: #131c2e; --surface2: #1b2740; --line: #2a3752; --ink: #e5e7eb; --muted: #94a3b8;
  --accent: #22b8d6; --accent-ink: #06202a; --accent-soft: #12333f; --danger: #f87171; --canvas: #0f172a; --dots: #1e293b;
  --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
h2, h3, p { margin: 0; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.err { color: var(--danger); }
.grow { flex: 1; }
[hidden] { display: none !important; }

#app { display: grid; grid-template-columns: 264px minmax(0, 1fr) 360px; height: 100%; }
body.no-panel #app { grid-template-columns: 264px minmax(0, 1fr); }
body.no-panel #panel { display: none; }

/* Botões e campos */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border: 1px solid var(--accent); border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn.ghost:hover { background: var(--surface2); filter: none; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost.danger { background: transparent; color: var(--danger); border-color: var(--line); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.sm .ic { width: 15px; height: 15px; }
.btn.block { width: 100%; }
.btn.rooton { color: var(--danger); border-color: var(--danger); font-weight: 600; }
.btn.rooton .ic { fill: currentColor; }
.icon { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; color: var(--muted); font-size: 17px; flex: none; }
.icon:hover { background: var(--surface2); color: var(--ink); }
.icon.sm { width: 26px; height: 26px; }
.icon.sm .ic { width: 15px; height: 15px; }
.link { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px 2px; }
.link:hover { color: var(--accent); }
.link .ic { width: 15px; height: 15px; }
input:not([type=checkbox]):not([type=radio]), select, textarea { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 12px 0 4px; text-transform: uppercase; letter-spacing: .03em; }
label.check { display: flex; gap: 8px; align-items: center; text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 400; color: var(--ink); cursor: pointer; }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row.between { justify-content: space-between; }
.mobile { display: none; }

/* Barra lateral */
#sidebar { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 12px 10px; gap: 10px; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; padding: 0 4px 2px; }
.brand svg { width: 30px; height: 30px; }
.brand .icon { margin-left: auto; }
.qwrap { position: relative; }
.qwrap .ic { position: absolute; left: 9px; top: 9px; color: var(--muted); width: 16px; height: 16px; }
.qwrap input { padding-left: 32px !important; }
.shead { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 4px 6px 0; }
.shead .link { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 13px; }
#dlist { flex: 1; overflow-y: auto; min-height: 0; margin: 0 -4px; padding: 0 4px; }
.ditem { position: relative; padding: 9px 36px 9px 10px; border-radius: 8px; cursor: pointer; }
.ditem:hover { background: var(--surface2); }
.ditem.on { background: var(--accent-soft); }
.ditem.on .dt { color: var(--accent); }
.dt { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ds { font-size: 12px; color: var(--muted); }
.ditem .icon { position: absolute; right: 6px; top: 11px; opacity: 0; }
.ditem:hover .icon, .ditem.on .icon { opacity: 1; }
.pad { padding: 10px; }
.sfoot { border-top: 1px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; align-items: flex-start; font-size: 13px; }

/* Barra superior */
#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
#title { flex: 1; min-width: 80px; font-size: 16px; font-weight: 700; border-color: transparent !important; background: transparent !important; padding: 6px 8px !important; }
#title:hover { background: var(--surface2) !important; }
.tools { display: flex; align-items: center; gap: 4px; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

/* Quadro */
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background-color: var(--canvas); background-image: radial-gradient(var(--dots) 1px, transparent 1px); background-size: 22px 22px; cursor: grab; outline: none; touch-action: none; user-select: none; }
#stage.panning { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#world svg { display: block; overflow: visible; }
#world [data-id] { cursor: pointer; }
#world [data-id]:hover .hit { fill-opacity: .08; }
#zoombar { position: absolute; right: 12px; bottom: 12px; display: flex; align-items: center; gap: 2px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); cursor: default; }
#zoomv { min-width: 44px; text-align: center; font-size: 12.5px; color: var(--muted); }
#empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 20px; cursor: default; }
#empty svg { width: 64px; height: 64px; }
#empty p { color: var(--muted); margin-bottom: 6px; }
.inplace { position: fixed; z-index: 30; height: 32px; font-weight: 600; box-shadow: var(--shadow) !important; border-color: var(--accent) !important; }

/* Painel */
#panel { background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 6px; align-items: center; }
.tabs > button:not(.icon) { display: inline-flex; align-items: center; gap: 6px; padding: 11px 10px 9px; border: 0; border-bottom: 2px solid transparent; background: none; cursor: pointer; color: var(--muted); font-weight: 600; }
.tabs > button.on { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .icon { margin-left: auto; }
#pbody { flex: 1; overflow-y: auto; min-height: 0; padding: 10px 12px 16px; }
.orow { display: flex; align-items: center; gap: 6px; border-radius: 7px; padding: 1px 2px 1px 6px; }
.orow.cause { margin-left: 16px; }
.orow.sub { margin-left: 34px; }
.orow.cat { margin-top: 6px; }
.orow.sel { background: var(--accent-soft); }
.orow input { border-color: transparent !important; background: transparent !important; box-shadow: none !important; padding: 5px 4px !important; min-width: 0; }
.orow.cat input, .orow.effect input { font-weight: 700; }
.orow.sub input { font-size: 13px; }
.orow .icon { opacity: 0; }
.orow:hover .icon, .orow:focus-within .icon { opacity: 1; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.orow.cause .dot { width: 7px; height: 7px; }
.orow.sub .dot { width: 5px; height: 5px; opacity: .7; }
.otag { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; background: var(--ink); color: var(--surface); border-radius: 5px; padding: 2px 6px; flex: none; }
.addrow { margin: 8px 0 0 4px; }
.hint { font-size: 11.5px; color: var(--muted); margin: 10px 4px 0; line-height: 1.6; }
.hint b { font-weight: 600; color: var(--ink); }
/* Estrutura rola por cima; os detalhes do item selecionado ficam sempre à vista embaixo */
#pbody.split { display: flex; flex-direction: column; overflow: hidden; padding: 0; }
#outline { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px 14px; }
#details { flex: none; max-height: 52%; overflow-y: auto; padding: 12px 12px 14px; border-top: 1px solid var(--line); background: var(--surface); }
#details h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
#details .row { margin-top: 12px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.stats div { background: var(--surface2); border-radius: 8px; padding: 8px 4px; text-align: center; font-size: 11px; color: var(--muted); }
.stats b { display: block; font-size: 18px; color: var(--ink); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; padding: 6px 4px; border: 0; background: none; cursor: pointer; font-size: 13px; border-right: 1px solid var(--line); }
.seg button:last-child { border: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.votes { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.votes b { min-width: 20px; text-align: center; color: var(--ink); font-size: 15px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--surface); cursor: pointer; box-shadow: 0 0 0 1px var(--line); }
.swatches button.on { box-shadow: 0 0 0 2px var(--ink); }
.acard { border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 10px; padding: 10px 12px 12px; margin: 10px 0; }
.acard.doing { border-left-color: #d97706; }
.acard.done { border-left-color: #059669; }
.acard select[data-f=status] { width: auto; padding: 3px 8px; font-size: 13px; }
.acard .row { flex-wrap: nowrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 10px; }

/* Sobreposições */
.modalwrap { position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 42, .45); display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); width: min(520px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.mhead { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 6px 20px; }
.mhead h2 { font-size: 18px; }
.mbody { padding: 0 20px 20px; overflow-y: auto; }
.mfoot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.tpls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tpl { margin: 0; text-transform: none; letter-spacing: 0; cursor: pointer; }
.tpl input { position: absolute; opacity: 0; }
.tpl div { border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; height: 100%; }
.tpl b { display: block; color: var(--ink); font-size: 14px; }
.tpl span { font-weight: 400; font-size: 12.5px; }
.tpl small { display: block; font-weight: 400; font-size: 11.5px; margin-top: 4px; opacity: .85; }
.tpl input:checked + div { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); background: var(--accent-soft); }
.tpl input:focus-visible + div { border-color: var(--accent); }
.pop { position: fixed; z-index: 60; min-width: 210px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; }
.pop button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; text-align: left; }
.pop button:hover { background: var(--surface2); }
.pop button.danger { color: var(--danger); }
.pop hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s; z-index: 70; max-width: calc(100vw - 32px); }
#toast.on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast .link { color: #67e8f9; font-weight: 600; margin-left: 8px; }
#scrim { display: none; }

@media (max-width: 1100px) {
  .tools .btn span { display: none; }
}
@media (max-width: 900px) {
  #app, body.no-panel #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .mobile { display: inline-grid; }
  #main { overflow: hidden; }
  #topbar { flex-wrap: wrap; padding: 6px 8px; }
  #title { flex-basis: 140px; }
  .tools { margin-left: auto; }
  #sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 40; transform: translateX(-102%); transition: transform .2s; }
  body.side-open #sidebar { transform: none; box-shadow: var(--shadow); }
  body.side-open #scrim { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 35; }
  #panel { height: 46vh; min-width: 0; border-left: 0; border-top: 1px solid var(--line); }
  #zoombar { bottom: auto; top: 12px; }
  .sep { display: none; }
  .tpls { grid-template-columns: 1fr; }
  /* celular: rótulos curtos nos botões, áreas seguras (entalhe) e campos sem zoom automático do iPhone */
  .tools { flex-wrap: wrap; justify-content: flex-end; }
  .tools .btn span { display: inline; }
  #topbar { padding-top: max(6px, env(safe-area-inset-top)); padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  #sidebar { padding-top: max(14px, env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  #panel { padding-bottom: env(safe-area-inset-bottom); }
  #details { max-height: 42%; }
  input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px; }
  .modalwrap { align-items: end; padding: 0; }
  .modal { width: 100%; border-radius: 16px 16px 0 0; max-height: 92vh; padding-bottom: env(safe-area-inset-bottom); }
  #toast { bottom: calc(24px + env(safe-area-inset-bottom)); }
}
@media (max-width: 520px) {
  .tools .icon[data-act=togglePanel] { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .stats b { font-size: 16px; }
}
/* Telas de toque: sem passar o mouse, os botões ficam sempre visíveis e maiores */
@media (pointer: coarse) {
  .orow .icon, .ditem .icon { opacity: 1; }
  .icon { width: 38px; height: 38px; }
  .icon.sm { width: 32px; height: 32px; }
  .btn.sm { padding: 8px 12px; }
  .pop button { padding: 12px 12px; }
  .hint.keys { display: none; }
}
