/* Bat Sensor - hand-written stylesheet, no build step.
   Plain HTML elements are styled by selector wherever possible; the small
   set of classes below only exist for things a bare element can't express
   (status badges, cards, buttons, the media gallery grid). */

:root {
  --color-bg: #f3f4f6;
  --color-surface: #ffffff;
  --color-border: #e5e7eb;
  --color-text: #111827;
  --color-text-muted: #6b7280;
  --color-primary: #1f2937;
  --color-primary-hover: #374151;
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-success-bg: #f0fdf4;
  --color-success-border: #bbf7d0;
  --color-success-text: #166534;
  --color-green-bg: #dcfce7;
  --color-green-text: #166534;
  --color-gray-bg: #f3f4f6;
  --color-gray-text: #4b5563;
  --color-red-bg: #fee2e2;
  --color-red-text: #991b1b;
  --color-amber-bg: #fffbeb;
  --color-amber-border: #fde68a;
  --color-amber-text: #92400e;
  --radius: 0.5rem;
  --shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  font-family: var(--font-sans);
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  font-size: 15px;
}

h1, h2, h3 {
  font-weight: 600;
  line-height: 1.25;
  margin: 0;
}

h2 {
  font-size: 1.125rem;
}

p {
  margin: 0 0 0.5rem;
}

a {
  color: inherit;
}

img {
  max-width: 100%;
  display: block;
}

/* Layout */

.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.site-nav {
  max-width: 80rem;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 4rem;
}

.site-nav__group {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.site-nav__brand {
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--color-text);
}

.site-nav__links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.site-nav__link {
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
}

.site-nav__link:hover {
  color: var(--color-text);
}

.site-nav__link[aria-current="page"] {
  color: var(--color-text);
  border-bottom-color: var(--color-primary);
}

.page-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.page-header__inner {
  max-width: 80rem;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

main {
  display: block;
}

.container {
  max-width: 80rem;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.container--narrow {
  max-width: 32rem;
}

.container--medium {
  max-width: 64rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.hidden {
  display: none !important;
}

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

.header-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.inline-form-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}

.inline-form-row .field {
  margin: 0;
}

.inline-form-row label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.inline-form-row input[type="number"] {
  width: 6rem;
}

/* Cards */

.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.card > * + * {
  margin-top: 1rem;
}

.card > section + section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

/* Flash / status messages */

.flash {
  background: var(--color-success-bg);
  border: 1px solid var(--color-success-border);
  color: var(--color-success-text);
  border-radius: var(--radius);
  padding: 1rem;
  font-size: 0.9rem;
}

.flash--warning {
  background: var(--color-amber-bg);
  border-color: var(--color-amber-border);
  color: var(--color-amber-text);
}

.token-box {
  display: block;
  margin-top: 0.5rem;
  padding: 0.6rem 0.75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  word-break: break-all;
}

.flash-saved {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  animation: fade-out 0.5s ease-in 1.5s forwards;
}

@keyframes fade-out {
  to {
    opacity: 0;
  }
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.25;
}

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

.btn-primary:hover {
  background: var(--color-primary-hover);
}

.btn-secondary {
  background: var(--color-gray-bg);
  color: var(--color-text);
}

.btn-secondary:hover {
  background: #e5e7eb;
}

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

.btn-danger:hover {
  background: var(--color-danger-hover);
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--color-text-muted);
  text-decoration: underline;
  font-size: 0.875rem;
}

.btn-link--danger {
  color: var(--color-danger);
}

/* Forms */

form .field + .field {
  margin-top: 1.25rem;
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text);
  margin-bottom: 0.25rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

input[type="checkbox"] {
  width: auto;
  margin-right: 0.4rem;
}

.field-error {
  color: var(--color-danger);
  font-size: 0.8rem;
  margin: 0.35rem 0 0;
  padding: 0;
  list-style: none;
}

.field-hint {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  margin-top: 0.35rem;
}

.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  font-weight: 400;
  margin-bottom: 0;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

/* Tables */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th {
  text-align: left;
  color: var(--color-text-muted);
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
}

td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--color-border);
}

tr:last-child td {
  border-bottom: none;
}

.table-actions {
  text-align: right;
}

.table-actions form {
  display: inline;
}

.table-actions > * + * {
  margin-left: 0.75rem;
}

.table-wrap {
  overflow-x: auto;
}

/* Badges */

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-green {
  background: var(--color-green-bg);
  color: var(--color-green-text);
}

.badge-gray {
  background: var(--color-gray-bg);
  color: var(--color-gray-text);
}

.badge-red {
  background: var(--color-red-bg);
  color: var(--color-red-text);
}

/* Device list (dashboard) */

.device-list {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.device-list__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px solid var(--color-border);
}

.device-list__item:last-child {
  border-bottom: none;
}

.device-list__item:hover {
  background: #fafafa;
}

.device-list__name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.device-list__meta {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.device-list__arrow {
  color: var(--color-text-muted);
}

/* Media gallery */

.media-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.75rem;
}

.media-grid__item img,
.media-grid__item video {
  max-width: 12rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

.media-grid__label {
  color: var(--color-text-muted);
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

.detection {
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--color-border);
}

.detection:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.detection + .detection {
  margin-top: 1.5rem;
}

.detection__meta {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* Live view */

#live-view img {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

/* Details/summary based nav dropdown + mobile menu (replaces Alpine) */

.user-menu {
  position: relative;
}

.user-menu > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
}

.user-menu > summary:hover {
  color: var(--color-text);
  background: var(--color-gray-bg);
}

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

.user-menu[open] > summary {
  background: var(--color-gray-bg);
}

.user-menu__panel {
  position: absolute;
  right: 0;
  margin-top: 0.5rem;
  min-width: 12rem;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  border: 1px solid var(--color-border);
  overflow: hidden;
  z-index: 50;
}

.user-menu__panel a,
.user-menu__panel button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  color: var(--color-text);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
}

.user-menu__panel a:hover,
.user-menu__panel button:hover {
  background: var(--color-gray-bg);
}

.nav-toggle {
  display: none;
  position: relative;
}

.nav-toggle > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.5rem;
  font-size: 1.25rem;
}

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

.nav-toggle__panel {
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 12rem;
  max-width: calc(100vw - 2rem);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  padding: 0.5rem;
  z-index: 50;
}

.nav-toggle__panel a,
.nav-toggle__panel button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  color: var(--color-text);
  text-decoration: none;
  background: none;
  border: none;
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: var(--radius);
}

.nav-toggle__panel a:hover,
.nav-toggle__panel button:hover {
  background: var(--color-gray-bg);
}

@media (max-width: 640px) {
  .site-nav__links,
  .site-nav__user {
    display: none;
  }

  .nav-toggle {
    display: block;
  }
}

/* Guest (auth) layout */

.guest-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  gap: 1.5rem;
}

.guest-layout__brand {
  font-weight: 700;
  font-size: 1.25rem;
  text-decoration: none;
  color: var(--color-text);
}

.guest-layout__card {
  width: 100%;
  max-width: 24rem;
  background: var(--color-surface);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

/* Native <dialog> based modal (replaces Alpine modal) */

dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
  padding: 0;
  max-width: 28rem;
  width: calc(100% - 2rem);
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.5);
}

dialog .card {
  box-shadow: none;
}
