:root {
  --bg: #0e1827;
  --surface: #17273d;
  --bg-soft: #1d2f49;
  --ink: #f4ecd9;
  --muted: #8293aa;
  --line: #2a3b55;
  --primary: #d49836;
  --primary-hover: #e3a843;
  --on-primary: #1b1208;
  --accent: #6ba6d8;
  --danger: #e06a4a;
  --danger-bg: #2a1612;
  --panel-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #ffffff;
  --surface: #ffffff;
  --bg-soft: #f7f7f7;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e5e5e5;
  --primary: #3a6b9e;
  --primary-hover: #2d5580;
  --on-primary: #ffffff;
  --accent: #c8892f;
  --danger: #b23a1a;
  --danger-bg: #fdf2ee;
  --panel-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.15);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  font-size: 16px;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

/* Header */

header {
  text-align: center;
  margin-bottom: 1.25rem;
}

.logo {
  display: block;
  margin: 0 auto;
  width: min(357px, 76.5%);
  height: auto;
}

/* Headings */

h2 {
  font-size: 1.15rem;
  margin: 0 0 1.25rem;
  font-weight: 600;
}

h3 {
  font-size: 0.95rem;
  margin: 1.5rem 0 0.5rem;
  font-weight: 600;
}

/* Form */

form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.business-input {
  padding: 0.85rem 1rem;
  font-size: 1rem;
}

.business-input::placeholder {
  color: var(--muted);
}

/* Image grid */

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.6rem;
}

.tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  animation: tile-in 0.25s ease-out both;
}

@keyframes tile-in {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.tile:hover .tile-remove,
.tile:focus-within .tile-remove {
  opacity: 1;
}

.tile-add {
  background: var(--bg-soft);
  border: 1.5px dashed var(--line);
  color: var(--muted);
  font-size: 2rem;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    border-color 0.15s,
    color 0.15s,
    background 0.15s;
  font-family: inherit;
  padding: 0;
}

.tile-add:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--surface);
}

.tile-add.empty {
  grid-column: 1 / -1;
  aspect-ratio: auto;
  padding: 1.4rem 1rem;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 1rem;
}

.tile-add.empty .plus {
  font-size: 1.75rem;
  line-height: 1;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--ink);
}

.optional {
  color: var(--muted);
  font-weight: normal;
}

input[type="text"],
input[type="password"],
select {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
}

input[type="file"] {
  font-size: 0.9rem;
  font-family: inherit;
}

input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 0.5rem;
}

/* Settings menu */

.settings {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10;
}

.settings-toggle {
  width: 40px;
  height: 40px;
  padding: 0;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.settings-toggle:hover {
  background: var(--bg-soft);
  color: var(--primary);
}

.settings-toggle[aria-expanded="true"] {
  background: var(--bg-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.settings-panel {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.1rem 1.1rem;
  box-shadow: var(--panel-shadow);
  flex-direction: column;
  gap: 0;
}

.settings-panel:not([hidden]) {
  display: flex;
}

.settings-panel h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.9rem 0 0.25rem;
}

.settings-section + .settings-section {
  padding-top: 1.1rem;
}

.settings-section-title {
  margin: 0 0 0.1rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.help-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}

.help-link:hover:not(:disabled) {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--bg-soft);
}

.auth-logout {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.auth-logout:hover:not(:disabled) {
  color: var(--ink);
  background: var(--bg-soft);
}

.auth-status {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  color: var(--ink);
}

.auth-status strong {
  font-weight: 600;
  word-break: break-all;
}

.help-toggle {
  position: fixed;
  top: 1rem;
  right: calc(1rem + 40px + 0.5rem);
  z-index: 10;
}

/* Help modal */

.help-modal {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.75rem 1.75rem 1.25rem;
  background: var(--surface);
  color: var(--ink);
  max-width: 640px;
  width: calc(100% - 2rem);
  max-height: calc(100vh - 3rem);
  overflow: auto;
  box-shadow: var(--panel-shadow);
}

.help-modal::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.help-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.help-modal-header h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1;
}

.help-modal-close {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0 0.3rem;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.help-modal-close:hover:not(:disabled) {
  color: var(--ink);
}

.help-section {
  margin-top: 1.75rem;
}

.help-section:first-of-type {
  margin-top: 1rem;
}

.help-intro {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--ink);
}

.help-section h3 {
  margin: 0 0 0.85rem;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.help-section h4 {
  margin: 1rem 0 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
}

.help-section p,
.help-section ol,
.help-section ul {
  margin: 0 0 0.6rem;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--ink);
}

.help-section ol,
.help-section ul {
  padding-left: 1.3rem;
}

.help-section li {
  margin: 0.2rem 0;
}

.help-section code {
  background: var(--bg-soft);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.help-footnote {
  margin: 0.25rem 0 0 !important;
  font-size: 0.82rem !important;
  color: var(--muted) !important;
}

.help-details {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-soft);
  margin: 0 0 0.9rem;
  overflow: hidden;
}

.help-details > summary::-webkit-details-marker {
  display: none;
}

.help-details > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}

.help-details > summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid var(--muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.help-details[open] > summary::before {
  transform: rotate(90deg);
}

.help-details > p {
  margin: 0 !important;
  padding: 0 0.85rem 0.75rem 1.65rem;
  font-size: 0.88rem !important;
}

/* API key status row in settings */

.api-key-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.api-key-row-label {
  font-size: 0.85rem;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.api-key-row-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

#api-key-reset {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  border-radius: 5px;
}

#api-key-reset:hover:not(:disabled) {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--bg-soft);
}

/* API key modal */

.api-key-modal {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.5rem;
  background: var(--surface);
  color: var(--ink);
  max-width: 420px;
  width: calc(100% - 2rem);
  box-shadow: var(--panel-shadow);
}

.api-key-modal::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.api-key-modal h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.api-key-modal p {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.api-key-modal label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--ink);
  margin-bottom: 1rem;
}

.api-key-modal input[type="password"] {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
}

.api-key-modal input[type="password"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}

.api-key-modal-error {
  margin: 0 0 0.8rem !important;
  color: var(--danger) !important;
  font-size: 0.85rem !important;
}

.api-key-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

.api-key-modal-actions button {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}

#api-key-modal-cancel {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

#api-key-modal-cancel:hover:not(:disabled) {
  color: var(--ink);
  background: var(--bg-soft);
}

/* Auth gate (full screen sign-in) */

.auth-gate {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
}

.auth-gate:not([hidden]) {
  display: flex;
}

.auth-gate-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.auth-gate-logo {
  display: block;
  width: min(240px, 70%);
  height: auto;
  margin: 0 auto 1rem;
}

.auth-gate-card h1 {
  font-size: 1.25rem;
  margin: 0 0 0.4rem;
  font-weight: 600;
}

.auth-gate-subtitle {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

#auth-gate-form {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  text-align: left;
}

#auth-gate-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--ink);
}

#auth-gate-form input[type="email"] {
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
}

#auth-gate-form input[type="email"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}

#auth-send {
  width: 100%;
}

.auth-message {
  margin: 1rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

.auth-message.error {
  color: var(--danger);
}

button {
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--primary-hover);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Reports list */

.reports-section {
  margin-top: 2.5rem;
}

.reports-section h2 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 0.8rem;
  font-weight: 600;
}

.reports-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.reports-list li {
  margin: 0;
}

.report-item {
  min-width: 0;
}

.report-details {
  width: 100%;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.report-details:hover {
  border-color: var(--primary);
}

.report-details > summary::-webkit-details-marker {
  display: none;
}
.report-details > summary {
  list-style: none;
}

.report-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
  user-select: none;
}

.report-details[open] > .report-row {
  border-bottom: 1px solid var(--line);
}

.report-row::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid var(--muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  margin-right: 0.5rem;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.report-details[open] > .report-row::before {
  transform: rotate(90deg);
}

.report-body {
  margin: 0;
  padding: 0.9rem 1rem 1rem;
  background: var(--bg-soft);
  font-size: 0.9rem;
}

.report-body h4 {
  margin: 1rem 0 0.4rem;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.report-body h4:first-child {
  margin-top: 0;
}

.report-body .report-summary {
  margin: 0;
  padding: 0.7rem 0.85rem;
  background: var(--surface);
  border-left: 3px solid var(--primary);
  border-radius: 4px;
  color: var(--ink);
}

.report-body ul {
  padding-left: 1.2rem;
  margin: 0;
}

.report-body li {
  margin: 0.2rem 0;
}

.report-sections-list {
  list-style: none;
  padding: 0 !important;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.report-sections-list li {
  margin: 0;
}

.report-sections-list a {
  display: inline-block;
  padding: 0.25rem 0;
}

.report-download-all {
  margin: 1rem 0 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  font-size: 0.88rem;
}

.report-row-main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  flex: 1;
}

.report-row-date {
  font-size: 0.85rem;
  color: var(--ink);
  font-weight: 500;
}

.report-row-desc {
  font-size: 0.8rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reports-empty {
  margin: 0;
  padding: 0.8rem 0.9rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
}

/* Loading flavor text */

.loading-flavor {
  margin: 0;
  text-align: left;
  font-size: 0.88rem;
  color: var(--muted);
  font-style: italic;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.loading-flavor #status-text {
  transition: opacity 0.35s ease;
  display: inline-block;
}

.loading-flavor.fading #status-text {
  opacity: 0;
}

/* Error */

#error {
  margin-top: 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  border-radius: 6px;
}

#error h3 {
  margin: 0 0 0.4rem;
  color: var(--danger);
  font-size: 0.95rem;
}

#error p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink);
}

.error-hint {
  margin-top: 0.4rem !important;
  color: var(--muted) !important;
}

ul {
  padding-left: 1.25rem;
  margin: 0;
}

li {
  margin: 0.25rem 0;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
