* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  height: 100vh;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns:
    calc((100% - 16px) * var(--col-1, 0.33))
    8px
    calc((100% - 16px) * var(--col-2, 0.34))
    8px
    calc((100% - 16px) * var(--col-3, 0.33));
  grid-template-rows: 1fr;
  height: 100vh;
  gap: 0;
}

.resize-handle {
  width: 8px;
  background: #e5e7eb;
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s;
  touch-action: none;
}

.resize-handle:hover {
  background: #2563eb;
}

.resize-handle:active {
  background: #1d4ed8;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Map panel */
#panel-map {
  position: relative;
}

#map {
  flex: 1;
  min-height: 0;
}

.map-legend {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(255, 255, 255, 0.95);
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

#selected-parcel-info {
  color: #555;
}

/* Chat panel */
#panel-chat {
  background: #fafafa;
  min-height: 0;
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}

.chat-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header h2 {
  margin: 0 0 4px 0;
  font-size: 1.1rem;
}

#debug-toggle {
  padding: 3px 10px;
  font-size: 11px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #f3f4f6;
  color: #6b7280;
  cursor: pointer;
  font-family: "SF Mono", "Consolas", monospace;
  transition: all 0.15s;
}

#debug-toggle:hover {
  border-color: #9ca3af;
}

#debug-toggle.active {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #92400e;
}

#parcel-context {
  margin: 0;
  font-size: 12px;
  color: #666;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  max-width: 90%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  flex-shrink: 0;
}

.chat-message.user {
  align-self: flex-end;
  background: #2563eb;
  color: white;
}

.chat-message.assistant {
  align-self: flex-start;
  background: white;
  border: 1px solid #e5e7eb;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.chat-message-markdown p { margin: 0 0 0.5em 0; }
.chat-message-markdown p:last-child { margin-bottom: 0; }
.chat-message-markdown ul, .chat-message-markdown ol { margin: 0.5em 0; padding-left: 1.25em; }
.chat-message-markdown li { margin: 0.25em 0; }
.chat-message-markdown strong { font-weight: 600; }
.chat-message-markdown code { background: #f1f5f9; padding: 0.15em 0.35em; border-radius: 4px; font-size: 0.9em; }
.chat-message-markdown .ordinance-cite { color: #2563eb; text-decoration: underline; cursor: pointer; }
.chat-message-markdown .ordinance-cite:hover { color: #1d4ed8; }

.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  resize: none;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

#chat-input:focus {
  outline: none;
  border-color: #2563eb;
}

#chat-send {
  padding: 10px 20px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

#chat-send:hover {
  background: #1d4ed8;
}

#chat-send:disabled {
  background: #9ca3af;
  cursor: not-allowed;
}

/* Reference tabs */
#doc-tabs {
  display: flex;
  gap: 4px;
  padding: 6px 10px;
  overflow-x: auto;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
  background: #f9fafb;
  scrollbar-width: thin;
}

#doc-tabs::-webkit-scrollbar { height: 4px; }
#doc-tabs::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

.doc-tab {
  padding: 4px 10px;
  font-size: 12px;
  font-family: inherit;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: white;
  color: #374151;
  cursor: pointer;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.doc-tab:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.doc-tab.active {
  background: #eff6ff;
  border-color: #2563eb;
  color: #1d4ed8;
  font-weight: 500;
}

/* Ordinance panel */
#panel-ordinance {
  background: white;
}

.ordinance-header {
  padding: 12px 16px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.doc-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ordinance-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.doc-back-btn {
  padding: 3px 10px;
  font-size: 11px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #f3f4f6;
  color: #374151;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.doc-back-btn:hover {
  background: #e5e7eb;
  border-color: #9ca3af;
}

#ordinance-search {
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
}

#ordinance-frame {
  flex: 1;
  min-height: 0;
  border: none;
}

.ordinance-no-results {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #6b7280;
  font-size: 14px;
  z-index: 10;
  pointer-events: none;
}

#panel-ordinance {
  position: relative;
}

/* Thinking indicator */
.chat-thinking {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  font-size: 13px;
  color: #6b7280;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.thinking-dots {
  display: flex;
  gap: 4px;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  background: #9ca3af;
  border-radius: 50%;
  animation: thinking-bounce 1.4s infinite ease-in-out;
}

.thinking-dots span:nth-child(1) { animation-delay: 0s; }
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking-bounce {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.thinking-text {
  color: #374151;
}

.thinking-timer {
  color: #9ca3af;
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 11px;
}

/* Debug trace */
.debug-trace {
  align-self: stretch;
  flex-shrink: 0;
  font-size: 12px;
  font-family: "SF Mono", "Consolas", "Courier New", monospace;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fafafa;
}

.debug-trace-toggle {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: #f9fafb;
  color: #6b7280;
  font-size: 11px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.debug-trace-toggle:hover {
  background: #f3f4f6;
}

.debug-trace-toggle::before {
  content: "▶ ";
  font-size: 9px;
}

.debug-trace-toggle.open::before {
  content: "▼ ";
}

.debug-trace-details {
  border-top: 1px solid #e5e7eb;
  padding: 8px 12px;
}

.debug-trace-details.collapsed {
  display: none;
}

.debug-summary {
  padding: 6px 8px;
  margin-bottom: 8px;
  background: #eff6ff;
  border-radius: 4px;
  color: #1e40af;
  font-size: 11px;
}

.debug-warn {
  color: #dc2626;
  font-weight: 600;
}

.debug-iteration {
  margin-bottom: 8px;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
}

.debug-iter-header {
  padding: 4px 8px;
  background: #f3f4f6;
  font-weight: 600;
  font-size: 11px;
  color: #374151;
}

.debug-llm-call {
  padding: 4px 8px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  border-bottom: 1px solid #f3f4f6;
}

.debug-label {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.debug-llm-call .debug-label {
  background: #dbeafe;
  color: #1e40af;
}

.debug-tool-call .debug-label {
  background: #dcfce7;
  color: #166534;
}

.debug-model {
  color: #6b7280;
}

.debug-timing {
  color: #b45309;
  font-weight: 600;
}

.debug-tokens {
  color: #6b7280;
}

.debug-stop {
  color: #9ca3af;
  font-style: italic;
}

.debug-tool-call {
  padding: 4px 8px;
  border-bottom: 1px solid #f3f4f6;
}

.debug-tool-call:last-child {
  border-bottom: none;
}

.debug-tool-error {
  background: #fef2f2;
}

.debug-tool-name {
  color: #059669;
  font-weight: 600;
}

.debug-tool-io {
  margin-top: 4px;
  padding-left: 8px;
}

.debug-tool-input,
.debug-tool-output {
  margin: 2px 0;
  color: #4b5563;
  word-break: break-all;
}

.debug-tool-io code {
  font-size: 10px;
  background: #f1f5f9;
  padding: 1px 4px;
  border-radius: 2px;
}
