/* EquiiTrack dark appearance. Loaded last so it wins over legacy page CSS.
   Preserve map imagery, horse photos and alert severity colours. */
html[data-theme="dark"] {
  color-scheme: dark;
  --burgundy: #85d0aa;
  --burgundy2: #60a985;
  --gold: #c6d49e;
  --cream: #182820;
  --cream2: #1d2c24;
  --slate: #ebf3ed;
  --muted-brand: #b0c6b9;
  --brand-line: #3a5145;
  --navy: #ebf3ed;
  --teal: #96dfba;
  --teal2: #70c59c;
  --pale: #1b2b23;
  --pale2: #24372d;
  --line: #3a5145;
  --muted: #b0c6b9;
  --green: #8cdbaf;
  --red: #ff9898;
  --amber: #f3bd71;
  --dark-page: #101a15;
  --dark-panel: #1b2b23;
  --dark-raised: #263b2f;
  --dark-soft: #23372b;
  --dark-text: #ebf3ed;
  --dark-muted: #b0c6b9;
  --dark-outline: #3a5145;
}
html[data-theme="dark"] body,
html[data-theme="dark"] .app-shell { background:var(--dark-page)!important; color:var(--dark-text); }
html[data-theme="dark"] :is(.screen,.screen.auth-screen,.screen.alerts-screen,.auth-screen,.alerts-screen) {
  background:linear-gradient(160deg,#14231b,#101a15 64%,#1b2a22)!important;
  color:var(--dark-text);
}
html[data-theme="dark"] :is(h1,h2,h3,h4,h5,h6,b,strong,label,legend,th,dt) { color:inherit; }
html[data-theme="dark"] :is(p,small,.muted,.muted-note,.last-update,.eyebrow,.updated,.metrics small,.admin-intro,.settings-section-label,.desktop-nav-section) { color:var(--dark-muted); }
html[data-theme="dark"] :is(.topbar,.screen>.topbar,.desktop-sidebar,.bottom-nav,.global-bottom-nav,.settings-list,.horse-card,.boundary-card,.tracker-card,.device-hero,.map-preview,.map-location-card,.map-controls button,.map-horse-picker,.map-type-switch,.map-centre-button,.map-status-sheet,
 .card,.info-card,.warning-card,.diagnostic-card,.horse-edit-card,.alert-card,.alert-event-card,.alerts-overview,.alerts-empty,.alerts-skeleton,
 .alerts-notification-panel,.auth-card,.signin-panel,.rug-result-card,.tracker-product-card,.battery-research-grid>div,
 .desktop-quick-grid a,.plan-card,.product-grid a,.admin-kpi,.admin-table-wrap,.admin-tabs button.selected,.alert-filter-chip,
 .alert-rules-link,.alerts-rules-link,.settings-signout,.secondary,.map-picker-card,.filter,.chart,.quick-history-ranges button) {
  background:var(--dark-panel)!important;
  color:var(--dark-text);
  border-color:var(--dark-outline)!important;
}
html[data-theme="dark"] :is(.settings-profile-card,.settings-icon,.battery-impact,.shortcut-grid a,.global-back,.offline-banner,
 .alert-icon,.alert-event-icon,.alert-event-meta span,.tracker-product-icon,.tracker-assigned-photo,.settings-status,
 .admin-tabs,.segmented,.alert-event-card.is-attention,.admin-table th,.ops-status,.diag-result,.diagnostic-card code,
 .admin-tracker-detail pre,.admin-message pre,.chart,.reporting-badge,.reporting-verified,.alerts-status-icon,
 .alerts-skeleton>span,.alerts-skeleton i,.map-status-icon,.map-picker-avatar,.map-type-switch button.active) {
  background:var(--dark-soft)!important;
  color:var(--dark-text);
  border-color:var(--dark-outline)!important;
}
/* Keep destructive/warning/success statuses visually distinguishable. */
html[data-theme="dark"] :is(.warning-card,.offline-banner,.alert-card.warn .alert-icon,.diag-state.timeout,.ops-testing) {
  background:#3b301f!important; color:#ffdd9c!important; border-color:#735b37!important;
}
html[data-theme="dark"] :is(.danger-button,.alert-card.danger .alert-icon,.diag-state.error,.ops-suspended,.ops-cancelled,.ops-retired) {
  background:#3c2528!important; color:#ffa7a7!important; border-color:#80494c!important;
}
html[data-theme="dark"] :is(.diag-state.ok,.diag-state.working,.ops-active,.ops-ready,.device-hero em) {
  background:#1a4233!important; color:#a9e8c3!important; border-color:#38785d!important;
}
html[data-theme="dark"] :is(.primary,.button.primary,button.primary,.admin-add) {
  background:linear-gradient(105deg,#276746,#22563e)!important;
  color:#fff!important; border-color:#38785d!important;
}
html[data-theme="dark"] :is(.primary:hover,.button.primary:hover) { background:#317b55!important; }
html[data-theme="dark"] :is(.secondary,.global-back,.text-button,.text-link,.desktop-nav a.active,.bottom-nav a.active,.global-bottom-nav a.active) {
  color:var(--teal)!important;
}
html[data-theme="dark"] :is(.desktop-nav a,.bottom-nav a,.global-bottom-nav a,.desktop-account,.brand,.settings-list a,.settings-list a b) { color:var(--dark-text); }
html[data-theme="dark"] :is(.desktop-nav a:hover,.desktop-nav a.active,.desktop-account:hover,.bottom-nav a:hover,.global-bottom-nav a:hover) {
  background:var(--dark-raised)!important;
}
html[data-theme="dark"] :is(.desktop-sidebar,.desktop-sidebar .brand,.desktop-account,.topbar,.bottom-nav) { border-color:var(--dark-outline)!important; }
html[data-theme="dark"] :is(input,select,textarea,.search,.horse-select,dialog,.admin-dialog,.filter,.segmented button,.map-type-switch button) {
  background:var(--dark-raised)!important; color:var(--dark-text)!important; border-color:var(--dark-outline)!important;
}
html[data-theme="dark"] :is(input,select,textarea)::placeholder { color:#a8bcb0; opacity:1; }
html[data-theme="dark"] :is(input,select,textarea,button,a):focus-visible { outline:2px solid #a4e7be; outline-offset:3px; }
html[data-theme="dark"] :is(option,optgroup) { background:#203329; color:#ebf3ed; }
html[data-theme="dark"] :is(.admin-table th,.admin-table td,.admin-table-wrap th,.admin-table-wrap td,table th,table td) {
  color:var(--dark-text); border-color:var(--dark-outline)!important;
}
html[data-theme="dark"] :is(.admin-table tr:nth-child(even),table tbody tr:nth-child(even)) { background:#213329; }
html[data-theme="dark"] :is(pre,code,.admin-message,blockquote,.admin-definition-list dd,.battery-life-estimate) {
  color:var(--dark-text); border-color:var(--dark-outline);
}
html[data-theme="dark"] :is(.chart,.admin-tracker-detail pre,.admin-message pre,pre) { background:var(--dark-soft)!important; }
html[data-theme="dark"] :is(.global-back,.map-controls button,.map-centre-button,.map-type-switch) { box-shadow:0 4px 16px #060d0880; }
html[data-theme="dark"] :is(.alert-event-card,.horse-card,.tracker-card,.card,.admin-kpi) { box-shadow:0 6px 16px #050c0766; }
/* Markers stay highly visible without recolouring satellite or street-map tiles. */
html[data-theme="dark"] :is(.leaflet-container,.map-full,.history-map,.draw-map,.map-art,.alert-map) { color:inherit; }
html[data-theme="dark"] :is(.leaflet-popup-content-wrapper,.leaflet-popup-tip) { background:var(--dark-panel); color:var(--dark-text); }
html[data-theme="dark"] .leaflet-control-zoom a { background:var(--dark-raised); color:var(--dark-text); border-color:var(--dark-outline); }
html[data-theme="dark"] .leaflet-control-attribution { background:#101a15de; color:#b0c6b9; }
html[data-theme="dark"] .leaflet-control-attribution a { color:#a4e7be; }
html[data-theme="dark"] :is(.equii-map-marker small,.map-pin small,.google-horse-marker b) { background:#1b2b23; color:#ebf3ed; }
html[data-theme="dark"] :is(.auth-screen,.signin-panel,.auth-card) { box-shadow:none; }
html[data-theme="dark"] .avatar { background:#2c4936; color:#eaf4ed; }
/* Site-wide option selectors and the desktop one-tap switch. */
.appearance-options { display:flex; flex-wrap:wrap; gap:8px; margin:12px 0 4px; }
.appearance-options button {
  flex:1 1 80px; padding:11px 13px; border-radius:11px; border:1px solid var(--line);
  background:var(--cream2); color:var(--navy); font:inherit; font-weight:700; cursor:pointer;
}
.appearance-options button[aria-pressed="true"] { background:#e4f1e5; border:2px solid #2e805d; color:#225d40; }
.appearance-options button:focus-visible,.sidebar-theme-toggle:focus-visible { outline:2px solid var(--teal); outline-offset:2px; }
.appearance-note { font-size:12px; color:var(--muted); }
html[data-theme="dark"] .appearance-options button { background:#24372c; color:#eaf3ed; border-color:#456352; }
html[data-theme="dark"] .appearance-options button[aria-pressed="true"] { background:#286044; border-color:#99dcb3; color:#fff; }
.sidebar-theme-toggle {
  margin:12px 8px 0; padding:12px; border:1px solid var(--line); background:#eff4ed; color:var(--navy);
  border-radius:12px; cursor:pointer; text-align:left; font:inherit; font-weight:700; font-size:13px;
}
html[data-theme="dark"] .sidebar-theme-toggle { color:#eaf3ed; background:#24392e; border-color:#456352; }
@media (min-width:900px) {
  html[data-theme="dark"] .desktop-sidebar { background:#14241c!important; }
  html[data-theme="dark"] .screen { background:#142119!important; }
  html[data-theme="dark"] .screen>.topbar { background:#192a21!important; }
}
@media (prefers-reduced-motion:reduce) {
  .appearance-options button,.sidebar-theme-toggle { transition:none; }
}
