/* Shared layout and components for eBird Folders web UI */
:root {
  --color-bg: #f0f4f3;
  --color-surface: #ffffff;
  --color-text: #2c3e50;
  --color-text-muted: #5c6b7a;
  --color-primary: #2d8a6e;
  --color-primary-hover: #247a61;
  --color-accent: #3b82f6;
  --color-accent-hover: #2563eb;
  --color-danger: #dc3545;
  --color-border: #e2e8f0;
  --color-header-border: #dde4ea;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --header-height: 56px;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--color-accent-hover);
}

.container {
  background: var(--color-surface);
  max-width: 1200px;
  width: min(100%, 1200px);
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2.5rem;
  min-height: 100vh;
  text-align: left;
}

.container--card {
  margin: 1rem auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

h1, h2, h3 {
  color: var(--color-text);
  line-height: 1.25;
}

h2 {
  margin-top: 2rem;
  margin-bottom: 1rem;
  font-size: 1.35rem;
  font-weight: 600;
  border-bottom: 2px solid var(--color-border);
  padding-bottom: 0.5rem;
}

h2.original-downloads-header {
  margin-top: 2.5rem;
}

.page-title {
  margin: 0 0 1.5rem;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
}

p {
  color: var(--color-text-muted);
  margin: 0 0 1rem;
}

/* Header & navigation */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  min-height: var(--header-height);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-header-border);
  margin: -1.25rem -1.5rem 1.25rem;
  padding: 0.5rem 1.5rem;
}

.site-title-link {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: inherit;
  min-width: 0;
  flex-shrink: 0;
}

.site-title-link:hover {
  color: var(--color-primary);
}

.site-title-link h1 {
  margin: 0;
  font-size: clamp(1.05rem, 3vw, 1.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-title-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: block;
  object-fit: contain;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-left: auto;
}

.nav-menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
}

.nav-menu-toggle span {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--color-text);
  border-radius: 1px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.header.nav-open .nav-menu-toggle span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.header.nav-open .nav-menu-toggle span:nth-child(2) {
  opacity: 0;
}

.header.nav-open .nav-menu-toggle span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.main-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.35rem;
  align-items: center;
  padding: 0;
  flex: 1 1 auto;
  min-width: 0;
}

.main-nav .nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0.4rem 0.65rem;
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.main-nav .nav-link:hover {
  color: var(--color-text);
  background: #f1f5f9;
}

.main-nav .nav-link.active {
  color: var(--color-primary);
  background: #e8f5f0;
  border-color: #b8e0d0;
}

.breadcrumbs {
  padding: 0.75rem 0;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 1.25rem;
  overflow-x: auto;
  white-space: nowrap;
}

.breadcrumb-link {
  color: var(--color-accent);
}

.breadcrumb-separator {
  margin: 0 0.4rem;
  color: #94a3b8;
}

.breadcrumb-current {
  color: var(--color-text);
  font-weight: 600;
}

.settings-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: -0.5rem 0 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--color-border);
}

.settings-subnav .subnav-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0.3rem 0.75rem;
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
  border-radius: 999px;
  border: 1px solid transparent;
}

.settings-subnav .subnav-link:hover {
  color: var(--color-text);
  background: #f1f5f9;
}

.settings-subnav .subnav-link.active {
  color: var(--color-primary);
  background: #e8f5f0;
  border-color: #b8e0d0;
}

/* User menu */
.user-dropdown {
  position: relative;
}

.user-dropdown-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.user-dropdown-toggle:hover {
  background: #f1f5f9;
}

.user-icon {
  position: relative;
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(160deg, #7a8fa3 0%, #5a7085 100%);
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  line-height: 1;
  border: 2px solid var(--color-border);
  flex-shrink: 0;
}

.user-icon.has-photo {
  background: #e2e8f0;
}

.user-icon.has-photo .user-icon-initials {
  visibility: hidden;
}

.user-icon img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-icon-large {
  width: 48px;
  height: 48px;
  font-size: 1rem;
}

.user-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  display: none;
  overflow: hidden;
}

.user-dropdown.active .user-dropdown-menu {
  display: block;
}

.user-dropdown-identity {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem 0.75rem;
}

.user-dropdown-identity-text {
  min-width: 0;
}

.user-dropdown-identity-text strong {
  display: block;
  font-size: 0.9rem;
  font-weight: 650;
  color: var(--color-text);
  overflow-wrap: anywhere;
}

.user-dropdown-identity-text span {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-dropdown-menu .dropdown-item {
  display: block;
  padding: 0.75rem 1rem;
  color: var(--color-text);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
}

.user-dropdown-menu .dropdown-item:hover {
  background: #f8fafc;
}

.user-dropdown-menu .dropdown-item.logout {
  color: var(--color-danger);
}

.user-dropdown-menu .dropdown-divider {
  height: 1px;
  background: var(--color-border);
  margin: 0.25rem 0;
}

/* Buttons */
a.button,
button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 44px;
  padding: 0.55rem 1rem;
  margin: 0.25rem 0.35rem 0.25rem 0;
  background: var(--color-accent);
  color: #fff !important;
  text-decoration: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  font-family: inherit;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s ease, transform 0.1s ease;
}

a.button:hover,
button:hover:not(:disabled),
.button:hover {
  background: var(--color-accent-hover);
  color: #fff !important;
}

a.button:active,
button:active {
  transform: translateY(1px);
}

a.button.primary,
.button.primary {
  background: var(--color-primary);
}

a.button.primary:hover,
.button.primary:hover {
  background: var(--color-primary-hover);
}

a.button.logout,
.button.logout,
.button.danger {
  background: var(--color-danger);
}

a.button.logout:hover,
.button.danger:hover {
  background: #c82333;
}

a.icon-btn,
button.icon-btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-height: 40px;
  min-width: 40px;
  padding: 0;
  margin: 0;
  background: #f1f5f9 !important;
  color: var(--color-text) !important;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: none;
  text-decoration: none;
  flex-shrink: 0;
}

a.icon-btn:hover,
button.icon-btn:hover:not(:disabled),
.icon-btn:hover {
  background: #e8f5f0 !important;
  color: var(--color-primary) !important;
  transform: none;
}

button.icon-btn.icon-btn-danger {
  background: #fef2f2 !important;
  color: var(--color-danger) !important;
  border-color: #f5c2c7;
}

button.icon-btn.icon-btn-danger:hover:not(:disabled) {
  background: #fee2e2 !important;
  color: #b91c1c !important;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.location-cell {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
}

.location-main {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
}

.location-cell .location-name {
  flex: 1 1 auto;
  min-width: 0;
}

.filename-toggle {
  margin-top: -0.2rem;
}

.filename-toggle[aria-expanded="true"] {
  background: #e8f5f0 !important;
  color: var(--color-primary) !important;
  border-color: #b8e0d0;
}

.filename-detail {
  padding: 0.55rem 0.7rem;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.filename-detail-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
}

.filename-detail code {
  display: block;
  font-size: 0.8rem;
  word-break: break-all;
  color: var(--color-text);
}

th.col-actions,
td.col-actions {
  width: 3.75rem;
  white-space: nowrap;
  word-break: normal;
  vertical-align: middle;
  text-align: right;
  padding-left: 0.5rem;
  padding-right: 0.75rem;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.row-actions form {
  display: inline-flex;
  margin: 0;
}

.system-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin: 1.25rem 0;
  padding: 1rem;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.control-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* Search */
.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch;
  margin: 1rem 0 1.25rem;
}

.search-form input[type="search"],
.search-form input[type="text"] {
  flex: 1 1 220px;
  min-width: 0;
  min-height: 44px;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
}

.search-form input:focus {
  outline: 2px solid rgba(45, 138, 110, 0.35);
  border-color: var(--color-primary);
}

/* Tables — desktop */
.table-scroll {
  margin: 1rem 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  table-layout: fixed;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  text-align: left;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid #eef2f6;
  vertical-align: top;
  word-break: break-word;
}

.col-location,
.col-filename {
  width: auto;
}

.col-date {
  width: 8.75rem;
  white-space: nowrap;
  word-break: normal;
}

.col-datetime {
  width: 11.25rem;
  white-space: nowrap;
  word-break: normal;
}

th.col-date,
th.col-datetime {
  white-space: normal;
}

th {
  background: #f1f5f9;
  color: var(--color-text);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tr:nth-child(even) td {
  background: #fafbfc;
}

tr:hover td {
  background: #f1f5f9;
}

tr.is-expanded td,
tr.is-expanded:nth-child(even) td {
  background: #f4faf7;
}

tr.is-expanded:hover td {
  background: #eef7f3;
}

td a {
  font-weight: 600;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin: 1rem 0;
}

.pagination a,
.pagination span.disabled {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  text-decoration: none;
}

.pagination a {
  background: #fff;
  color: var(--color-accent);
}

.pagination a:hover {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

.pagination span.disabled {
  background: #f1f5f9;
  color: #94a3b8;
}

/* Status & banners */
.message,
.message.success {
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radius-sm);
  background: #e8f5f0;
  border: 1px solid #b8e0d0;
  color: #1e5c47;
}

.message.error {
  background: #fdecea;
  border-color: #f5c2c0;
  color: #842029;
}

.gmail-pipeline-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 1rem;
  padding: 0.85rem 1rem;
  background: linear-gradient(90deg, #e8f4fd, #e8fdf0);
  border: 1px solid #b8daff;
  border-radius: var(--radius-sm);
  color: #1a5276;
  font-size: 0.95rem;
}

.gmail-pipeline-spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(52, 152, 219, 0.25);
  border-top-color: #3498db;
  border-radius: 50%;
  animation: gmail-pl-spin 0.85s linear infinite;
  flex-shrink: 0;
}

@keyframes gmail-pl-spin {
  to { transform: rotate(360deg); }
}

.health-panel {
  margin: 0 0 1.25rem;
  padding: 1rem 1.1rem 1.15rem;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.health-panel__header h2 {
  margin: 0 0 0.85rem;
  padding: 0;
  border: none;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.health-panel__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.health-item {
  background: #fff;
  border: 1px solid var(--color-border);
  border-left-width: 3px;
  border-left-color: #94a3b8;
  border-radius: var(--radius-sm);
  padding: 0.85rem 0.95rem;
  min-width: 0;
}

.health-item--ok { border-left-color: #27ae60; }
.health-item--warn { border-left-color: #f39c12; }
.health-item--error { border-left-color: #e74c3c; }
.health-item--neutral { border-left-color: #94a3b8; }

.health-item__label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: 0.4rem;
}

.health-item__value {
  font-size: 1.05rem;
  font-weight: 650;
  color: var(--color-text);
  line-height: 1.3;
}

.health-item__value-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.health-item__location {
  min-width: 0;
  overflow-wrap: anywhere;
}

.health-item__meta {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  line-height: 1.45;
}

.health-item__meta a {
  font-weight: 600;
}

.health-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.health-badge--ok { background: #d4edda; color: #155724; }
.health-badge--warn { background: #fff3cd; color: #7d6608; }
.health-badge--error { background: #f8d7da; color: #721c24; }
.health-badge--neutral { background: #e2e8f0; color: #475569; }

.health-download {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  background: #e8f5f0;
  color: var(--color-primary);
  font-size: 0.75rem;
  font-weight: 700;
  text-decoration: none;
  flex-shrink: 0;
}

.health-download:hover {
  background: #d5efe6;
  color: var(--color-primary-hover);
}

.health-download svg {
  width: 14px;
  height: 14px;
}

time.timeago {
  cursor: help;
  border-bottom: 1px dotted currentColor;
}

/* Settings & forms */
.settings-section {
  margin-bottom: 1.5rem;
  padding: 1.25rem;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.settings-section h2 {
  margin-top: 0;
  border-bottom-color: var(--color-primary);
  font-size: 1.15rem;
}

.form-group {
  margin: 1rem 0;
}

label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
  color: var(--color-text);
}

input[type="text"],
input[type="password"],
input[type="search"],
textarea,
select {
  width: 100%;
  max-width: 32rem;
  min-height: 44px;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
}

.checkbox-group {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin: 0.75rem 0;
}

.checkbox-group input {
  width: 1.1rem;
  height: 1.1rem;
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.help-text,
.token-help {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.login-panel {
  text-align: center;
  padding: 2rem 1rem;
}

.login-panel .button {
  margin-top: 0.5rem;
}

.info {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-top: 1.5rem;
}

/* Modal (settings API key dialog) */
.modal {
  display: none;
  position: fixed;
  z-index: 1100;
  inset: 0;
  overflow: auto;
  background: rgba(15, 23, 42, 0.45);
  padding: 1rem;
}

.modal-content {
  background: #fff;
  margin: 10vh auto 0;
  padding: 1.5rem;
  width: min(100%, 32rem);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.modal .close {
  float: right;
  font-size: 1.5rem;
  line-height: 1;
  color: #94a3b8;
  cursor: pointer;
  border: none;
  background: none;
}

.modal .close:hover {
  color: var(--color-text);
}

.api-key-status {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.api-key-status.configured {
  background: #d4edda;
  color: #155724;
}

.api-key-status.not-configured {
  background: #f8d7da;
  color: #721c24;
}

/* Species images */
.species-images .stats {
  background: #e8f4f8;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  text-align: center;
  font-size: 0.95rem;
  color: var(--color-text);
}

.species-images-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.species-images-toolbar .search-form {
  margin: 0;
  width: 100%;
}

.species-images-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.species-images-actions .button {
  flex: 1 1 calc(50% - 0.25rem);
  margin: 0;
  min-width: 0;
}

.species-images-actions .button--wide {
  flex: 1 1 100%;
}

.species-images .images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.species-images .image-card {
  display: flex;
  flex-direction: column;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  text-align: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.species-images .image-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.species-images .image-card img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 0.5rem;
  cursor: pointer;
}

.species-images .image-card .species-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-text);
  margin-bottom: 0.25rem;
  word-break: break-word;
  line-height: 1.3;
}

.species-images .image-card .image-info {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  line-height: 1.4;
}

.species-images .image-card .delete-button {
  margin-top: 0.5rem;
  align-self: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0.5rem;
  background: transparent;
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1rem;
  box-shadow: none;
}

.species-images .image-card .delete-button:hover {
  background: var(--color-danger);
  color: #fff;
}

.species-images .image-card--selectable {
  cursor: pointer;
  border: 2px solid transparent;
}

.species-images .image-card--selectable:hover {
  border-color: var(--color-accent);
}

.species-images .image-card.selected,
.species-images .image-card--selected {
  border-color: var(--color-primary);
  background: #e8f5f0;
}

.species-images .instructions {
  background: #e8f4f8;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  text-align: center;
  font-size: 0.9rem;
  line-height: 1.5;
}

.species-images .replacement-search {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch;
  margin-bottom: 1rem;
}

.species-images .replacement-search input {
  flex: 1 1 220px;
  min-width: 0;
  max-width: none;
}

.species-images .select-button {
  display: block;
  width: 100%;
  max-width: 20rem;
  margin: 1rem auto 0;
}

.species-images .back-link {
  display: inline-flex;
  align-items: center;
  margin-bottom: 1rem;
  font-weight: 600;
}

/* Lightbox */
.species-images .lightbox {
  display: none;
  position: fixed;
  z-index: 1200;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  cursor: pointer;
}

.species-images .lightbox-content {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem 4rem;
}

.species-images .lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.species-images .lightbox-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  color: #fff;
  font-size: 2.25rem;
  line-height: 1;
  cursor: pointer;
  z-index: 1201;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.species-images .lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.65rem 0.85rem;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  user-select: none;
  z-index: 1201;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.species-images .lightbox-prev {
  left: 0.5rem;
}

.species-images .lightbox-next {
  right: 0.5rem;
}

.species-images .lightbox-info {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  text-align: center;
  background: rgba(0, 0, 0, 0.7);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  max-width: calc(100% - 2rem);
  line-height: 1.4;
}

/* Gmail settings */
.gmail-settings .hint-muted {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin: 0.5rem 0 0;
  line-height: 1.5;
}

.gmail-settings .detail-list {
  margin: 0;
  padding-left: 1.25rem;
}

.gmail-settings .action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.gmail-settings .action-buttons .button,
.gmail-settings .action-buttons a.button {
  margin: 0;
}

.gmail-settings .action-buttons form {
  margin: 0;
  flex: 1 1 auto;
}

.gmail-settings .debug-box {
  background: #2c3e50;
  color: #ecf0f1;
  padding: 1rem;
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
  overflow-x: auto;
  margin-top: 0.75rem;
  -webkit-overflow-scrolling: touch;
}

.gmail-settings .debug-box pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.gmail-settings .progress-wrap {
  display: none;
  margin: 1rem 0 0;
  max-width: 32rem;
}

.gmail-settings .progress-wrap.active {
  display: block;
}

.gmail-settings .progress-track {
  height: 14px;
  background: #e9ecef;
  border-radius: 7px;
  overflow: hidden;
  margin-top: 0.5rem;
}

.gmail-settings .progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3498db, #2ecc71);
  border-radius: 7px;
  transition: width 0.25s ease;
}

.gmail-settings .gmail-check-status {
  font-size: 0.875rem;
  color: var(--color-text);
  margin-top: 0.65rem;
  min-height: 1.4em;
  word-break: break-word;
}

.gmail-settings .diag-checks {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  max-width: 56rem;
}

.gmail-settings .diag-checks li {
  margin-bottom: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: #fff;
}

.gmail-settings .diag-checks li.diag-ok {
  border-left: 4px solid #28a745;
}

.gmail-settings .diag-checks li.diag-fail {
  border-left: 4px solid #dc3545;
  background: #fff5f5;
}

.gmail-settings .diag-checks .diag-key {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-weight: normal;
}

.gmail-settings .renewal-overall {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-weight: 600;
  font-size: 1rem;
}

.gmail-settings .renewal-overall.ok {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.gmail-settings .renewal-overall.warning {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeeba;
}

.gmail-settings .renewal-overall.error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.gmail-settings .gmail-check-error {
  display: none;
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
  border-radius: var(--radius-sm);
  max-width: 32rem;
}

.gmail-settings .gmail-check-error.active,
.gmail-settings .gmail-check-error[style*="block"] {
  display: block;
}

.gmail-settings .gmail-check-summary {
  display: none;
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: #d4edda;
  border: 1px solid #c3e6cb;
  border-radius: var(--radius-sm);
  color: #155724;
  max-width: 32rem;
}

.gmail-settings .gmail-check-summary.active {
  display: block;
}

.gmail-settings .diag-recommendations {
  margin-top: 1.25rem;
  font-size: 1rem;
}

.gmail-settings .diag-recommendations ul {
  margin-top: 0.5rem;
}

.gmail-settings #gmailRenewalOut,
.gmail-settings #gmailDiagnosticsOut {
  margin-top: 0.5rem;
}

.button.warning {
  background: #f39c12;
}

.button.warning:hover {
  background: #d68910;
}

.button.success {
  background: #28a745;
}

.button.success:hover {
  background: #218838;
}

button:disabled,
.button:disabled {
  background: #95a5a6 !important;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Lightroom keywords & downloads */
.lr-keywords .page-header,
.lr-downloads .page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.lr-keywords .page-header .page-title,
.lr-downloads .page-header .page-title {
  margin: 0;
}

.lr-keywords .subtitle,
.lr-downloads .subtitle {
  color: var(--color-text-muted);
  margin: 0.35rem 0 0;
  font-size: 1rem;
}

.lr-keywords .page-header-actions,
.lr-downloads .page-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.lr-keywords .section,
.lr-downloads .section {
  margin-bottom: 1.5rem;
  padding: 1.25rem 1.35rem 1.5rem;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.lr-keywords .section h2,
.lr-downloads .section h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
  border: none;
  padding: 0;
}

.lr-keywords .section-lead {
  margin-bottom: 1.15rem;
}

.lr-keywords .search-results {
  margin-top: 0.5rem;
  max-height: min(50vh, 400px);
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #fff;
}

.lr-keywords .region-item {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.lr-keywords .region-item:hover {
  background: #f1f5f9;
}

.lr-keywords .region-item:last-child {
  border-bottom: none;
}

.lr-keywords .region-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.lr-keywords .selected-regions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
  min-height: 2.5rem;
}

.lr-keywords .selected-regions-empty {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin: 0;
}

.lr-keywords .selected-region {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  background: var(--color-primary);
  color: #fff;
  border-radius: 999px;
  font-size: 0.875rem;
  max-width: 100%;
}

.lr-keywords .selected-region .remove {
  cursor: pointer;
  font-weight: 700;
  padding: 0 0.15rem;
  border: none;
  background: transparent;
  color: inherit;
  min-height: 0;
  margin: 0;
  box-shadow: none;
}

.lr-keywords .selected-region .remove:hover {
  background: transparent !important;
  color: #fff !important;
  transform: none;
}

.lr-keywords .info-box,
.lr-keywords .warning-box {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.lr-keywords .info-box {
  background: #e8f4f8;
  border-left: 4px solid var(--color-accent);
}

.lr-keywords .warning-box {
  background: #fff8e6;
  border-left: 4px solid #f39c12;
}

.lr-keywords .generate-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.lr-keywords #generate_btn {
  width: auto;
  max-width: 100%;
  margin: 0;
}

.lr-keywords #region_search {
  max-width: none;
}

.lr-keywords #loading {
  display: none;
  text-align: center;
  padding: 1rem;
}

.lr-keywords #lrFeedback {
  margin-top: 1rem;
}

.lr-keywords .spinner {
  border: 4px solid #f3f3f3;
  border-top: 4px solid var(--color-accent);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: gmail-pl-spin 0.85s linear infinite;
  margin: 0 auto;
}

.lr-downloads .back-link {
  display: inline-flex;
  align-items: center;
  margin-bottom: 1rem;
  font-weight: 600;
}

.lr-downloads .empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  background: #f8fafc;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
}

.lr-downloads .empty-state h2 {
  border: none;
  margin-top: 0;
}

.lr-downloads .delete-btn {
  min-height: 40px;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  background: var(--color-danger);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

@media (max-width: 900px) {
  .health-panel__grid {
    grid-template-columns: 1fr;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }

  .container--card {
    margin: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .header {
    margin: -1rem -1rem 1rem;
    padding: 0.5rem 1rem;
  }

  .nav-menu-toggle {
    display: inline-flex;
  }

  .main-nav {
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    padding: 0.15rem 0 0.5rem;
    order: 3;
  }

  .header.nav-open .main-nav {
    display: flex;
  }

  .main-nav .nav-link {
    justify-content: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
  }

  .system-controls,
  .control-group {
    flex-direction: column;
    align-items: stretch;
  }

  .system-controls .button,
  .control-group .button {
    width: 100%;
    margin-right: 0;
  }

  .search-form .button {
    width: 100%;
  }

  /* Stack tables as labeled cards instead of horizontal scroll */
  .table-scroll {
    overflow: visible;
    border: none;
    box-shadow: none;
    margin: 0.75rem 0;
  }

  table.data-table {
    min-width: 0;
    table-layout: auto;
  }

  .col-date,
  .col-datetime,
  th.col-actions,
  td.col-actions {
    width: auto;
    white-space: normal;
    text-align: left;
  }

  table.data-table thead {
    display: none;
  }

  table.data-table tbody {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  table.data-table tbody tr {
    display: block;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 0.85rem;
    box-shadow: var(--shadow-sm);
  }

  table.data-table tbody tr td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.45rem 0;
    border: none;
    background: transparent !important;
    font-size: 0.9rem;
  }

  table.data-table tbody tr td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-muted);
    flex: 0 0 38%;
    max-width: 42%;
  }

  table.data-table tbody tr td:last-child {
    padding-top: 0.65rem;
    margin-top: 0.25rem;
    border-top: 1px solid var(--color-border);
  }

  table.data-table tbody tr td.col-actions {
    justify-content: flex-end;
  }

  table.data-table tbody tr td.col-actions::before {
    content: none;
    display: none;
  }

  .location-cell {
    flex: 1 1 auto;
    min-width: 0;
  }

  table.data-table tbody tr.is-expanded td:first-child {
    flex-wrap: wrap;
  }

  table.data-table tbody tr.is-expanded td:first-child .filename-detail {
    flex-basis: 100%;
  }

  .lr-keywords .page-header,
  .lr-downloads .page-header {
    flex-direction: column;
  }

  .lr-keywords .page-header-actions .button,
  .lr-downloads .page-header-actions .button {
    width: 100%;
  }

  .lr-keywords .region-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .species-images .images-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .species-images-actions .button {
    flex: 1 1 100%;
  }

  .species-images .lightbox-content {
    padding: 2.5rem 0.25rem 3.5rem;
  }

  .gmail-settings .action-buttons {
    flex-direction: column;
    align-items: stretch;
  }

  .gmail-settings .action-buttons .button,
  .gmail-settings .action-buttons a.button,
  .gmail-settings .action-buttons form .button {
    width: 100%;
  }

  .gmail-settings .progress-wrap,
  .gmail-settings .gmail-check-error,
  .gmail-settings .gmail-check-summary,
  .gmail-settings .diag-checks {
    max-width: none;
  }

  .gmail-settings .debug-box {
    font-size: 0.7rem;
    padding: 0.75rem;
  }
}

@media (min-width: 769px) {
  table.data-table {
    min-width: 0;
  }

  .table-scroll {
    overflow-x: auto;
  }
  .container--card {
    padding: 1.5rem 2rem 2.5rem;
  }
}
