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

:root {
  --bg: #1a1a1a;
  --surface: #242424;
  --surface2: #2e2e2e;
  --border: #3a3a3a;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent-storage: #c0842a;
  --accent-money: #4caf50;
  --accent-secure: #2a7fc0;
  --complete: #2d5a2d;
  --complete-border: #4caf50;
  --collected: #1e3a1e;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.search-wrap {
  display: flex;
  align-items: center;
  position: relative;
}

#search-input {
  background: var(--surface2);
  border: 1px solid #555;
  border-radius: 4px;
  color: var(--text);
  font-size: 14px;
  padding: 6px 28px 6px 12px;
  outline: none;
  width: 260px;
}
#search-input:focus { border-color: #999; }
#search-input::placeholder { color: var(--text-muted); }

#search-clear {
  display: none;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  padding: 0;
  line-height: 1;
}
#search-clear:hover { color: var(--text); }

#save-status {
  font-size: 12px;
  color: var(--text-muted);
  transition: opacity 0.3s;
}

#app {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  min-height: calc(100vh - 57px);
}

/* Quest chain column */
.chain {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.chain:last-child { border-right: none; }

.chain-header {
  padding: 14px 16px 10px;
  border-bottom: 3px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 10;
}
.chain[data-id="storage"] .chain-header { border-bottom-color: var(--accent-storage); }
.chain[data-id="money"]   .chain-header { border-bottom-color: var(--accent-money); }
.chain[data-id="secure"]  .chain-header { border-bottom-color: var(--accent-secure); }

.chain-title {
  font-size: 16px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.progress-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
  background: var(--text-muted);
}
.chain[data-id="storage"] .progress-bar-fill { background: var(--accent-storage); }
.chain[data-id="money"]   .progress-bar-fill { background: var(--accent-money); }
.chain[data-id="secure"]  .progress-bar-fill { background: var(--accent-secure); }

.progress-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Stage card */
.stage {
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  transition: background 0.2s;
}

.stage.complete {
  background: var(--complete);
}

.stage.ready {
  background: rgba(255, 193, 7, 0.08);
  border-color: rgba(255, 193, 7, 0.45);
}

.stage-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  cursor: pointer;
  user-select: none;
  background: var(--surface2);
}
.stage.complete .stage-header,
.stage.ready .stage-header {
  background: transparent;
}

.stage-toggle {
  font-size: 11px;
  color: var(--text-muted);
  transition: transform 0.2s;
  flex-shrink: 0;
}
.stage.collapsed .stage-toggle { transform: rotate(-90deg); }

.stage-num {
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.stage-cost {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
  white-space: nowrap;
}

.stage-check {
  font-size: 14px;
  flex-shrink: 0;
}

.stage-body {
  padding: 8px 16px 12px;
}
.stage.collapsed .stage-body { display: none; }

/* Handed-in row */
.handed-in-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 6px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: #a5d6a7;
}
.handed-in-row.hidden { display: none; }
.handed-in-row input[type="checkbox"] { accent-color: #4caf50; cursor: pointer; width: 15px; height: 15px; }
.handed-in-row input[type="checkbox"]:disabled { cursor: not-allowed; opacity: 0.4; }
.handed-in-row:has(input:disabled) { opacity: 0.5; }
.handed-in-row label { cursor: pointer; }

/* Item rows */
.item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-radius: 4px;
  transition: background 0.15s;
}
.item-row:hover { background: var(--surface2); padding-left: 4px; padding-right: 4px; margin: 0 -4px; }

.item-row.collected { opacity: 1; }
.item-row:not(.collected) { opacity: 0.65; }

.item-row input[type="checkbox"] {
  flex-shrink: 0;
  accent-color: #4caf50;
  cursor: pointer;
  width: 15px;
  height: 15px;
}

.item-name {
  flex: 1;
  font-size: 13px;
  cursor: pointer;
}

.shared-badge {
  font-size: 10px;
  color: #e0a030;
  font-weight: 700;
  background: #3a2800;
  border: 1px solid #5a3d00;
  border-radius: 3px;
  padding: 1px 4px;
  flex-shrink: 0;
}

.location-select {
  font-size: 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 4px;
  cursor: pointer;
  flex-shrink: 0;
  min-width: 80px;
}
.location-select:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.location-select option { background: var(--surface); }

/* Search highlight */
.item-row.search-match {
  background: rgba(255, 200, 0, 0.15) !important;
  outline: 1px solid rgba(255, 200, 0, 0.4);
  border-radius: 4px;
  opacity: 1 !important;
}
.item-row.search-no-match {
  opacity: 0.15 !important;
}

/* Location color coding */
.item-row.loc-base   .item-name { color: #f0c060; }
.item-row.loc-atlas  .item-name { color: #60c0f0; }

@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; }
  .chain { border-right: none; border-bottom: 1px solid var(--border); }
}

/* ─── User info / logout in header ──────────────────────────────────────────── */

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.user-email {
  font-size: 12px;
  color: var(--text-muted);
}

.logout-btn {
  font-size: 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  padding: 3px 10px;
  cursor: pointer;
}
.logout-btn:hover {
  border-color: #888;
  color: var(--text);
}

/* ─── Login page ─────────────────────────────────────────────────────────────── */

body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-card h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.login-error {
  font-size: 13px;
  color: #f28b82;
  background: rgba(242, 139, 130, 0.1);
  border: 1px solid rgba(242, 139, 130, 0.3);
  border-radius: 4px;
  padding: 8px 12px;
}

.login-success {
  font-size: 13px;
  color: #a5d6a7;
  background: rgba(165, 214, 167, 0.1);
  border: 1px solid rgba(165, 214, 167, 0.3);
  border-radius: 4px;
  padding: 8px 12px;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#email-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 14px;
  padding: 8px 12px;
  outline: none;
  width: 100%;
}
#email-input:focus { border-color: var(--accent-secure); }
#email-input::placeholder { color: var(--text-muted); }

#submit-btn {
  background: var(--accent-secure);
  border: none;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 9px;
}
#submit-btn:hover { filter: brightness(1.15); }
#submit-btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }

.privacy-notice {
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 4px;
  line-height: 1.5;
}
.privacy-notice a { color: var(--text-muted); }
.privacy-notice a:hover { color: var(--text); }

.guest-link {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}
.guest-link button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  text-decoration: underline;
  padding: 0;
}
.guest-link button:hover { color: var(--text); }
