:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #1f2933;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  --control-height: 36px;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

a {
  color: #2563eb;
  text-decoration: none;
  transition: opacity 0.15s;
}

a:hover {
  opacity: 0.75;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 12px 24px;
}

nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

nav a {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border-radius: var(--radius);
  color: #374151;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}

nav a:hover {
  background: #f3f4f6;
  color: #1f2933;
  opacity: 1;
}

.nav-status {
  align-self: center;
  color: #047857;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px;
}

h1, h2 {
  margin: 0 0 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.card, form, table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card {
  padding: 20px;
}

.card + .card {
  margin-top: 12px;
}

form {
  padding: 20px;
  margin-bottom: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

label {
  position: relative;
  display: grid;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
}

input, select, textarea, button {
  font: inherit;
}

input, select, textarea {
  min-width: 0;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 8px 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

textarea {
  min-height: 72px;
}

button,
.button-link,
.actions a,
.inline-form a,
.duplicate-confirm-form a,
.pagination a,
.ai-pdf-open {
  min-height: var(--control-height);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  border-radius: 6px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

button {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #ffffff;
  cursor: pointer;
}

button:hover {
  background: var(--primary-hover);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.is-hidden {
  display: none !important;
}

.login-page {
  background: #eef2f7;
}

.login-main {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
}

.login-panel h1 {
  text-align: center;
  margin-bottom: 18px;
}

.login-panel form {
  display: grid;
  gap: 14px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-label input {
  width: auto;
}

.compact-button {
  font-size: 12px;
  min-height: 32px;
  padding: 0 10px;
}

.section-action-button {
  margin-top: 8px;
}

.danger-button {
  border-color: var(--danger);
  background: var(--danger);
  color: #ffffff;
}

.danger-button:hover {
  background: var(--danger-hover);
}

.button-link {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.button-link:hover {
  background: var(--primary-hover);
  opacity: 1;
}

.secondary-link,
.secondary-button,
.actions a:not(.button-link),
.inline-form a,
.duplicate-confirm-form a,
.pagination a,
.cancel-button {
  border: 1px solid var(--border-strong);
  background: #ffffff;
  color: #374151;
}

.secondary-link:hover,
.secondary-button:hover,
.actions a:not(.button-link):hover,
.inline-form a:hover,
.duplicate-confirm-form a:hover,
.pagination a:hover,
.cancel-button:hover {
  background: #f3f4f6;
  color: #1f2933;
  opacity: 1;
  box-shadow: none;
}

.inline-form a,
.duplicate-confirm-form a {
  min-height: 34px;
}

.page-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin: -4px 0 16px;
}

.print-selection-form {
  display: none;
}

.print-toolbar {
  margin: 0 0 12px;
}

.compact-title {
  margin-bottom: 10px;
  font-size: 22px;
}

.compact-section-title {
  margin: 8px 0 10px;
  font-size: 17px;
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}

th, td {
  border-bottom: 1px solid #f3f4f6;
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--surface-muted);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
}

tr:hover td {
  background: #fafbfc;
}

.property-thumb {
  display: inline-flex;
  width: 76px;
  height: 56px;
  align-items: center;
  justify-content: center;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
  background: #f9fafb;
  color: #6b7280;
  font-size: 12px;
  font-weight: 600;
}

.property-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.property-thumb-empty {
  color: #9ca3af;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.form-actions {
  margin-top: 12px;
}

.actions form {
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  box-shadow: none;
}

.table-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: start;
  min-width: max-content;
  white-space: nowrap;
}

.table-actions.single-action {
  min-width: 64px;
}

.table-actions .action-group {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 66px;
}

.table-actions form {
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  box-shadow: none;
}

.table-actions .action-danger {
  width: auto;
  margin-left: 2px;
  padding-left: 10px;
  border-left: 1px solid #e5e7eb;
}

.table-actions .danger-button {
  width: 66px;
  height: 32px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid #fecaca;
  background: #ffffff;
  color: #b91c1c;
  box-sizing: border-box;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
}

.table-actions .danger-button:hover {
  background: #fef2f2;
  opacity: 1;
}

.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 66px;
  height: 32px;
  min-height: 32px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 0 10px;
  background: #ffffff;
  color: #374151;
  box-sizing: border-box;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
}

.action-link:hover {
  background: #f3f4f6;
  opacity: 1;
}

.view-link {
  border-color: #d1d5db;
  background: #ffffff;
  color: #374151;
}

.view-link:hover {
  background: #f3f4f6;
}

.edit-link {
  border-color: #d1d5db;
  background: #ffffff;
  color: #374151;
}

.edit-link:hover {
  background: #f3f4f6;
}

.muted {
  color: #6b7280;
}

.hint {
  display: none;
  position: absolute;
  left: 0;
  top: 100%;
  z-index: 5;
  max-width: 320px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #374151;
  padding: 8px 10px;
  font-weight: 400;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

label:focus-within .hint {
  display: block;
}

.filter-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin: 18px 0 12px;
}

.field-offset {
  margin-top: 12px;
}

.inline-control {
  width: fit-content;
  margin-top: 6px;
}

.status-line {
  display: inline-block;
  font-size: 12px;
  margin-top: 4px;
}

.list-section {
  scroll-margin-top: 16px;
}

.pagination {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 16px 0;
}

.pagination a {
  min-height: 34px;
}

.upload-zone {
  border: 2px dashed #d1d5db;
  border-radius: 10px;
  background: #ffffff;
  padding: 18px;
  margin-bottom: 16px;
  transition: border-color 0.15s, background 0.15s;
}

.upload-zone.dragging {
  border-color: #2563eb;
  background: #eff6ff;
}

.ai-entry-panel {
  margin: 0 0 18px;
  padding: 14px 0;
  border-top: 1px solid #d8dde3;
  border-bottom: 1px solid #d8dde3;
}

.ai-entry-panel textarea {
  width: 100%;
  margin: 6px 0 10px;
  resize: vertical;
}

@media (max-width: 760px) {
  header {
    padding: 10px 12px;
  }

  nav {
    gap: 4px;
  }

  nav a {
    padding: 6px 10px;
    font-size: 13px;
  }

  main {
    padding: 14px 10px;
  }

  h1 {
    font-size: 22px;
  }

  h2 {
    font-size: 18px;
  }

  form {
    padding: 14px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .filter-form {
    align-items: stretch;
  }

  .filter-form input,
  .filter-form select,
  .filter-form button {
    width: 100%;
  }

  .responsive-table {
    display: block;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }

  .responsive-table tr:first-child {
    display: none;
  }

  .responsive-table tr {
    margin-bottom: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    overflow: hidden;
  }

  .responsive-table td {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    min-height: 40px;
    padding: 9px 12px;
    border-bottom: 1px solid #f3f4f6;
  }

  .responsive-table td::before {
    content: attr(data-label);
    color: #6b7280;
    font-size: 12px;
    font-weight: 600;
  }

  .responsive-table td:last-child {
    border-bottom: 0;
  }

  .responsive-table .table-actions {
    display: flex;
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
  }

  .responsive-table .feedback-cell {
    display: block;
  }

  .responsive-table .feedback-cell::before {
    display: block;
    margin-bottom: 8px;
  }

  .property-thumb {
    width: 92px;
    height: 68px;
  }

  .detail-table {
    display: block;
  }

  .detail-table tbody,
  .detail-table tr,
  .detail-table th,
  .detail-table td {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }

  .detail-table tr {
    border-bottom: 1px solid #f3f4f6;
  }

  .detail-table th {
    padding-bottom: 2px;
    border-bottom: 0;
  }

  .detail-table td {
    padding-top: 2px;
  }

  .detail-image-link img {
    height: 140px;
  }
}

.contract-toolbar {
  padding: 12px 0 16px;
  border-bottom: 1px solid #d8dde3;
}

.contract-snippet {
  max-width: 720px;
  white-space: pre-wrap;
  line-height: 1.55;
}

.contract-answer {
  margin-top: 12px;
  white-space: pre-wrap;
  line-height: 1.6;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.image-item {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 8px;
}

.image-preview-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: zoom-in;
}

.image-preview-button:hover {
  background: transparent;
  box-shadow: none;
}

.image-item img,
.image-preview-button img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 6px;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.82);
  padding: 28px;
}

.lightbox img {
  max-width: min(96vw, 1200px);
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}

.lightbox-close {
  position: fixed;
  top: 18px;
  right: 18px;
  background: #111827;
}

.duplicate-card {
  margin-bottom: 16px;
}

.duplicate-card h2 {
  font-size: 16px;
}

.duplicate-confirm-form {
  margin-top: 12px;
}

.path-display {
  margin: 14px 0;
  color: #374151;
  word-break: break-all;
}

.detail-table {
  table-layout: fixed;
  margin-bottom: 12px;
  font-size: 13px;
}

.detail-table th {
  width: 96px;
  color: var(--text-muted);
  white-space: nowrap;
  padding: 6px 10px;
  line-height: 1.35;
}

.detail-table td {
  color: var(--text);
  overflow-wrap: anywhere;
  padding: 6px 10px;
  line-height: 1.35;
}

.detail-image-grid {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.detail-image-link {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
  background: var(--surface);
  color: inherit;
  cursor: zoom-in;
  box-shadow: var(--shadow);
}

.detail-image-link:hover {
  border-color: var(--border-strong);
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
  opacity: 1;
}

.detail-image-link img {
  width: 100%;
  height: 132px;
  object-fit: cover;
  display: block;
}

.modal-open {
  overflow: hidden;
}

.gallery-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.78);
}

.gallery-panel {
  width: min(1180px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 16px 50px rgba(15, 23, 42, 0.3);
}

.gallery-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
  padding: 10px 12px;
}

.gallery-close {
  min-height: 32px;
  border-color: var(--border-strong);
  background: #ffffff;
  color: #374151;
}

.gallery-close:hover {
  background: #f3f4f6;
  color: #1f2933;
  box-shadow: none;
}

.waterfall-gallery {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 10px;
}

.waterfall-image {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #f9fafb;
  display: flex;
  justify-content: center;
}

.waterfall-image img {
  max-width: 100%;
  max-height: calc(100vh - 112px);
  height: auto;
  width: auto;
  display: block;
  object-fit: contain;
}

.test-image-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.test-image-preview {
  display: grid;
  gap: 6px;
  color: #374151;
}

.test-image-preview img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f9fafb;
}

.test-image-preview span {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.test-preview-empty {
  margin-top: 12px;
}

.feedback-form {
  display: grid;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  margin-bottom: 8px;
  box-shadow: none;
}

.inline-form {
  padding: 0;
  border: 0;
  background: transparent;
  margin: 0;
  box-shadow: none;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.error {
  border-color: #fca5a5;
  color: #b91c1c;
}

.success {
  border-color: #6ee7b7;
  color: #065f46;
}

.coord-link {
  display: inline-block;
  font-size: 12px;
  font-weight: 500;
  color: #2563eb;
  padding: 2px 8px;
  border: 1px solid #bfdbfe;
  border-radius: 4px;
  margin-top: 2px;
  width: fit-content;
}

.coord-link:hover {
  background: #eff6ff;
  opacity: 1;
}

.nav-centered {
  justify-content: center;
}

.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.settings-section h2 {
  margin-top: 0;
}

.formula-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}

.formula-status.custom {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.formula-status.default {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.formula-status.error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.formula-display {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 12px 16px;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 15px;
  margin-bottom: 12px;
}

.fallback-params {
  opacity: 0.7;
  border-left: 3px solid #e5e7eb;
  padding-left: 16px;
}

.fallback-params .muted {
  margin-bottom: 12px;
}

.health-status {
  display: flex;
  align-items: center;
  gap: 10px;
}

.health-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10b981;
}

/* --- AI Chat --- */
.chat-layout {
  display: flex;
  height: calc(100vh - 104px);
  min-height: 560px;
  gap: 0;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}

.chat-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #f9fafb;
  border-right: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#new-chat-btn {
  flex: 1;
}

#conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.1s;
}

.conv-item:hover { background: #e5e7eb; }
.conv-item.active { background: #dbeafe; }

.conv-title {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #374151;
}

.conv-title-wrap {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}

.conv-token {
  font-size: 11px;
  color: #9ca3af;
  line-height: 1.2;
}

.conv-delete {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  min-height: 22px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #9ca3af;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.conv-delete:hover { background: #fca5a5; color: #b91c1c; }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  padding: 8px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #ffffff;
  color: #6b7280;
  font-size: 12px;
  box-sizing: border-box;
}

.agent-badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  padding: 3px 8px;
  font-weight: 600;
}

#token-status {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.chat-empty {
  color: #9ca3af;
  text-align: center;
  padding-top: 80px;
  font-size: 15px;
}

.chat-bubble {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  max-width: min(860px, 92%);
  min-width: 0;
}

.chat-bubble.user { align-self: flex-end; align-items: flex-end; }
.chat-bubble.assistant { align-self: flex-start; align-items: flex-start; }

.chat-bubble.has-table {
  align-self: stretch;
  max-width: 100%;
  width: 100%;
}

.bubble-content {
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.7;
  width: 100%;
  box-sizing: border-box;
  overflow-wrap: anywhere;
}

.bubble-content p { margin: 0 0 6px; }
.bubble-content p:last-child { margin-bottom: 0; }

.chat-bubble.user .bubble-content {
  background: #111827;
  color: #fff;
  border-bottom-right-radius: 3px;
}

.chat-bubble.assistant .bubble-content {
  background: #ffffff;
  color: #1f2933;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 3px;
}

.bubble-content code {
  background: rgba(0,0,0,0.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
}

.bubble-content .entity-link {
  display: inline-block;
  background: #dbeafe;
  color: #1d4ed8;
  padding: 1px 8px;
  border-radius: 4px;
  font-weight: 500;
  margin: 1px 2px;
  text-decoration: none;
}

.chat-input {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 0;
  box-shadow: none;
  margin: 0;
}

.chat-input textarea {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 120px;
}

.chat-input button {
  flex-shrink: 0;
  align-self: flex-end;
}

.sidebar-toolbar {
  display: flex;
  gap: 8px;
  padding: 12px 12px 0;
}

.sidebar-toolbar button {
  margin: 0;
  white-space: nowrap;
}

#skills-btn {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
  font-size: 13px;
}

.sidebar-batch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  border-bottom: 1px solid #e5e7eb;
}

.select-all-label {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: #6b7280;
  font-weight: 400;
}

.select-all-label input { accent-color: #2563eb; }

#stop-btn {
  background: #dc2626;
  flex-shrink: 0;
  align-self: flex-end;
}

.conv-check {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: #2563eb;
}

.table-divider {
  border: 0;
  border-top: 1px solid #e5e7eb;
  margin: 10px 0;
  width: 100%;
}

.table-section {
  width: 100%;
  display: block;
  box-sizing: border-box;
}

.result-table-wrap {
  margin: 0;
  overflow-x: auto;
  max-width: 100%;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
}

.result-table-collapsible {
  display: grid;
  gap: 8px;
}

.result-table-meta {
  color: #6b7280;
  font-size: 12px;
  line-height: 1.4;
}

.result-table-more {
  width: 100%;
}

.result-table-more > summary {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #f9fafb;
  color: #374151;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.result-table-more > summary::-webkit-details-marker {
  display: none;
}

.result-table-more[open] > summary {
  margin-bottom: 8px;
}

.result-table-more > summary:hover {
  background: #f3f4f6;
}

.result-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  box-shadow: none;
  border-radius: 0;
}

.result-table th {
  background: #f8fafc;
  color: #475569;
  font-weight: 600;
  padding: 8px 12px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
  text-align: left;
  position: sticky;
  top: 0;
}

.result-table td {
  padding: 6px 12px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13px;
  max-width: 260px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.result-table td:first-child {
  max-width: none;
  white-space: nowrap;
}

.ai-property-images {
  display: flex;
  gap: 6px;
  align-items: center;
}

.ai-property-images a {
  display: block;
  flex: 0 0 auto;
}

.ai-property-images img {
  width: 72px;
  height: 54px;
  object-fit: cover;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #f9fafb;
}

.ai-pdf-list {
  display: grid;
  gap: 8px;
  margin: 8px 0;
}

.ai-pdf-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
}

.ai-pdf-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}

.ai-pdf-main {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.ai-pdf-main strong,
.ai-pdf-main span,
.ai-pdf-main code {
  overflow-wrap: anywhere;
}

.ai-pdf-main span {
  color: #64748b;
  font-size: 12px;
}

.ai-pdf-main code {
  color: #64748b;
  font-size: 11px;
  background: #f8fafc;
  padding: 2px 4px;
  border-radius: 4px;
}

.ai-pdf-open {
  min-height: 30px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  white-space: nowrap;
  color: #2563eb;
  font-size: 13px;
}

.ai-pdf-open:hover {
  background: #dbeafe;
}

.ai-pdf-open.secondary {
  border-color: #e2e8f0;
  background: #f8fafc;
  color: #475569;
}

.ai-pdf-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.svg-chart {
  margin: 8px 0;
  padding: 12px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow-x: auto;
}

.svg-chart svg,
.svg-chart img {
  display: block;
  max-width: 100%;
  height: auto;
}

.result-table tbody tr:hover td { background: #f8fafc; }

.thinking-log,
.live-progress {
  width: 100%;
}

.thinking-log {
  margin-bottom: 10px;
}

.thinking-log > summary,
.live-progress > summary {
  cursor: pointer;
  color: #374151;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.4;
  list-style: none;
  user-select: none;
}

.thinking-log > summary::-webkit-details-marker,
.live-progress > summary::-webkit-details-marker,
.progress-step-card > summary::-webkit-details-marker {
  display: none;
}

.thinking-log > summary::before,
.live-progress > summary::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: #6b7280;
  vertical-align: 1px;
}

.progress-bubble {
  align-self: flex-start;
  max-width: min(820px, 94%);
}

.progress-bubble .bubble-content {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.progress-steps {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.current-plan-panel {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f9fafb;
}

.current-plan-panel.is-hidden {
  display: none;
}

.current-plan-title {
  color: #111827;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}

.current-plan-list,
.progress-checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  color: #4b5563;
  font-size: 12px;
  line-height: 1.45;
}

.progress-checklist {
  margin-top: 8px;
}

.current-plan-list li,
.progress-checklist li {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  min-width: 0;
}

.current-plan-list li::before,
.progress-checklist li::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-top: 6px;
  border-radius: 50%;
  background: #9ca3af;
}

.current-plan-list li.done::before,
.progress-checklist li.done::before {
  background: #16a34a;
}

.current-plan-list li.doing::before,
.progress-checklist li.doing::before {
  background: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.current-plan-list li.blocked::before,
.progress-checklist li.blocked::before {
  background: #dc2626;
}

.current-plan-list li.done .plan-item-text,
.progress-checklist li.done .plan-item-text {
  color: #166534;
}

.current-plan-list li.doing .plan-item-text,
.progress-checklist li.doing .plan-item-text {
  color: #111827;
  font-weight: 650;
}

.current-plan-list li.blocked .plan-item-text,
.progress-checklist li.blocked .plan-item-text {
  color: #b91c1c;
}

.plan-item-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

.plan-status {
  color: #6b7280;
  font-size: 11px;
  white-space: nowrap;
}

.progress-step-card {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

.progress-step-card > summary {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 8px 10px;
  cursor: pointer;
  color: #374151;
  font-size: 13px;
  line-height: 1.45;
  list-style: none;
}

.progress-step-card[open] > summary {
  border-bottom: 1px solid #f1f5f9;
}

.progress-step-body {
  padding: 8px 10px 10px 30px;
  color: #4b5563;
  font-size: 12px;
  line-height: 1.55;
}

.progress-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  margin-top: 7px;
}

.progress-plan .progress-dot,
.progress-query .progress-dot,
.progress-execute .progress-dot,
.progress-model .progress-dot {
  background: #2563eb;
}

.progress-search .progress-dot {
  background: #059669;
}

.progress-error .progress-dot {
  background: #dc2626;
}

.progress-exam .progress-dot,
.progress-done .progress-dot,
.progress-final .progress-dot {
  background: #16a34a;
}

.progress-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

.progress-detail-line {
  overflow-wrap: anywhere;
}

.model-output-pre {
  margin: 0;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #334155;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 8px;
  font-size: 12px;
  line-height: 1.5;
}

.agent-step-bubble {
  align-self: flex-start;
  max-width: 86%;
  margin: 0 0 10px;
  padding: 10px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff7ed;
  color: #334155;
  font-size: 13px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.agent-step-bubble.node-execute { background: #eff6ff; }
.agent-step-bubble.node-exam { background: #f0fdf4; }
.agent-step-bubble.node-done { background: #f8fafc; }

.agent-step-bubble .step-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.agent-step-bubble .step-marker {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #fff;
  color: #15803d;
  font-size: 12px;
  line-height: 1;
}

.agent-step-bubble .step-title {
  font-weight: 650;
  color: #1f2937;
  overflow-wrap: anywhere;
}

.agent-step-bubble .step-summary {
  margin-top: 6px;
  color: #64748b;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.agent-step-bubble .step-checklist {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.agent-step-bubble .step-checklist li {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  color: #64748b;
  line-height: 1.45;
}

.agent-step-bubble .checkmark {
  width: 16px;
  height: 16px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: rgba(255,255,255,0.8);
  color: #15803d;
  font-size: 12px;
}

.agent-step-bubble .step-checklist li.done {
  color: #166534;
}

.agent-step-bubble.step-done {
  opacity: 0.78;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 640px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.modal-box h2 { margin-top: 0; }

.modal-section {
  border-top: 1px solid #e5e7eb;
  padding-top: 16px;
  margin-top: 16px;
}

.modal-section h3 { margin: 0 0 8px; font-size: 15px; }

.skill-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #f3f4f6;
}

.skill-row:last-child { border-bottom: 0; }

.skill-status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 12px;
  margin-left: 8px;
  background: #f3f4f6;
  color: #6b7280;
}

.skill-status.enabled {
  background: #dcfce7;
  color: #166534;
}

.skill-status.disabled {
  background: #fee2e2;
  color: #991b1b;
}

.skill-prompt-preview {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 2px;
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.skill-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.skill-actions button {
  min-height: 30px;
  font-size: 12px;
  padding: 0 10px;
}

.skill-info { flex: 1; min-width: 0; }

.skill-edit-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.skill-edit-form input,
.skill-edit-form textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  font-size: 13px;
}

.skill-edit-actions {
  display: flex;
  gap: 6px;
}

.cancel-button {
  background: #f3f4f6 !important;
  color: #374151 !important;
  border: 1px solid var(--border-strong) !important;
}

.add-skill-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  padding: 12px;
  background: #f9fafb;
  border-radius: 8px;
}

.add-skill-form input,
.add-skill-form textarea { width: 100%; box-sizing: border-box; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

@media (max-width: 800px) {
  main {
    padding: 12px;
  }

  .chat-layout {
    height: auto;
    min-height: calc(100vh - 96px);
    flex-direction: column;
  }

  .chat-sidebar {
    width: 100%;
    max-height: 220px;
    border-right: 0;
    border-bottom: 1px solid #e5e7eb;
  }

  #chat-messages {
    min-height: 420px;
    padding: 14px;
  }

  .chat-bubble {
    max-width: 96%;
  }

  .chat-bubble.has-table {
    max-width: 100%;
  }

  .chat-input {
    padding: 10px 12px;
  }

  .modal-box {
    width: calc(100% - 24px);
    padding: 18px;
  }
}

@media (max-width: 760px) {
  .detail-image-link img {
    height: 140px;
  }

  .gallery-modal {
    padding: 8px;
  }

  .gallery-panel {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
  }

  .waterfall-gallery {
    gap: 8px;
    padding: 8px;
  }

  .waterfall-image img {
    max-height: calc(100vh - 88px);
  }
}
