* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: monospace;
  background: #fafafa;
  color: #111;
  padding: 40px 20px;
  max-width: 1200px;
  margin: 0 auto;
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 20px;
  margin-bottom: 32px;
  background: #f7f8ec;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.site-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  flex-shrink: 0;
}
.site-heading h1 {
  font-size: 1.75rem;
  line-height: 1.1;
  margin-bottom: 2px;
}
.site-heading .subtitle {
  color: #6b7280;
  font-size: 0.9rem;
}

h1 { font-size: 2rem; margin-bottom: 4px; }
.subtitle { color: #666; }

/* Input card */
#input-card {
  background: #fff;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.input-label {
  font-size: 0.75rem;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: bold;
}
#gtm-input {
  width: 100%;
  font-family: monospace;
  font-size: 1.6rem;
  padding: 16px 20px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  background: #fafafa;
  color: #111;
  letter-spacing: 0.05em;
  transition: border-color 0.15s, background 0.15s;
}
#gtm-input:focus {
  outline: none;
  border-color: #6366f1;
  background: #fff;
}
#gtm-input::placeholder {
  color: #b0b4bb;
  letter-spacing: 0.05em;
}

.input-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.selected-file {
  font-size: 0.82rem;
  color: #4b5563;
  min-height: 1em;
}

button {
  padding: 10px 22px;
  font-family: monospace;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  border-radius: 6px;
  font-weight: bold;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
button:disabled { background: #aaa; cursor: not-allowed; color: #fff; }

.btn-primary {
  background: #111;
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: #374151; }

.btn-secondary {
  background: #fff;
  color: #111;
  border: 1.5px solid #d1d5db;
}
.btn-secondary:hover:not(:disabled) {
  border-color: #6366f1;
  color: #6366f1;
}

#status { font-size: 0.9rem; color: #555; margin-bottom: 12px; min-height: 1.2em; }

/* Metadata bar */
#meta-bar {
  background: #1e1e2e;
  color: #cdd6f4;
  border-radius: 6px;
  padding: 14px 20px;
  margin-bottom: 28px;
  display: none;
  gap: 32px;
  flex-wrap: wrap;
  font-size: 0.85rem;
}
#meta-bar.visible { display: flex; }
.meta-item { display: flex; flex-direction: column; gap: 2px; }
.meta-label { color: #6c7086; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.meta-value { color: #cba6f7; font-weight: bold; }

/* Results sections */
#results { display: flex; flex-direction: column; gap: 36px; }

.count-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: bold;
  color: #fff;
}
.count-badge.tags      { background: #1d4ed8; }
.count-badge.variables { background: #15803d; }
.count-badge.triggers  { background: #b45309; }
.count-badge.templates { background: #7c3aed; }

/* Tabs */
.tabs { display: flex; flex-direction: column; gap: 18px; }

.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 1.5px solid #e5e7eb;
}
.tab-btn {
  background: none;
  color: #6b7280;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 16px;
  margin-bottom: -1.5px;
  font-family: monospace;
  font-size: 0.95rem;
  font-weight: bold;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tab-btn:hover { color: #111; }
.tab-btn.active {
  color: #111;
  border-bottom-color: #111;
}

.tab-panels { display: contents; }
.tab-panel { display: none; flex-direction: column; gap: 16px; }
.tab-panel.active { display: flex; }

/* Tab header (filters) */
.tab-header {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  background: #fff;
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  padding: 14px 16px;
}
.filter-field { display: flex; flex-direction: column; gap: 4px; }
.filter-label {
  font-size: 0.7rem;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.filter-input {
  font-family: monospace;
  font-size: 0.85rem;
  padding: 7px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  background: #fafafa;
  color: #111;
}
.filter-input:focus {
  outline: none;
  border-color: #6366f1;
  background: #fff;
}

.empty-note { font-size: 0.82rem; color: #9ca3af; }

.tab-summary {
  font-size: 0.8rem;
  color: #6b7280;
}

/* Tile grid */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

/* Individual tile */
.tile {
  background: #fff;
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tile:hover {
  border-color: #6366f1;
  box-shadow: 0 2px 10px rgba(99,102,241,0.12);
}
.tile.paused {
  background: #f9fafb;
  opacity: 0.75;
  border-style: dashed;
}
.tile.paused .tile-title { color: #4b5563; }

.tile-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: bold;
  color: #fff;
  align-self: flex-start;
}
.tile-badge.tag      { background: #1d4ed8; }
.tile-badge.variable { background: #15803d; }
.tile-badge.trigger  { background: #b45309; }
.tile-badge.template { background: #7c3aed; }

.tile-title {
  font-size: 0.9rem;
  font-weight: bold;
  word-break: break-word;
  line-height: 1.3;
}
.tile-subtitle {
  font-size: 0.78rem;
  color: #6b7280;
  word-break: break-word;
}

.tile-refs-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.tile-refs-summary {
  margin-top: 4px;
  font-size: 0.78rem;
  color: #6b7280;
}

/* Reference chips. One rule, four palette variants — colors mirror the
   .tile-badge.* / .count-badge.* palette so the type is recognisable. */
.ref-chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid;
  border-radius: 999px;
  padding: 3px 10px;
  font-family: monospace;
  font-size: 0.78rem;
  font-weight: 600;
  background: transparent;
  cursor: pointer;
  margin: 0;
  transition: background-color 80ms, filter 80ms;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ref-chip:hover { filter: brightness(0.95); }

.ref-chip-tag      { color: #1d4ed8; border-color: #bfdbfe; background: #eff6ff; }
.ref-chip-variable { color: #15803d; border-color: #bbf7d0; background: #f0fdf4; }
.ref-chip-trigger  { color: #b45309; border-color: #fde68a; background: #fffbeb; }
.ref-chip-template { color: #7c3aed; border-color: #ddd6fe; background: #f5f3ff; }

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

#modal {
  background: #fff;
  border-radius: 10px;
  padding: 28px;
  width: 90%;
  max-width: 640px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  color: #111;
  font-size: 1.4rem;
  padding: 0 6px;
  line-height: 1;
  border-radius: 4px;
}
#modal-close:hover { background: #f3f4f6; }

#modal-title { font-size: 1.1rem; font-weight: bold; padding-right: 32px; }
#modal-subtitle { font-size: 0.82rem; color: #6b7280; }

#modal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-top: 8px;
}
#modal-table th, #modal-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: top;
  word-break: break-word;
}
#modal-table th { background: #f9fafb; font-weight: bold; color: #374151; }
#modal-table td:first-child { color: #6b7280; width: 35%; }

/* Drawer */
#drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 110;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
}
#drawer-overlay.open {
  opacity: 1;
  visibility: visible;
}

#drawer {
  position: absolute;
  top: 0;
  right: 0;
  height: 100vh;
  width: 680px;
  max-width: 100%;
  background: #fff;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
#drawer-overlay.open #drawer { transform: translateX(0); }

.drawer-ghost {
  position: absolute;
  top: 0;
  right: 0;
  height: 100vh;
  width: 680px;
  max-width: 100%;
  background: #fff;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.18);
  transform: translateX(0);
  transition: transform 0.25s ease;
  pointer-events: none;
  filter: brightness(0.55);
}

@media (max-width: 768px) {
  #drawer { width: 100vw; }
  .drawer-ghost { width: 100vw; }
}

#drawer-header {
  position: relative;
  padding: 22px 56px 18px 24px;
  border-bottom: 1.5px solid #e5e7eb;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#drawer-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  color: #111;
  font-size: 1.4rem;
  padding: 0 8px;
  line-height: 1;
  border-radius: 4px;
}
#drawer-close:hover { background: #f3f4f6; }

.drawer-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 0.74rem;
  color: #6b7280;
  margin-bottom: 6px;
  font-family: monospace;
}
.drawer-crumb {
  background: none;
  border: none;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: inherit;
  font-size: inherit;
  color: #6366f1;
  cursor: pointer;
  font-weight: bold;
}
.drawer-crumb:hover { background: #eef2ff; }
.drawer-crumb.is-current { color: #111; cursor: default; }
.drawer-crumb-sep { color: #9ca3af; }

#drawer-badge-wrap { margin-bottom: 4px; }
.drawer-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
#drawer-title {
  font-size: 1.1rem;
  font-weight: bold;
  word-break: break-word;
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
}
#drawer-subtitle {
  font-size: 0.82rem;
  color: #6b7280;
  word-break: break-word;
}

#drawer-tabbar {
  display: flex;
  gap: 0;
  padding: 0 24px;
  border-bottom: 1.5px solid #e5e7eb;
  flex-shrink: 0;
  overflow-x: auto;
}
.drawer-tab-btn {
  background: none;
  color: #6b7280;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 12px 14px;
  margin-bottom: -1.5px;
  font-family: monospace;
  font-size: 0.88rem;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
}
.drawer-tab-btn:hover { color: #111; }
.drawer-tab-btn.active {
  color: #111;
  border-bottom-color: #111;
}

#drawer-content {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px 24px 32px;
}

.drawer-section { display: flex; flex-direction: column; gap: 18px; }
.drawer-empty { color: #9ca3af; font-size: 0.85rem; }

/* "Used in" tab */
.used-in-tab { gap: 22px; }
.used-in-section { display: flex; flex-direction: column; gap: 8px; }
.used-in-heading {
  font-size: 0.78rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #374151;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 4px;
}
.used-in-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Overview key/value table inside drawer */
.kv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.kv-table th, .kv-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: top;
  word-break: break-word;
}
.kv-table th { background: #f9fafb; font-weight: bold; color: #374151; }
.kv-table td:first-child { color: #6b7280; width: 40%; }

/* Permissions */
.perm-section { display: flex; flex-direction: column; gap: 8px; }
.perm-heading {
  font-size: 0.78rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #374151;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 4px;
}
.perm-empty { color: #9ca3af; font-size: 0.82rem; }
.perm-value { font-size: 0.85rem; }

.perm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.perm-table th, .perm-table td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: top;
  word-break: break-word;
}
.perm-table th {
  background: #f9fafb;
  font-weight: bold;
  color: #374151;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.perm-table td.perm-flag {
  width: 64px;
  text-align: center;
  font-weight: bold;
}
.perm-table td.perm-flag.yes { color: #15803d; }
.perm-table td.perm-flag.no  { color: #d1d5db; }
.perm-table td.perm-key {
  color: #111;
  font-weight: bold;
  max-width: 320px;
  overflow-wrap: break-word;
}

/* Rename button in drawer header */
.rename-btn {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  line-height: 0;
}
.rename-btn:hover { color: #6366f1; background: #f3f4f6; }
.rename-btn svg { display: block; }

/* Inline rename input */
.rename-input {
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: bold;
  padding: 4px 8px;
  border: 1.5px solid #6366f1;
  border-radius: 4px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
}

.perm-bullet-list {
  list-style: disc;
  padding-left: 22px;
  font-size: 0.82rem;
  color: #111;
}
.perm-bullet-list li { word-break: break-word; padding: 2px 0; }

.perm-kv, .perm-rdl { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; }
.perm-sub-label {
  display: inline-block;
  color: #6b7280;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 6px;
}
.perm-json {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 0.78rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* APIs Used */
.apis-title {
  font-size: 0.82rem;
  color: #4b5563;
  margin-bottom: 4px;
}
.api-pill-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.api-pill {
  display: inline-block;
  background: #ede9fe;
  color: #5b21b6;
  border: 1px solid #ddd6fe;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: bold;
}

.sandboxed-js-heading {
  margin-top: 22px;
}

.sandboxed-js-code {
  background: #1e1e2e;
  color: #cdd6f4;
  border-radius: 6px;
  padding: 14px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre;
  overflow: auto;
  max-height: 60vh;
  margin: 6px 0 0;
}

.sandboxed-js-code code {
  font-family: inherit;
  background: none;
  padding: 0;
}

/* Code blocks rendered inside kv-table value cells */
.kv-table td .sandboxed-js-code,
#modal-table td .sandboxed-js-code {
  margin: 0;
  max-height: 50vh;
  white-space: pre;
}

/* Pretty names + raw-key pill (used for tag/variable/trigger types and parameter keys) */
.pretty-name {
  font-weight: bold;
  color: #111;
}
.pretty-name.is-unreferenced {
  color: #b45309;
  font-style: italic;
  font-weight: bold;
}
.raw-key-pill {
  display: inline-block;
  background: #f3f4f6;
  color: #6b7280;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.7rem;
  font-weight: normal;
  vertical-align: middle;
  word-break: break-all;
}
.is-unreferenced + .raw-key-pill {
  background: #fef3c7;
  color: #b45309;
  border-color: #fde68a;
}
#modal-table td .raw-key-pill,
.kv-table td .raw-key-pill {
  margin-top: 2px;
}

/* Export button (Download JSON Export) */
#export-bar {
  margin: 0.5rem 0 0;
}
.export-btn {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
  border: 1px solid #6366f1;
  background: transparent;
  color: #6366f1;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.export-btn:hover {
  background: #6366f1;
  color: #fff;
}
.export-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}
.export-btn[hidden] {
  display: none !important;
}
