:root {
  --bg: #f4f8ef;
  --panel: #ffffff;
  --line: #d5dfca;
  --ink: #182015;
  --muted: #596453;
  --brand: #77bf43;
  --brand-dark: #5f9c32;
  --brand-ink: #203114;
  --warning: #8a2d19;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #eef5e7 0%, var(--bg) 52%, #f7faf3 100%);
  background-attachment: fixed;
}

.site-header {
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 10px 24px rgba(28, 44, 18, 0.06);
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  transition: opacity 0.2s;
}

.brand-link:hover {
  opacity: 0.8;
}

.brand-logo {
  width: 122px;
  height: auto;
  object-fit: contain;
  display: block;
}

.brand-text-link {
  text-decoration: none;
  color: inherit;
  transition: opacity 0.2s;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.brand-text-link:hover {
  opacity: 0.7;
}

.brand-title {
  margin: 0;
  font-size: 1.25rem;
  color: var(--brand-ink);
}

.brand-subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.user-menu-wrap {
  position: relative;
}

.user-menu-trigger {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  transition: background-color 0.2s;
}

.user-menu-trigger:hover {
  background-color: rgba(119, 191, 67, 0.16);
}

.user-name {
  color: var(--ink);
  font-size: 0.95rem;
}

.user-role {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 400;
}

.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(24, 32, 21, 0.14);
  min-width: 180px;
  z-index: 100;
  display: none;
  flex-direction: column;
}

.user-menu.active {
  display: flex;
}

.user-menu-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: none;
  text-align: left;
  text-decoration: none;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
  transition: background-color 0.15s;
}

.user-menu-item:hover {
  background-color: #f0f7e8;
}

.user-menu-form {
  display: contents;
}

.user-menu-signout {
  color: var(--warning);
  border-top: 1px solid var(--line);
  margin-top: 4px;
  padding-top: 10px;
}

.container {
  max-width: 1400px;
  margin: 20px auto;
  padding: 0 16px 24px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 14px 34px rgba(24, 32, 21, 0.08);
}

.narrow {
  max-width: 420px;
  margin: 30px auto;
}

.muted {
  color: var(--muted);
}

.alert {
  border: 1px solid #e4b2a6;
  background: #fff1ee;
  color: var(--warning);
  border-radius: 8px;
  padding: 10px 12px;
}

.notice {
  border: 1px solid #b9d79c;
  background: #f0f8e7;
  color: #35551d;
  border-radius: 8px;
  padding: 10px 12px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 600;
}

input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
}

.btn {
  display: inline-block;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--brand);
  color: var(--brand-ink);
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}

.btn:hover {
  background: var(--brand-dark);
}

.btn-secondary {
  background: #f3f8ee;
  color: var(--ink);
  border: 1px solid var(--line);
}

.card-grid {
  margin-top: 14px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: linear-gradient(180deg, #fbfdf8 0%, #f7fbf2 100%);
}

.template-card-grid {
  margin-top: 18px;
}

.template-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: space-between;
}

.template-card h3 {
  margin: 0;
}

.row-gap {
  margin-top: 14px;
}

.narrow-wide {
  max-width: 620px;
  margin: 30px auto;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.filter-row {
  display: grid;
  grid-template-columns: 1.2fr 220px auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.filter-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  background: #fff;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 10px 8px;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}

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

.status-chip {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.8rem;
  font-weight: 700;
}

.status-active {
  color: #35551d;
  background: #e9f6db;
}

.status-inactive {
  color: #6a2f1f;
  background: #fcefe8;
}

.btn-danger {
  background: #8a2d19;
}

.btn-danger:hover {
  background: #702414;
}

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

.field-label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.color-input-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.color-input-row input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 2px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
}

.color-text {
  width: 80px;
  font-family: monospace;
}

.bg-mode-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 400;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  background: var(--panel);
  transition: border-color 0.15s, background 0.15s;
}

.bg-mode-option:hover {
  border-color: var(--brand);
}

.bg-mode-option input[type="radio"] {
  accent-color: var(--brand);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.map-preview {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: repeating-conic-gradient(#e0e0e0 0% 25%, #ffffff 0% 50%) 0 0 / 16px 16px;
}

.map-preview svg {
  display: block;
  width: 100%;
  height: auto;
}

.county-result-list {
  columns: 3;
  column-gap: 16px;
  margin: 0;
  padding-left: 18px;
  font-size: 0.9rem;
}

.county-result-list li {
  break-inside: avoid;
  margin-bottom: 4px;
}

.output-box {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, #fbfdf8 0%, #f7fbf2 100%);
}

.query-editor-grid {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  margin-top: 12px;
}

.query-editor-grid label span {
  font-size: 0.92rem;
}

.render-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

.copy-dropdown {
  position: relative;
}

.copy-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(20, 40, 28, 0.1);
  min-width: 190px;
  z-index: 100;
}

.copy-menu li button {
  display: block;
  width: 100%;
  padding: 9px 14px;
  border: none;
  background: none;
  text-align: left;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  border-radius: 4px;
}

.copy-menu li button:hover {
  background: #f0f7e8;
}

.render-frame-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

#render-frame {
  display: block;
  width: 100%;
  min-height: 600px;
  border: none;
}

@media (max-width: 720px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .brand-logo {
    width: 104px;
  }

  .user-menu-wrap {
    width: 100%;
    display: flex;
    justify-content: flex-end;
  }

  .user-menu {
    right: auto;
  }

  .filter-row {
    grid-template-columns: 1fr;
  }
}