:root {
  color-scheme: light;
  --ink: #252823;
  --muted: #73776e;
  --line: #dcded7;
  --paper: #f3f3ee;
  --card: #fbfcf9;
  --accent: #344031;
  --accent-soft: #dfe6d8;
  --dark: #20241f;
  --radius: 10px;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 80% -10%, rgba(130, 151, 121, .16), transparent 35%),
    var(--paper);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, a { -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; }

.site-header {
  height: 76px;
  padding: 0 clamp(22px, 5vw, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--dark);
  color: #f5f7f1;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: block;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
}

.brand strong { display: block; letter-spacing: .08em; font-size: 16px; }
.brand small { display: block; margin-top: 4px; color: #aeb6a8; font-size: 9px; letter-spacing: .16em; }

.device-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #c7cec2;
  font-size: 13px;
}

.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #899583;
  box-shadow: 0 0 0 4px rgba(137, 149, 131, .14);
}

.device-state.online .state-dot { background: #a8c795; box-shadow: 0 0 0 4px rgba(168, 199, 149, .14); }

.header-actions { display: flex; align-items: center; gap: 18px; }
.account-link { max-width: 260px; overflow: hidden; color: #dce2d7; font-size: 12px; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.logout-button { padding: 8px 12px; color: #e9ede5; background: transparent; border: 1px solid #596156; border-radius: 5px; cursor: pointer; }
.logout-button:hover { background: rgba(255,255,255,.06); }

main { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 54px 0 60px; }

.intro, .section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.intro { margin-bottom: 38px; }

.eyebrow {
  margin: 0 0 9px;
  color: #65705f;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .19em;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font: 500 clamp(34px, 6vw, 57px)/1.05 Georgia, "Songti SC", serif; letter-spacing: -.03em; }
h2 { margin-bottom: 0; font: 500 26px/1.2 Georgia, "Songti SC", serif; }
h3 { margin-bottom: 8px; font-size: 18px; }
.description { margin-bottom: 0; color: var(--muted); line-height: 1.7; }

.refresh-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 17px;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}

.refresh-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.refresh-button.loading svg { animation: spin .7s linear infinite; }
.refresh-button:focus-visible, .latest-image-button:focus-visible, .photo-card:focus-visible { outline: 3px solid #9aad8e; outline-offset: 3px; }

.latest-panel {
  margin-bottom: 50px;
  padding: clamp(18px, 3vw, 30px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.latest-panel .section-heading { margin-bottom: 20px; }
.section-heading time, .photo-count { color: var(--muted); font-size: 13px; }

.latest-image-button {
  display: block;
  width: 100%;
  padding: 0;
  overflow: hidden;
  background: #171a16;
  border: 0;
  border-radius: 6px;
  cursor: zoom-in;
}

.latest-image-button img {
  display: block;
  width: 100%;
  max-height: 600px;
  object-fit: contain;
}

.history-section > .section-heading { padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.photo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; padding-top: 20px; }

.photo-card {
  padding: 0;
  overflow: hidden;
  color: inherit;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease;
}

.photo-card:hover { transform: translateY(-2px); border-color: #afb5aa; }
.photo-card img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #e3e4df; }
.photo-card-meta { display: flex; justify-content: space-between; gap: 10px; padding: 13px 14px; color: var(--muted); font-size: 12px; }
.photo-card-meta strong { color: var(--ink); font-size: 12px; font-weight: 600; }

.empty-state { padding: 72px 20px; text-align: center; color: var(--muted); }
.empty-icon { display: grid; width: 62px; height: 62px; margin: 0 auto 20px; place-items: center; color: #717b6b; background: var(--accent-soft); border-radius: 50%; }
.empty-icon svg { width: 28px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.empty-state p { max-width: 430px; margin: 0 auto; line-height: 1.7; }
.empty-link { display: inline-block; margin-top: 15px; }
.error-message { margin-top: 20px; padding: 14px 16px; color: #7d302b; background: #f5e5e2; border: 1px solid #e8c8c3; border-radius: 6px; }

.viewer { width: min(1000px, calc(100% - 28px)); max-height: calc(100vh - 28px); padding: 0; overflow: hidden; color: #f3f4ef; background: #161915; border: 1px solid #454c42; border-radius: 9px; }
.viewer::backdrop { background: rgba(16, 18, 15, .82); backdrop-filter: blur(4px); }
.viewer img { display: block; width: 100%; max-height: calc(100vh - 105px); object-fit: contain; }
.viewer-close { position: absolute; top: 12px; right: 12px; width: 38px; height: 38px; color: #fff; background: rgba(0,0,0,.62); border: 1px solid rgba(255,255,255,.25); border-radius: 50%; cursor: pointer; font: 300 27px/1 sans-serif; }
.viewer-meta { display: flex; justify-content: space-between; padding: 15px 18px; color: #bac1b6; font-size: 13px; }
.viewer-meta a { color: #e4eadf; }

footer { min-height: 70px; padding: 0 clamp(22px, 5vw, 72px); display: flex; align-items: center; justify-content: space-between; gap: 20px; color: #858a81; border-top: 1px solid var(--line); font-size: 12px; }

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

@media (max-width: 760px) {
  .site-header { height: 68px; }
  .brand small { display: none; }
  main { width: min(100% - 28px, 620px); padding-top: 38px; }
  .intro { align-items: center; }
  .description { max-width: 250px; }
  .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}

@media (max-width: 480px) {
  .device-state span:last-child { display: none; }
  .refresh-button { padding: 0 13px; }
  .photo-grid { grid-template-columns: 1fr; }
  .latest-panel { padding: 13px; }
  footer { align-items: flex-start; flex-direction: column; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Authentication and account pages */
.auth-body { display: grid; min-height: 100vh; place-items: center; padding: 28px; background: #e9eae4; }
.auth-shell { display: grid; width: min(980px, 100%); min-height: 610px; grid-template-columns: .95fr 1.05fr; padding: 0; overflow: hidden; background: var(--card); border: 1px solid #d3d6ce; border-radius: 14px; box-shadow: 0 25px 70px rgba(36, 40, 34, .13); }
.auth-intro { display: flex; min-height: 100%; padding: 44px; flex-direction: column; justify-content: space-between; color: #f3f5ef; background: linear-gradient(145deg, #1d211c, #343c31); }
.auth-intro .eyebrow { color: #aebba7; }
.auth-intro h1 { margin-bottom: 18px; font-size: clamp(39px, 5vw, 62px); }
.auth-intro p { max-width: 390px; color: #c5ccc0; line-height: 1.8; }
.auth-intro > small { color: #929c8d; }
.auth-card { display: flex; padding: clamp(38px, 7vw, 72px); flex-direction: column; justify-content: center; }
.auth-card h2 { margin-bottom: 34px; font-size: 31px; }
.auth-card form { display: grid; gap: 20px; }
.auth-card label { display: grid; gap: 8px; color: #555b52; font-size: 13px; font-weight: 600; }
.auth-card input { width: 100%; height: 48px; padding: 0 14px; color: var(--ink); background: #fff; border: 1px solid #cfd3ca; border-radius: 6px; outline: 0; }
.auth-card input:focus { border-color: #687663; box-shadow: 0 0 0 3px rgba(104, 118, 99, .14); }
.password-hint { color: #7d8279; font-size: 11px; font-weight: 400; line-height: 1.55; }
.code-row { display: grid; grid-template-columns: 1fr 128px; align-items: end; gap: 10px; }
.primary-button, .secondary-button, .primary-link { display: inline-grid; height: 48px; place-items: center; border-radius: 6px; cursor: pointer; text-decoration: none; }
.primary-button, .primary-link { color: #fff; background: var(--accent); border: 0; }
.secondary-button { color: var(--accent); background: #edf0e9; border: 1px solid #cbd2c5; font-size: 13px; }
.primary-button:disabled, .secondary-button:disabled { cursor: wait; opacity: .62; }
.form-message { margin: -3px 0 0; padding: 11px 12px; color: #842f2a; background: #f6e7e5; border-radius: 5px; font-size: 13px; }
.form-message[data-kind="success"] { color: #365733; background: #e6eee2; }
.auth-switch { margin: 24px 0 0; color: var(--muted); font-size: 13px; text-align: center; }
.auth-switch a, .text-link { color: #3e5239; font-weight: 600; }
.account-page, .admin-page { width: min(1120px, calc(100% - 40px)); margin: 0 auto; padding: 60px 0; }
.info-card, .table-card { padding: 28px; background: var(--card); border: 1px solid var(--line); border-radius: 9px; }
.info-card { max-width: 680px; }
.password-card { margin-top: 22px; }.password-card h2 { margin-bottom: 24px; }.password-card form { display: grid; max-width: 430px; gap: 17px; }.password-card label { display: grid; gap: 8px; color: var(--muted); font-size: 13px; }.password-card input { height: 45px; padding: 0 13px; border: 1px solid #cfd3ca; border-radius: 6px; }.password-card .primary-button { width: 170px; }
.device-card { margin-top: 22px; }
.card-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.card-heading h2 { margin: 0; }
.muted-copy { color: var(--muted); line-height: 1.7; }
.device-list { display: grid; gap: 12px; margin-bottom: 24px; }
.device-item { display: grid; grid-template-columns: minmax(180px, 1fr) 1.5fr; gap: 25px; padding: 17px; background: #f1f2ed; border: 1px solid var(--line); border-radius: 7px; }
.device-item strong, .device-item small { display: block; }.device-item small { margin-top: 6px; color: var(--muted); font-family: ui-monospace, monospace; font-size: 11px; }
.device-item dl { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin: 0; }.device-item dl > div { padding: 0; border: 0; }.device-item dt { margin-bottom: 5px; color: var(--muted); font-size: 11px; }.device-item dd { font-size: 12px; font-weight: 500; }
.inline-form { display: flex; align-items: flex-end; gap: 12px; margin-top: 20px; }
.inline-form label { display: grid; min-width: 240px; gap: 8px; color: var(--muted); font-size: 12px; }
.inline-form input { height: 44px; padding: 0 13px; background: #fff; border: 1px solid #cfd3ca; border-radius: 6px; }
.inline-form .primary-button { min-width: 140px; padding: 0 18px; }
.device-card .form-message, .admin-section .form-message { margin-top: 14px; }
.admin-section { margin-bottom: 48px; }
.create-device-form { margin: 0 0 20px; }
.credential-output { margin: 0 0 20px; padding: 17px; overflow-wrap: anywhere; color: #e9eee5; white-space: pre-wrap; background: #242923; border-radius: 7px; font: 12px/1.7 ui-monospace, monospace; }
.action-cell { display: flex; gap: 8px; }
.table-button { padding: 7px 10px; color: #344031; background: #eef1eb; border: 1px solid #cbd1c6; border-radius: 5px; cursor: pointer; font-size: 11px; }.table-button.danger { color: #7b332e; background: #f6e9e7; border-color: #e8cbc7; }.table-button:disabled { opacity: .55; }
.info-card dl { margin: 0 0 28px; }
.info-card dl > div { display: grid; grid-template-columns: 140px 1fr; padding: 17px 0; border-bottom: 1px solid var(--line); }
.info-card dt { color: var(--muted); }.info-card dd { margin: 0; font-weight: 600; }
.info-card .primary-link { width: 190px; margin-right: 18px; }.info-card .text-link { font-size: 13px; }
.admin-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.user-count { padding: 8px 12px; color: #53604f; background: var(--accent-soft); border-radius: 20px; font-size: 12px; }
.table-card { padding: 0; overflow: hidden; }.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; } th, td { padding: 17px 20px; border-bottom: 1px solid var(--line); white-space: nowrap; } th { color: var(--muted); background: #f1f2ed; font-size: 12px; } td { font-size: 13px; } tbody tr:last-child td { border-bottom: 0; }
.role-badge { display: inline-block; padding: 5px 9px; color: #566052; background: #e7e9e3; border-radius: 12px; font-size: 11px; }.role-badge.admin { color: #5f4c21; background: #eee5cb; }

@media (max-width: 760px) {
  .auth-body { padding: 0; }.auth-shell { min-height: 100vh; grid-template-columns: 1fr; border: 0; border-radius: 0; }.auth-intro { min-height: 250px; padding: 28px; }.auth-intro > small { display: none; }.auth-card { padding: 38px 28px; }
  .account-link, .device-state { display: none; }.header-actions { gap: 8px; }.info-card dl > div { grid-template-columns: 1fr; gap: 7px; }.info-card .primary-link { width: 100%; margin: 0 0 18px; }
  .device-item { grid-template-columns: 1fr; }.device-item dl { grid-template-columns: 1fr; }.inline-form { align-items: stretch; flex-direction: column; }.inline-form label, .inline-form .primary-button { width: 100%; min-width: 0; }
}
