:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
}

* { box-sizing: border-box; }

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

#app { min-height: 100vh; display: flex; flex-direction: column; }

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: env(safe-area-inset-top) 16px 12px;
  padding-top: calc(env(safe-area-inset-top) + 12px);
}

header h1 { font-size: 18px; margin: 0 0 10px; }

#search {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
}

#search:focus { outline: 2px solid var(--accent); }

#status-banner {
  display: none;
  background: #7c2d12;
  color: #fed7aa;
  padding: 8px 16px;
  font-size: 13px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#status-banner.visible { display: flex; }
#status-banner button {
  background: #fed7aa;
  color: #7c2d12;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
}

main { flex: 1; padding: 12px 16px 32px; }

.brand-list { list-style: none; margin: 0; padding: 0; }

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.brand-row:active { background: var(--surface-2); }

.brand-row .name { font-size: 16px; font-weight: 600; }
.brand-row .meta { font-size: 13px; color: var(--text-dim); }
.brand-row .chev { color: var(--text-dim); font-size: 18px; }

.empty-state { text-align: center; color: var(--text-dim); padding: 40px 16px; }

/* Detail view */
.detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 16px;
  padding: 6px 0;
}
.detail-header h2 { margin: 0; font-size: 20px; flex: 1; }

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 20px 0 8px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.field-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.field-row:last-child { border-bottom: none; }
.field-row .label { color: var(--text-dim); }

.flag-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.flag {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}
.flag .icon { font-size: 16px; }
.flag.on .icon { color: var(--green); }
.flag.off .icon { color: var(--red); }
.flag-group-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 12px 0 6px;
}

textarea {
  width: 100%;
  min-height: 70px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}

.contact-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.contact-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.contact-name { font-weight: 600; font-size: 15px; }
.contact-meta { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.contact-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 0;
  white-space: nowrap;
}

.ghost-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  flex: 1;
}

.contact-edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 4px;
}
.contact-edit-grid input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px;
  font-size: 14px;
}
.contact-edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.save-btn.small {
  padding: 10px 14px;
  font-size: 14px;
  flex: 1;
  border-radius: 8px;
}

.save-bar {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  margin: 24px -16px -32px;
}
.save-btn {
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
}
.save-btn:disabled { opacity: 0.5; }

/* Login */
.login-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 14px;
}
.login-screen h1 { font-size: 20px; margin: 0 0 8px; }
.login-screen input {
  width: 100%;
  max-width: 320px;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  text-align: center;
}
.login-screen button {
  width: 100%;
  max-width: 320px;
  padding: 14px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 16px;
  font-weight: 600;
}
.login-error { color: var(--red); font-size: 13px; min-height: 18px; }

.spinner {
  text-align: center;
  color: var(--text-dim);
  padding: 40px;
}
