:root {
  color-scheme: light;
  --canvas: #f5f5f4;
  --card: #ffffff;
  --border: #eae8e4;
  --text: #1c1917;
  --muted: #78716c;
  --accent-1: #f59e0b;
  --accent-2: #f97316;
  --accent-grad: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  --online: #16a34a;
  --offline: #a8a29e;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(28, 25, 23, .06), 0 8px 24px rgba(28, 25, 23, .06);
  --shadow-lg: 0 12px 40px rgba(28, 25, 23, .18);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--canvas);
  background-image:
    radial-gradient(1200px 600px at 12% -10%, rgba(245, 158, 11, .07), transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, rgba(249, 115, 22, .05), transparent 55%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.screen { min-height: 100vh; }

/* ---------------------------------------------------------- brand */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent-grad);
  box-shadow: 0 2px 8px rgba(249, 115, 22, .35);
  position: relative;
}

/* stacked-shelf glyph inside the mark */
.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  left: 6px;
  right: 6px;
  height: 2px;
  border-radius: 1px;
  background: rgba(255, 255, 255, .9);
}
.brand-mark::before { top: 9px; box-shadow: 0 6px 0 rgba(255, 255, 255, .9); }
.brand-mark::after { top: 19px; }

.brand-name {
  font-weight: 650;
  letter-spacing: -0.02em;
  font-size: 1.05rem;
}

.brand-lg .brand-mark { width: 40px; height: 40px; border-radius: 11px; }
.brand-lg .brand-mark::before { top: 13px; left: 9px; right: 9px; box-shadow: 0 8px 0 rgba(255,255,255,.9); }
.brand-lg .brand-mark::after { top: 27px; left: 9px; right: 9px; }
.brand-lg .brand-name { font-size: 1.25rem; }

/* ---------------------------------------------------------- inputs */
input {
  width: 100%;
  background: #fafaf9;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 13px;
  border-radius: 10px;
  font-size: 1rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}

input::placeholder { color: #a8a29e; }

input:focus-visible {
  outline: none;
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, .22);
}

/* ---------------------------------------------------------- buttons */
button { font-family: inherit; cursor: pointer; }

.btn-primary {
  background: var(--accent-grad);
  color: #fff;
  border: none;
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(249, 115, 22, .3);
  transition: transform .12s ease, box-shadow .15s ease, opacity .15s ease;
}
.btn-primary:hover { box-shadow: 0 4px 16px rgba(249, 115, 22, .4); }
.btn-primary:active { transform: translateY(1px); }

.btn-ghost {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 550;
  transition: background .15s ease, border-color .15s ease;
}
.btn-ghost:hover { background: #faf9f7; border-color: #d6d3ce; }

.btn-icon {
  background: #fff;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 1.05rem;
  line-height: 1;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.btn-icon:hover { background: #faf9f7; color: var(--text); border-color: #d6d3ce; }

button:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, .3);
}

/* ---------------------------------------------------------- login */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 32px 28px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-subtitle {
  margin: -4px 0 6px;
  color: var(--muted);
  font-size: 0.92rem;
}

.error {
  color: var(--danger);
  margin: 0;
  font-size: 0.88rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  padding: 8px 11px;
  border-radius: 9px;
}

/* ---------------------------------------------------------- header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: rgba(255, 255, 255, .8);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.app-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: var(--accent-grad);
  opacity: .55;
}

.app-main { padding: 22px 20px 48px; }

/* ---------------------------------------------------------- grid */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
  max-width: 1200px;
  margin: 0 auto;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  margin-top: 64px;
  font-size: 0.95rem;
}

/* ---------------------------------------------------------- card */
.device-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease;
}
.device-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(28, 25, 23, .07), 0 16px 40px rgba(28, 25, 23, .1);
}

.viewfinder {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #f2f0ed;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
}
.viewfinder::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 1px rgba(28, 25, 23, .04);
  pointer-events: none;
}

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

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

.timestamp-overlay {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(255, 255, 255, .78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--text);
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(28, 25, 23, .12);
}
.timestamp-overlay:empty { display: none; }

.status-pill {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: capitalize;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 1px 3px rgba(28, 25, 23, .12);
}
.status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--offline);
}
.status-pill.online { color: #14532d; }
.status-pill.online::before {
  background: var(--online);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, .18);
}
.status-pill.offline { color: #57534e; }

.card-name {
  padding: 14px 15px 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-actions {
  display: flex;
  gap: 8px;
  padding: 12px 15px;
}
.card-actions .capture-btn,
.card-actions .history-btn { flex: 1; }
.wifi-btn { flex: 0 0 auto; }

.capture-status {
  margin: 0 15px 14px;
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.1em;
}

/* ---------------------------------------------------------- modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, .38);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  z-index: 10;
  overflow-y: auto;
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 440px;
  margin-top: 8vh;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 24px;
}

.modal-content h2 {
  margin: 0 0 16px;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  padding-right: 28px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 6px;
  border-radius: 8px;
  transition: background .15s ease, color .15s ease;
}
.modal-close:hover { background: #f5f5f4; color: var(--text); }

/* ---------------------------------------------------------- wifi form */
#wifi-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-label {
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--muted);
}
.form-status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.1em;
}

/* ---------------------------------------------------------- history */
.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 12px;
  max-height: 60vh;
  overflow-y: auto;
  color: var(--muted);
  font-size: 0.9rem;
}

.history-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.history-item .history-ts {
  font-size: 0.66rem;
  color: var(--muted);
  text-align: center;
  margin-top: 4px;
}

/* ---------------------------------------------------------- motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .device-card:hover { transform: none; }
}
