:root {
  color-scheme: light;
  --canvas: #f3f6f4;
  --surface: #ffffff;
  --surface-subtle: #f8faf9;
  --surface-selected: #e9f3ed;
  --ink: #18211d;
  --ink-soft: #59665f;
  --ink-faint: #66736c;
  --border: #d9e1dd;
  --border-strong: #c3cec8;
  --accent: #176b4a;
  --accent-strong: #10583d;
  --accent-soft: #e7f2ec;
  --danger: #b3261e;
  --danger-soft: #fff0ee;
  --shadow: 0 12px 30px rgba(28, 48, 38, 0.07);
  --font-sans: "Microsoft JhengHei UI", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  --font-mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--canvas);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
summary {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

a {
  color: inherit;
}

.app-frame {
  min-height: 100dvh;
}

.app-header {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  height: 68px;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-lockup,
.header-actions,
.connection-status,
.panel-heading,
.form-actions,
.actions {
  align-items: center;
  display: flex;
}

.brand-lockup {
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  background: transparent;
  border-radius: 8px;
  display: block;
  flex: 0 0 42px;
  height: 42px;
  object-fit: cover;
  object-position: center;
  width: 42px;
}

.brand-lockup h1,
.brand-lockup p,
.view-header h2,
.view-header p,
.panel-heading h3,
.panel-heading p {
  margin: 0;
}

.brand-lockup h1 {
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.25;
}

.brand-lockup p {
  color: var(--ink-soft);
  font-size: 0.75rem;
  line-height: 1.35;
  margin-top: 2px;
}

.header-actions {
  gap: 10px;
}

.connection-status {
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 700;
  gap: 7px;
  white-space: nowrap;
}

.status-dot {
  background: var(--ink-faint);
  border: 2px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--border-strong);
  height: 8px;
  width: 8px;
}

.connection-status.is-ready {
  color: var(--accent);
}

.connection-status.is-ready .status-dot {
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(23, 107, 74, 0.28);
}

.app-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: calc(100dvh - 68px);
}

.side-rail {
  background: var(--surface-subtle);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
}

.primary-nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink-soft);
  display: flex;
  font-weight: 750;
  justify-content: space-between;
  min-height: 46px;
  padding: 0 13px;
  text-align: left;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 120ms ease;
  width: 100%;
}

.nav-item:hover {
  background: var(--surface);
  border-color: var(--border);
  color: var(--ink);
}

.nav-item:active,
.button:active,
.text-button:active {
  transform: translateY(1px);
}

.nav-item.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.nav-count {
  align-items: center;
  background: rgba(24, 33, 29, 0.06);
  border-radius: 5px;
  display: inline-flex;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  justify-content: center;
  min-height: 24px;
  min-width: 28px;
  padding: 0 6px;
}

.nav-item.is-active .nav-count {
  background: rgba(255, 255, 255, 0.16);
}

.side-utilities {
  border-top: 1px solid var(--border);
  display: grid;
  gap: 0;
  margin-top: 20px;
  padding-top: 8px;
}

.utility-panel {
  border-bottom: 1px solid var(--border);
}

.utility-panel summary {
  align-items: center;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  font-size: 0.86rem;
  font-weight: 750;
  gap: 10px;
  justify-content: space-between;
  list-style: none;
  min-height: 48px;
  outline: none;
}

.utility-panel summary::-webkit-details-marker {
  display: none;
}

.utility-panel summary::after {
  color: var(--ink-faint);
  content: "+";
  font-size: 1rem;
  font-weight: 500;
}

.utility-panel[open] summary::after {
  content: "−";
}

.utility-state {
  color: var(--ink-faint);
  font-size: 0.72rem;
  font-weight: 700;
  margin-left: auto;
}

.utility-state.is-ready,
.field-state.is-ready {
  color: var(--accent);
}

.utility-body {
  display: grid;
  gap: 12px;
  padding: 4px 0 16px;
}

.webhook-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: grid;
  gap: 7px;
  padding: 10px;
}

.field-caption,
.field-state {
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 700;
}

.field-state {
  float: right;
}

.webhook-block code {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.main-content {
  min-width: 0;
  padding: 24px;
}

.command-bar {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(260px, 1fr) auto;
  margin: 0 auto 22px;
  max-width: 1540px;
}

.search-box {
  display: block;
}

.search-box input {
  background: var(--surface);
  border-color: var(--border-strong);
  font-size: 1rem;
  min-height: 50px;
  padding-left: 16px;
}

.button {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  display: inline-flex;
  font-size: 0.88rem;
  font-weight: 750;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 120ms ease;
  white-space: nowrap;
}

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

.button-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.button-quiet {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--ink);
}

.button-quiet:hover {
  background: var(--surface-selected);
  border-color: rgba(23, 107, 74, 0.34);
  color: var(--accent-strong);
}

.button.compact {
  min-height: 36px;
  padding: 0 12px;
}

.full-width {
  width: 100%;
}

.feature-view {
  margin: 0 auto;
  max-width: 1540px;
}

.view-header {
  align-items: end;
  display: flex;
  justify-content: space-between;
  margin-bottom: 14px;
  min-height: 46px;
}

.view-header h2 {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.25;
}

.view-header p {
  color: var(--ink-soft);
  font-size: 0.82rem;
  margin-top: 4px;
}

.workspace {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(300px, 340px) minmax(0, 1fr);
}

.editor-panel,
.list-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.editor-panel {
  align-self: start;
  padding: 20px;
  position: sticky;
  top: 92px;
}

#contactForm,
#landmarkForm {
  display: grid;
  gap: 14px;
}

.panel-heading {
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 4px;
}

.panel-heading h3 {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.35;
}

.panel-heading p {
  color: var(--ink-faint);
  font-size: 0.75rem;
  line-height: 1.45;
  margin-top: 3px;
}

.text-button {
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 750;
  min-height: 34px;
  padding: 0 6px;
}

.text-button:hover {
  background: var(--accent-soft);
}

label {
  color: var(--ink-soft);
  display: grid;
  font-size: 0.8rem;
  font-weight: 750;
  gap: 7px;
}

label small {
  color: var(--ink-faint);
  font-size: 0.72rem;
  font-weight: 600;
}

input,
textarea {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--ink);
  min-height: 44px;
  outline: none;
  padding: 10px 11px;
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
  width: 100%;
}

input::placeholder,
textarea::placeholder {
  color: #66736c;
  opacity: 1;
}

textarea {
  line-height: 1.55;
  min-height: 92px;
  resize: vertical;
}

input:hover,
textarea:hover {
  border-color: #9caaa3;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 74, 0.13);
}

.coordinate-grid,
.field-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.repeatable-field {
  display: grid;
  gap: 8px;
}

.repeatable-field-heading {
  align-items: center;
  color: var(--ink-soft);
  display: flex;
  font-size: 0.8rem;
  font-weight: 750;
  justify-content: space-between;
}

.text-button.compact-text {
  min-height: 28px;
  padding: 0 5px;
}

.phone-fields,
.phone-value-list {
  display: grid;
  gap: 7px;
}

.phone-entry {
  align-items: center;
  display: grid;
  gap: 7px;
  grid-template-columns: minmax(0, 1fr) 44px;
}

.phone-entry:first-child {
  grid-template-columns: minmax(0, 1fr);
}

.remove-phone-button {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: #9a3f37;
  display: inline-flex;
  font-size: 1.25rem;
  height: 44px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  transition: background-color 140ms ease, border-color 140ms ease;
  width: 44px;
}

.remove-phone-button:hover {
  background: #fff5f3;
  border-color: #c98b84;
}

.form-actions {
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}

.form-actions .button-primary {
  min-width: 132px;
}

.list-panel {
  min-width: 0;
  overflow: hidden;
}

.table-wrap {
  max-height: calc(100dvh - 212px);
  min-height: 520px;
  overflow: auto;
  position: relative;
}

table {
  border-collapse: collapse;
  min-width: 680px;
  width: 100%;
}

.landmarks-table {
  min-width: 1240px;
}

thead {
  background: #f0f4f2;
  position: sticky;
  top: 0;
  z-index: 2;
}

th,
td {
  border-bottom: 1px solid var(--border);
  font-size: 0.84rem;
  line-height: 1.5;
  padding: 13px 14px;
  text-align: left;
  vertical-align: top;
}

th {
  color: #46534c;
  font-size: 0.74rem;
  font-weight: 800;
  height: 46px;
  white-space: nowrap;
}

td {
  color: var(--ink);
  overflow-wrap: anywhere;
}

tbody tr {
  background: var(--surface);
  transition: background-color 140ms ease;
}

tbody tr:hover {
  background: #fbfcfb;
}

.vendor-name {
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.4;
}

.notes-line {
  color: var(--ink-faint);
  font-size: 0.75rem;
  margin-top: 4px;
  max-width: 260px;
}

.cell-link,
.map-link {
  color: var(--accent);
  font-weight: 750;
  text-decoration: none;
}

.cell-link:hover,
.map-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.coordinate-line {
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  margin-bottom: 5px;
  white-space: nowrap;
}

.actions {
  gap: 6px;
  white-space: nowrap;
}

.inline-action {
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 750;
  min-height: 32px;
  padding: 0 9px;
  transition: background-color 140ms ease, border-color 140ms ease, transform 120ms ease;
}

.inline-action:hover {
  background: var(--accent-soft);
  border-color: rgba(23, 107, 74, 0.38);
}

.inline-action.danger {
  color: var(--danger);
}

.inline-action.danger:hover {
  background: var(--danger-soft);
  border-color: rgba(179, 38, 30, 0.32);
}

.inline-action:active {
  transform: translateY(1px);
}

.empty {
  align-items: center;
  color: var(--ink-faint);
  display: flex;
  flex-direction: column;
  inset: 47px 0 0;
  justify-content: center;
  padding: 36px 20px;
  position: absolute;
  text-align: center;
}

.empty strong {
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.empty span {
  font-size: 0.78rem;
  margin-top: 5px;
}

.loading-row:hover {
  background: var(--surface);
}

.skeleton {
  animation: skeleton-pulse 1.4s ease-in-out infinite;
  background: #e6ece8;
  border-radius: 4px;
  display: block;
  height: 12px;
  max-width: 150px;
}

.loading-row td:nth-child(2n) .skeleton {
  max-width: 90px;
}

.reply-box {
  background: #1d2923;
  border-radius: 6px;
  color: #edf5f0;
  display: none;
  font-family: var(--font-sans);
  font-size: 0.76rem;
  line-height: 1.6;
  margin: 0;
  max-height: 240px;
  overflow: auto;
  padding: 11px;
  white-space: pre-wrap;
}

.reply-box:not(:empty) {
  display: block;
}

.toast {
  background: #1d2923;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 7px;
  bottom: 22px;
  box-shadow: 0 14px 34px rgba(20, 36, 28, 0.2);
  color: #ffffff;
  left: 50%;
  max-width: min(460px, calc(100% - 28px));
  padding: 11px 15px;
  position: fixed;
  text-align: center;
  transform: translateX(-50%);
  z-index: 50;
}

.toast.is-error {
  background: #70251f;
}

.sheet-scrim,
.sheet-handle,
.mobile-only {
  display: none;
}

.visually-hidden {
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.hidden,
[hidden] {
  display: none !important;
}

button:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(23, 107, 74, 0.22);
  outline-offset: 2px;
}

@keyframes skeleton-pulse {
  0%,
  100% {
    opacity: 0.52;
  }

  50% {
    opacity: 1;
  }
}

@media (max-width: 1380px) {
  .app-layout {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .main-content {
    padding: 20px;
  }

  .workspace {
    grid-template-columns: minmax(280px, 300px) minmax(0, 1fr);
  }
}

@media (max-width: 900px) {
  .app-header {
    height: 62px;
    padding: 0 16px;
  }

  .brand-mark {
    flex-basis: 36px;
    height: 36px;
    width: 36px;
  }

  .brand-lockup h1 {
    font-size: 1.05rem;
  }

  .brand-lockup p {
    display: none;
  }

  .app-layout {
    display: block;
    min-height: calc(100dvh - 62px);
  }

  .side-rail {
    border-bottom: 1px solid var(--border);
    border-right: 0;
    padding: 12px 16px;
  }

  .primary-nav {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 7px;
    gap: 0;
    grid-template-columns: 1fr 1fr;
    overflow: hidden;
  }

  .nav-item,
  .nav-item:hover,
  .nav-item.is-active {
    background: var(--surface);
    border: 0;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    color: var(--ink-soft);
    justify-content: center;
    min-height: 48px;
  }

  .nav-item + .nav-item {
    border-left: 1px solid var(--border);
  }

  .nav-item.is-active {
    border-bottom-color: var(--accent);
    color: var(--accent);
  }

  .nav-item.is-active .nav-count,
  .nav-count {
    background: var(--surface-selected);
    color: var(--accent);
    margin-left: 8px;
  }

  .side-utilities {
    margin-top: 10px;
    padding-top: 0;
  }

  .utility-panel summary {
    min-height: 44px;
  }

  .main-content {
    padding: 16px;
  }

  .command-bar {
    grid-template-columns: minmax(0, 1fr) auto;
    margin-bottom: 18px;
  }

  .search-box {
    grid-column: 1 / -1;
  }

  .workspace {
    display: block;
  }

  .view-header {
    margin-bottom: 12px;
  }

  .view-header h2 {
    font-size: 1.35rem;
  }

  .editor-panel {
    border-bottom: 0;
    border-left: 0;
    border-radius: 8px 8px 0 0;
    border-right: 0;
    bottom: 0;
    left: 0;
    max-height: 88dvh;
    opacity: 0;
    overflow: auto;
    padding: 14px 18px 20px;
    pointer-events: none;
    position: fixed;
    right: 0;
    top: auto;
    transform: translateY(104%);
    transition: opacity 180ms ease, transform 220ms cubic-bezier(0.16, 1, 0.3, 1), visibility 220ms ease;
    visibility: hidden;
    z-index: 30;
  }

  .editor-panel.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    visibility: visible;
  }

  .sheet-handle {
    background: #a9b4ae;
    border-radius: 2px;
    display: block;
    height: 4px;
    margin: 0 auto 14px;
    width: 40px;
  }

  .sheet-scrim {
    background: rgba(17, 27, 22, 0.42);
    border: 0;
    display: block;
    inset: 0;
    opacity: 0;
    pointer-events: none;
    position: fixed;
    transition: opacity 180ms ease;
    z-index: 25;
  }

  .sheet-scrim.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  body.sheet-open {
    overflow: hidden;
  }

  .mobile-only {
    display: inline-flex;
  }

  .form-actions {
    background: var(--surface);
    bottom: -20px;
    margin: 2px -4px 0;
    padding: 10px 4px 20px;
    position: sticky;
  }

  .form-actions .button {
    flex: 1;
  }

  .list-panel {
    box-shadow: none;
  }

  .table-wrap {
    max-height: none;
    min-height: 480px;
  }
}

@media (max-width: 700px) {
  .connection-status {
    font-size: 0.76rem;
  }

  .button.compact {
    min-height: 34px;
    padding: 0 10px;
  }

  .list-panel {
    background: transparent;
    border: 0;
    overflow: visible;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  tbody {
    display: block;
    min-width: 0;
    width: 100%;
  }

  .landmarks-table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tbody tr {
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(28, 48, 38, 0.05);
    display: grid;
    gap: 10px;
    padding: 15px;
  }

  th,
  td {
    border: 0;
    display: grid;
    font-size: 0.84rem;
    grid-template-columns: 78px minmax(0, 1fr);
    padding: 0;
  }

  td::before {
    color: var(--ink-faint);
    content: attr(data-label);
    font-size: 0.72rem;
    font-weight: 750;
    padding-top: 1px;
  }

  td.record-title {
    display: block;
  }

  td.record-title::before,
  td.record-actions::before {
    display: none;
  }

  .vendor-name {
    font-size: 1rem;
  }

  td.record-actions {
    border-top: 1px solid var(--border);
    display: block;
    margin-top: 2px;
    padding-top: 12px;
  }

  .actions {
    justify-content: flex-end;
  }

  .inline-action {
    min-height: 36px;
    min-width: 60px;
  }

  .coordinate-line {
    white-space: normal;
  }

  .empty {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    inset: 0;
    min-height: 260px;
    position: relative;
  }

  .loading-row {
    min-height: 150px;
  }

  .loading-row td {
    display: block;
  }

  .loading-row td::before {
    display: none;
  }

  .skeleton {
    height: 14px;
    margin: 4px 0;
  }
}

@media (max-width: 520px) {
  .app-header {
    gap: 10px;
  }

  .header-actions {
    gap: 7px;
  }

  .connection-status > span:last-child {
    max-width: 82px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .main-content,
  .side-rail {
    padding-left: 12px;
    padding-right: 12px;
  }

  .command-bar {
    grid-template-columns: 1fr;
  }

  .command-bar .button-primary {
    width: 100%;
  }

  .coordinate-grid,
  .field-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* Full-width database and standalone settings page */
body {
  overflow-x: hidden;
}

.main-content {
  min-height: calc(100dvh - 68px);
  width: 100%;
}

.page-section {
  margin: 0 auto;
  max-width: 1700px;
  width: 100%;
}

.database-topbar {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  margin-bottom: 18px;
  min-height: 54px;
}

.database-tabs {
  align-self: stretch;
  display: flex;
  gap: 26px;
}

.database-tabs .nav-item {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  justify-content: flex-start;
  min-height: 54px;
  min-width: 150px;
  padding: 0 4px;
  width: auto;
}

.database-tabs .nav-item:hover,
.database-tabs .nav-item.is-active {
  background: transparent;
  border-color: var(--accent);
  color: var(--accent);
}

.database-tabs .nav-count,
.database-tabs .nav-item.is-active .nav-count {
  background: var(--surface-selected);
  color: var(--accent);
  margin-left: 10px;
}

.command-bar,
.feature-view {
  max-width: none;
}

.command-bar {
  grid-template-columns: minmax(320px, 1fr) auto;
  margin-bottom: 20px;
}

.view-header {
  min-height: 42px;
}

.view-header h2 {
  font-size: 1.35rem;
}

.contacts-table {
  min-width: 1080px;
}

.contacts-table th:nth-child(1) {
  width: 16%;
}

.contacts-table th:nth-child(2) {
  width: 15%;
}

.contacts-table th:nth-child(3) {
  width: 20%;
}

.landmarks-table th:nth-child(1) {
  width: 14%;
}

.landmarks-table th:nth-child(2) {
  width: 17%;
}

.landmarks-table th:nth-child(3) {
  width: 9%;
}

.landmarks-table th:nth-child(4),
.landmarks-table th:nth-child(6) {
  width: 9%;
}

.landmarks-table th:nth-child(5),
.landmarks-table th:nth-child(7) {
  width: 12%;
}

.landmarks-table th:nth-child(8) {
  width: 11%;
}

.contacts-table th:nth-child(4) {
  width: 11%;
}

.contacts-table th:nth-child(5) {
  width: 16%;
}

.contacts-table th:nth-child(6) {
  width: 14%;
}

.notes-cell {
  color: var(--ink-soft);
  white-space: pre-wrap;
}

.table-wrap {
  max-height: calc(100dvh - 260px);
  min-height: 500px;
}

.settings-page {
  max-width: 1380px;
}

.settings-header {
  border-bottom: 1px solid var(--border);
  margin-bottom: 26px;
  padding: 8px 0 22px;
}

.settings-header h2,
.settings-header p,
.settings-panel-heading h3,
.settings-panel-heading p,
.section-kicker {
  margin: 0;
}

.settings-header h2 {
  font-size: 1.65rem;
  line-height: 1.25;
}

.settings-header > div > p:last-child {
  color: var(--ink-soft);
  font-size: 0.86rem;
  margin-top: 6px;
}

.section-kicker {
  color: #7a6040;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 800;
  margin-bottom: 7px;
}

.settings-grid {
  display: grid;
  gap: 28px;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, 0.85fr);
}

.settings-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 0;
  padding: 22px;
}

.settings-panel-heading {
  align-items: flex-start;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 20px;
}

.settings-panel-heading h3 {
  font-size: 1.05rem;
  line-height: 1.35;
}

.settings-panel-heading p {
  color: var(--ink-faint);
  font-size: 0.76rem;
  line-height: 1.5;
  margin-top: 4px;
}

.settings-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.settings-form > .button {
  justify-self: end;
  min-width: 150px;
}

.settings-page .webhook-block {
  align-items: center;
  background: var(--surface-subtle);
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 13px 14px;
}

.settings-page .webhook-block .field-caption {
  grid-column: 1 / -1;
}

.settings-page .webhook-block code {
  font-size: 0.76rem;
}

.auto-reply-panel {
  margin-top: 28px;
  padding: 0;
  overflow: hidden;
}

.auto-reply-heading {
  border-bottom: 1px solid var(--border);
  margin: 0;
  padding: 20px 22px;
}

.panel-tools {
  align-items: center;
  display: flex;
  gap: 12px;
}

.record-count {
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 750;
  white-space: nowrap;
}

.settings-table-wrap {
  max-height: 520px;
  min-height: 280px;
}

.auto-replies-table {
  min-width: 760px;
}

.auto-replies-table th:nth-child(1) {
  width: 20%;
}

.auto-replies-table th:nth-child(2) {
  width: 53%;
}

.auto-replies-table th:nth-child(3) {
  width: 17%;
}

.keyword-value {
  font-weight: 800;
}

.response-cell {
  line-height: 1.65;
  white-space: pre-wrap;
}

.timestamp-cell {
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 0.73rem;
  white-space: nowrap;
}

/* Editors are drawers so database tables keep the full page width. */
.editor-panel.drawer-panel {
  background: var(--surface);
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0;
  bottom: auto;
  box-shadow: -18px 0 44px rgba(20, 36, 28, 0.14);
  height: calc(100dvh - 68px);
  left: auto;
  max-height: calc(100dvh - 68px);
  opacity: 0;
  overflow: auto;
  padding: 26px 24px;
  pointer-events: none;
  position: fixed;
  right: 0;
  top: 68px;
  transform: translateX(104%);
  transition: opacity 180ms ease, transform 240ms cubic-bezier(0.16, 1, 0.3, 1), visibility 240ms ease;
  visibility: hidden;
  width: min(460px, 100%);
  z-index: 40;
}

.editor-panel.drawer-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
  visibility: visible;
}

#contactForm,
#landmarkForm,
#autoReplyForm {
  display: grid;
  gap: 15px;
}

.drawer-panel .panel-heading {
  border-bottom: 1px solid var(--border);
  margin: -2px 0 4px;
  padding-bottom: 16px;
}

.drawer-panel .form-actions {
  background: var(--surface);
  bottom: -26px;
  margin: 4px -4px -26px;
  padding: 14px 4px 26px;
  position: sticky;
}

.sheet-scrim {
  background: rgba(17, 27, 22, 0.42);
  border: 0;
  display: block;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  transition: opacity 180ms ease;
  z-index: 35;
}

.sheet-scrim.is-visible {
  opacity: 1;
  pointer-events: auto;
}

body.drawer-open {
  overflow: hidden;
}

@media (max-width: 900px) {
  .main-content {
    min-height: calc(100dvh - 62px);
    padding: 16px;
  }

  .database-topbar {
    margin-bottom: 14px;
  }

  .database-tabs {
    gap: 18px;
  }

  .database-tabs .nav-item {
    min-width: 132px;
  }

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

  .editor-panel.drawer-panel {
    height: calc(100dvh - 62px);
    max-height: calc(100dvh - 62px);
    top: 62px;
    transform: translateX(104%);
  }

  .editor-panel.drawer-panel.is-open {
    transform: translateX(0);
  }
}

@media (max-width: 700px) {
  .app-header {
    padding: 0 12px;
  }

  .header-actions {
    min-width: 0;
  }

  .connection-status {
    display: none;
  }

  .database-topbar {
    align-items: stretch;
    gap: 10px;
  }

  .database-tabs {
    flex: 1;
    gap: 0;
  }

  .database-tabs .nav-item {
    justify-content: center;
    min-width: 0;
    width: 50%;
  }

  .command-bar {
    grid-template-columns: 1fr;
  }

  .command-bar .button-primary {
    width: 100%;
  }

  .settings-header {
    margin-bottom: 18px;
  }

  .settings-header h2 {
    font-size: 1.4rem;
  }

  .settings-panel {
    border-left: 0;
    border-radius: 0;
    border-right: 0;
    margin-left: -16px;
    margin-right: -16px;
    padding: 18px 16px;
  }

  .auto-reply-panel {
    padding: 0;
  }

  .auto-reply-heading {
    align-items: stretch;
    flex-direction: column;
    padding: 18px 16px;
  }

  .panel-tools {
    justify-content: space-between;
  }

  .settings-page .webhook-block {
    grid-template-columns: 1fr;
  }

  .settings-form > .button {
    justify-self: stretch;
  }

  .settings-table-wrap {
    max-height: none;
    min-height: 260px;
  }

  .contacts-table,
  .landmarks-table,
  .auto-replies-table {
    min-width: 0;
  }

  .editor-panel.drawer-panel {
    border: 0;
    border-radius: 8px 8px 0 0;
    bottom: 0;
    height: auto;
    left: 0;
    max-height: 90dvh;
    padding: 18px 18px 22px;
    right: 0;
    top: auto;
    transform: translateY(104%);
    width: 100%;
  }

  .editor-panel.drawer-panel.is-open {
    transform: translateY(0);
  }

  .drawer-panel .form-actions {
    bottom: -22px;
    margin-bottom: -22px;
    padding-bottom: 22px;
  }

  .drawer-panel .form-actions .button {
    flex: 1;
  }
}

@media (max-width: 420px) {
  .brand-lockup h1 {
    font-size: 0.98rem;
  }

  .header-actions .button {
    font-size: 0.8rem;
    padding: 0 10px;
  }

  .database-topbar {
    gap: 7px;
  }

  .database-tabs {
    flex-basis: auto;
  }

  .database-topbar > .button {
    font-size: 0.78rem;
    margin-left: 0;
    padding: 0 8px;
  }
}
