:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --danger: #f87171;
  --radius: 10px;
  --nav-height: 4.75rem;
  --topbar-height: 3rem;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow: hidden;
}

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow: auto;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  padding: 1.75rem;
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.auth-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

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

.muted.small {
  font-size: 0.8rem;
  margin: 0.35rem 0 0;
}

label {
  display: block;
  margin-top: 1rem;
  font-size: 0.85rem;
}

input,
textarea {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid #2c3a50;
  background: #121a26;
  color: var(--text);
}

.topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid #243044;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

.app-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem;
}

@media (min-width: 768px) {
  .container {
    max-width: 960px;
  }
}

.tab-viewport {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: 0.35rem;
  padding-bottom: 0.25rem;
}

.tab-panel-compact {
  padding-top: 0;
}

.tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.5rem;
}

.tab-panel.active {
  display: flex;
}

.tab-title {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  flex-shrink: 0;
}

.row label {
  flex: 1 1 160px;
  margin-top: 0;
}

.row label.flex-grow {
  flex: 1 1 200px;
}

.hidden {
  display: none !important;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.link {
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
}

.results {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}

.results li button,
.resident-btn {
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.35rem;
  border-radius: 8px;
  border: 1px solid #2c3a50;
  background: #121a26;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  font: inherit;
}

.results li button .result-name,
.resident-btn .result-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.results li button .result-address,
.resident-btn .result-address {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: pre-wrap;
  word-break: break-word;
}

.results li button .result-distance,
.resident-btn .result-distance {
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 500;
}

.results li button:hover,
.resident-btn:hover {
  border-color: var(--accent);
}

.address-card {
  background: var(--surface);
  border: 1px solid #243044;
  border-radius: var(--radius);
  overflow: hidden;
}

.address-card-header {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #243044;
  background: #151d2a;
}

.address-card-header .address-line {
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1.35;
  word-break: break-word;
}

.address-card-header .address-distance {
  font-size: 0.7rem;
  color: var(--accent);
  margin-top: 0.2rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
}

.address-card-residents {
  list-style: none;
  margin: 0;
  padding: 0.15rem 0;
}

.address-card-residents li {
  margin: 0;
}

.address-card-residents .resident-btn {
  margin-bottom: 0;
  padding: 0.7rem 0.75rem;
  border: none;
  border-radius: 0;
  background: transparent;
  border-bottom: 1px solid #1e2a3c;
}

.address-card-residents li:last-child .resident-btn {
  border-bottom: none;
}

.address-card-residents .resident-btn .result-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.address-card-residents .resident-btn:hover {
  background: #121a26;
}

.address-groups {
  margin-top: 0.25rem;
}

.address-card {
  margin-bottom: 0.5rem;
}

.nearby-toolbar {
  flex-shrink: 0;
  padding: 0 0 0.35rem;
}

.search-bar,
.search-field {
  width: 100%;
  margin: 0;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid #2c3a50;
  background: #121a26;
  color: var(--text);
  font-size: 1rem;
}

.search-bar:disabled {
  opacity: 0.65;
}

.mobile-search-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-shrink: 0;
  padding-bottom: 0.35rem;
}

.mobile-search-form .search-field {
  margin-top: 0;
}

.address-search-hint {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.address-search-hint strong {
  color: #a8b8d0;
  font-weight: 600;
}

.btn-block {
  width: 100%;
  padding: 0.7rem 1rem;
  margin-top: 0.15rem;
  font-size: 1rem;
}

.status-inline {
  margin: 0.25rem 0 0;
  padding: 0;
  font-size: 0.8rem;
  color: var(--danger);
}

.status-inline.hidden {
  display: none;
}

.location-help {
  flex-shrink: 0;
  margin-top: 0.5rem;
  padding: 1rem 1rem 1rem 0.9rem;
  background: #3a2a14;
  border: 1px solid #b45309;
  border-left: 4px solid #f59e0b;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(245, 158, 11, 0.12);
}

.location-help.hidden {
  display: none;
}

.location-help-header {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.location-help-icon {
  flex-shrink: 0;
  width: 1.35rem;
  height: 1.35rem;
  margin-top: 0.1rem;
  color: #fbbf24;
}

.location-help-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #fde68a;
  line-height: 1.3;
}

.location-help-lead {
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
  color: #fcd34d;
  line-height: 1.45;
  opacity: 0.95;
}

.location-help-steps {
  margin: 0 0 0.75rem;
  padding-left: 1.2rem;
  font-size: 0.88rem;
  color: #fef3c7;
  line-height: 1.5;
}

.location-help-steps li {
  margin-bottom: 0.5rem;
}

.location-help-steps li:last-child {
  margin-bottom: 0;
}

.location-help-steps strong {
  color: #fff;
  font-weight: 600;
}

.location-help-note {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
  color: #fbbf24;
  line-height: 1.4;
}

.location-help-note strong {
  color: #fde68a;
}

.location-help .btn.primary {
  background: #d97706;
  color: #1a1208;
  font-weight: 700;
}

.location-help .btn.primary:active {
  background: #f59e0b;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 0.75rem);
  transform: translateX(-50%) translateY(1rem);
  z-index: 1000;
  max-width: calc(100% - 2rem);
  width: max-content;
  padding: 0.75rem 1.25rem;
  border-radius: 10px;
  background: #1e3a2f;
  border: 1px solid #2d6a4f;
  color: #b7e4c7;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast.error {
  background: #3a1e1e;
  border-color: #6a2d2d;
  color: #f8b4b4;
}

.person-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.person-header-main {
  flex: 1;
  min-width: 0;
}

.person-label {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
}

.person-address {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
}

.captain-toggle {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.1rem;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  border: 2px solid #c9a227;
  background: rgba(201, 162, 39, 0.15);
  color: #e8c547;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.captain-toggle:has(input:checked) {
  background: linear-gradient(180deg, #e8c547 0%, #c9a227 100%);
  border-color: #e8c547;
  color: #1a1408;
  box-shadow: 0 2px 8px rgba(201, 162, 39, 0.45);
}

.captain-toggle input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  accent-color: #1a1408;
}

.captain-toggle-text {
  line-height: 1;
}

.person-tags {
  margin: 0 0 1rem;
}

.tags-legend {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.tag-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--tag-color, var(--accent));
  background: var(--tag-bg, rgba(91, 141, 239, 0.12));
  color: var(--tag-fg, var(--text));
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tag-pill.is-selected {
  background: var(--tag-color, var(--accent));
  color: #fff;
  border-color: var(--tag-color, var(--accent));
}

.tag-pill.is-inactive {
  opacity: 0.75;
  border-style: dashed;
}

.tag-pill .tag-checkbox {
  width: 0.95rem;
  height: 0.95rem;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--tag-color, var(--accent));
}

.tag-pill.is-selected .tag-checkbox {
  accent-color: #fff;
}

.tags-other {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

.tags-other select[multiple] {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  min-height: 5.5rem;
  padding: 0.35rem;
  border-radius: 8px;
  border: 1px solid #2c3a50;
  background: var(--bg);
  color: var(--text);
}

.error {
  color: var(--danger);
  margin-bottom: 0.75rem;
}

.inline {
  display: inline;
  margin: 0;
}

.fieldset-support {
  border: 1px solid #2c3a50;
  border-radius: 8px;
  padding: 0.75rem 1rem 1rem;
  margin: 1rem 0 0;
}

.fieldset-support legend {
  padding: 0 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.radio-row,
.checkbox-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.radio-row:first-of-type,
.checkbox-row {
  margin-top: 0.35rem;
}

.radio-row input[type="radio"],
.checkbox-row input[type="checkbox"] {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}

.bottom-nav {
  flex-shrink: 0;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid #243044;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  min-height: var(--nav-height);
  padding: 0.5rem 0.35rem;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}

.nav-item .nav-icon {
  width: 1.85rem;
  height: 1.85rem;
}

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

.nav-label {
  line-height: 1.15;
  letter-spacing: 0.01em;
}
