:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --ink: #222522;
  --muted: #69706b;
  --line: #ded9cf;
  --accent: #1f6f5b;
  --accent-2: #c9824a;
  --danger: #9b3d32;
  --warn: #9a6a1d;
  --ok: #246b46;
  --shadow: 0 18px 44px rgba(33, 35, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 13px;
  background: #fff;
  color: var(--ink);
  font-weight: 750;
  cursor: pointer;
}

.button-link {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 13px;
  background: #fff;
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
}

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

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.secondary {
  background: #fbfaf7;
}

.sidebar {
  min-height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #efebe2;
}

.app-mark {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.app-mark > span {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-weight: 900;
}

.app-mark div {
  display: grid;
  gap: 2px;
}

.app-mark small,
.panel p,
.stats small,
#statusText {
  color: var(--muted);
}

.panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.68);
}

.panel + .panel {
  margin-top: 14px;
}

.panel label {
  display: grid;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 800;
}

.panel input,
.panel select {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: white;
  color: var(--ink);
}

.check-row {
  grid-template-columns: 18px 1fr;
  align-items: start;
  font-weight: 650;
  line-height: 1.35;
}

.check-row input {
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

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

.toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

h1 {
  margin: 0 0 6px;
  font-size: 1.85rem;
  letter-spacing: 0;
}

#statusText {
  margin: 0;
}

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

.auth-user {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stats article {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stats span {
  display: block;
  font-size: 1.8rem;
  font-weight: 900;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.tabs button.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.saved-view {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.saved-view[hidden] {
  display: none;
}

.saved-map {
  position: sticky;
  top: 18px;
}

.map-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.map-card svg {
  width: 100%;
  max-height: 420px;
}

.map-card span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.saved-content {
  min-width: 0;
}

.saved-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.74);
}

.saved-controls label {
  display: grid;
  gap: 5px;
  min-width: 220px;
  font-size: 0.78rem;
  font-weight: 850;
}

.saved-controls select {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: white;
}

.saved-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.saved-card {
  min-height: 330px;
  perspective: 1100px;
}

.saved-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 330px;
  transition: transform 360ms ease;
  transform-style: preserve-3d;
}

.saved-card.flipped .saved-card-inner {
  transform: rotateY(180deg);
}

.saved-card-front,
.saved-card-back {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backface-visibility: hidden;
}

.saved-card-back {
  display: grid;
  align-content: center;
  gap: 10px;
  padding: 18px;
  transform: rotateY(180deg);
}

.saved-card-back span {
  color: var(--muted);
  line-height: 1.4;
}

.saved-preview {
  height: 210px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: #eee9df;
}

.saved-preview iframe {
  width: 1200px;
  height: 900px;
  border: 0;
  pointer-events: none;
  transform: scale(0.24);
  transform-origin: 0 0;
}

.saved-card-meta {
  display: grid;
  gap: 6px;
  padding: 12px;
}

.saved-card-meta span {
  color: var(--muted);
  font-size: 0.84rem;
}

.saved-card button {
  justify-self: start;
}

.saved-empty {
  min-height: 240px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255,255,255,0.58);
}

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

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.92rem;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fbfaf7;
  color: #4b514c;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

tbody tr:hover {
  background: #fbfaf5;
}

.company {
  display: grid;
  gap: 4px;
  min-width: 220px;
}

.company strong {
  font-size: 0.98rem;
}

.subtle {
  color: var(--muted);
  font-size: 0.82rem;
}

.url-cell {
  max-width: 220px;
  overflow-wrap: anywhere;
}

.contact-cell {
  display: grid;
  gap: 3px;
  min-width: 210px;
}

.contact-cell strong {
  font-size: 0.9rem;
}

.domain-suggestions {
  display: grid;
  gap: 8px;
  min-width: 210px;
}

.domain-suggestions > div {
  display: grid;
  gap: 4px;
  justify-items: start;
}

.domain-suggestions button {
  min-height: 30px;
  padding: 0 9px;
}

.busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  background: rgba(34, 37, 34, 0.18);
  backdrop-filter: blur(2px);
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.auth-gate[aria-hidden="false"] {
  display: grid;
}

.auth-panel {
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-panel strong {
  font-size: 1.3rem;
}

.auth-panel p {
  margin: 0;
  color: var(--muted);
}

.busy-overlay[aria-hidden="false"] {
  display: grid;
}

.busy-dialog {
  display: flex;
  align-items: center;
  gap: 14px;
  width: min(420px, calc(100vw - 36px));
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 26px 72px rgba(33, 35, 31, 0.22);
}

.busy-dialog > div:last-child {
  display: grid;
  gap: 3px;
}

.busy-dialog span {
  color: var(--muted);
  font-size: 0.9rem;
}

.busy-dialog small {
  color: var(--ink);
  font-weight: 850;
}

.busy-progress {
  width: min(280px, 100%);
  height: 8px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #eee9df;
}

.busy-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 180ms ease;
}

.busy-spinner {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: 4px solid #d8e6df;
  border-top-color: var(--accent);
  border-right-color: var(--accent-2);
  border-radius: 999px;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eee9df;
  font-weight: 850;
  font-size: 0.8rem;
}

.badge.ok {
  background: #dfeee3;
  color: var(--ok);
}

.badge.fail {
  background: #f0ded9;
  color: var(--danger);
}

.badge.parked {
  background: #f3e8cc;
  color: var(--warn);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.proposal-link-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}

.row-actions button {
  min-height: 32px;
  padding: 0 10px;
}

.empty-row td {
  height: 180px;
  text-align: center;
  color: var(--muted);
  vertical-align: middle;
}

@media (max-width: 1050px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  #searchForm {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toolbar,
  .toolbar-actions {
    justify-content: flex-start;
  }

  .toolbar {
    flex-direction: column;
  }

  .saved-view {
    grid-template-columns: 1fr;
  }

  .saved-map {
    position: static;
  }

  .map-card {
    grid-template-columns: 120px 1fr;
    align-items: center;
  }

  .map-card svg {
    max-height: 220px;
  }
}

@media (max-width: 760px) {
  #searchForm,
  .stats {
    grid-template-columns: 1fr;
  }
}
