/* Smart Drop Locker - Locker Hardware Console
 * Dark & Light themes with WCAG AA verified contrast, zero blur/glow slop.
 */

:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11100d;
  --surface: #181612;
  --surface-raised: #221f19;
  --border: #332f28;
  --border-strong: #756e63;
  --text: #f5f3ee;
  --text-muted: #b5aea2;
  --accent: #d89a2a;
  --accent-hover: #e2aa43;
  --accent-ink: #d89a2a;
  --accent-text: #11100d;
  --ok: #4ade80;
  --ok-bg: #14261c;
  --ok-border: #255c39;
  --danger: #f87171;
  --danger-bg: #2a1517;
  --danger-border: #6e282d;
  --radius-panel: 6px;
  --radius-control: 4px;
  --ease-spring: cubic-bezier(0.34, 1.45, 0.64, 1);
  --ease-emphasized: cubic-bezier(0.2, 0, 0, 1);
  --font-sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-raised: #ede8df;
  --border: #d9d2c5;
  --border-strong: #7d766b;
  --text: #14120e;
  --text-muted: #575148;
  --accent: #d89a2a;
  --accent-hover: #c68b22;
  --accent-ink: #8a5e0f;
  --accent-text: #14120e;
  --ok: #15803d;
  --ok-bg: #ecfdf3;
  --ok-border: #86efac;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --danger-border: #fca5a5;
}

/* Base layer & interactive pointer affordance (R-39) */
html {
  font-size: 16px;
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: clip;
}

a[href],
button,
summary,
select,
label[for],
label:has(> input[type="checkbox"], > input[type="radio"]),
[role="button"],
[role="link"],
[role="tab"],
input[type="checkbox"],
input[type="radio"],
input[type="file"],
input[type="submit"],
input[type="button"],
input[type="reset"] {
  cursor: pointer;
}

:disabled,
[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.65;
}

/* Keyboard focus ring (R-32) */
:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  top: -48px;
  left: 16px;
  z-index: 1050;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius-control);
}

.skip-link:focus {
  top: 12px;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Header & Navigation */
.console-header {
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding-top: 10px;
  padding-bottom: 10px;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  min-height: 44px;
  padding: 4px 2px;
}

.brand-link:hover {
  color: var(--text);
}

.brand-mark {
  width: 34px;
  height: 34px;
  padding: 0;
  background: transparent;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-mark img {
  display: block;
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-name {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.desktop-nav {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-item-link {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.92rem;
  white-space: nowrap;
  transition: background-color 0.2s var(--ease-emphasized),
              color 0.2s var(--ease-emphasized),
              border-color 0.2s var(--ease-emphasized),
              border-radius 0.22s var(--ease-spring),
              transform 0.18s var(--ease-spring);
}

.nav-item-link:hover {
  color: var(--text);
  background-color: var(--surface-raised);
  border-color: var(--border);
}

.nav-item-link:active {
  transform: scale(0.96);
  border-radius: 10px;
}

.nav-item-link.active {
  color: var(--text);
  background-color: var(--surface-raised);
  border-color: var(--border-strong);
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.theme-toggle-btn {
  white-space: nowrap;
  flex-shrink: 0;
}

.theme-toggle-text {
  display: inline;
  white-space: nowrap;
}

.mobile-drawer {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  border-top: 0 solid var(--border);
  background-color: var(--surface);
  transition: grid-template-rows 0.22s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.18s ease,
              padding 0.22s ease;
}

.mobile-drawer > .container-xl {
  overflow: hidden;
}

.mobile-drawer.is-open {
  grid-template-rows: 1fr;
  opacity: 1;
  border-top-width: 1px;
  padding: 12px 0 16px;
}

.mobile-drawer-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Soft Navigation Progress & Page Transition (R-19 MOTION 2) */
.nav-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: var(--accent);
  transform-origin: left center;
  transform: scaleX(0);
  opacity: 0;
  z-index: 1080;
  pointer-events: none;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.16s ease;
}

.nav-progress-bar.is-loading {
  opacity: 1;
  transform: scaleX(0.72);
}

.nav-progress-bar.is-done {
  opacity: 1;
  transform: scaleX(1);
}

@keyframes pageEnterFade {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.992);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes pageEnterForward {
  from {
    opacity: 0;
    transform: translateX(18px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pageEnterBack {
  from {
    opacity: 0;
    transform: translateX(-18px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes m3ItemReveal {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes m3RippleAnim {
  from {
    transform: translate(-50%, -50%) scale(0);
    opacity: 0.35;
  }
  to {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0;
  }
}

@keyframes iconSpinPop {
  0% {
    transform: rotate(-90deg) scale(0.75);
  }
  100% {
    transform: rotate(0deg) scale(1);
  }
}

.console-main {
  flex: 1 0 auto;
  padding-top: 24px;
  padding-bottom: 40px;
  view-transition-name: main-content;
}

.console-main.is-entering[data-nav-dir="forward"] {
  animation: pageEnterForward 0.28s var(--ease-emphasized) both;
}

.console-main.is-entering[data-nav-dir="back"] {
  animation: pageEnterBack 0.28s var(--ease-emphasized) both;
}

.console-main.is-entering:not([data-nav-dir="forward"]):not([data-nav-dir="back"]) {
  animation: pageEnterFade 0.24s var(--ease-emphasized) both;
}

.console-main.is-entering .m3-stagger {
  animation: m3ItemReveal 0.32s var(--ease-spring) both;
  animation-delay: calc(var(--stagger, 0) * 28ms);
}

.console-main.is-fetching {
  opacity: 0.68;
  transition: opacity 0.14s var(--ease-emphasized);
}

.m3-ripple {
  position: absolute;
  border-radius: 50%;
  background-color: currentColor;
  pointer-events: none;
  animation: m3RippleAnim 0.52s var(--ease-emphasized) forwards;
}

.theme-icon-pop {
  animation: iconSpinPop 0.36s var(--ease-spring);
}

::view-transition-old(main-content) {
  animation: 0.14s ease-out both fadeOutView;
}

::view-transition-new(main-content) {
  animation: 0.26s var(--ease-emphasized) both pageEnterFade;
}

html[data-nav-dir="forward"]::view-transition-new(main-content) {
  animation: 0.28s var(--ease-emphasized) both pageEnterForward;
}

html[data-nav-dir="back"]::view-transition-new(main-content) {
  animation: 0.28s var(--ease-emphasized) both pageEnterBack;
}

@keyframes fadeOutView {
  to {
    opacity: 0;
    transform: scale(0.99);
  }
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-title {
  margin: 0;
  font-size: clamp(1.35rem, 1.15rem + 0.9vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.page-subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Panels (no blur, no float shadows) */
.console-panel {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  padding: 20px;
}

.console-panel-focal {
  border-top: 3px solid var(--accent);
}

.panel-heading {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

/* Asymmetric Dashboard Top Grid */
.dashboard-top-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.door-state-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 16px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border);
  background-color: var(--bg);
  margin: 14px 0 16px;
}

.door-state-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.door-state-value {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.door-state-value.is-open {
  color: var(--ok);
}

.door-state-value.is-closed {
  color: var(--text);
}

.telemetry-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}

.telemetry-row {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 1;
}

.telemetry-label {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.telemetry-number {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.45rem, 1.2rem + 0.8vw, 1.85rem);
  font-weight: 700;
  line-height: 1.15;
}

.telemetry-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Buttons (min 44px touch target, crisp contrast, M3 tactile morph + ripple) */
.btn-console {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: var(--radius-control);
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background-color 0.2s var(--ease-emphasized),
              border-color 0.2s var(--ease-emphasized),
              color 0.2s var(--ease-emphasized),
              border-radius 0.26s var(--ease-spring),
              transform 0.22s var(--ease-spring);
}

.btn-console:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn-console:active:not(:disabled) {
  transform: scale(0.96);
  border-radius: 12px;
}

.menu-toggle-btn {
  display: none;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.55rem;
  line-height: 1;
}

.menu-toggle-btn:hover {
  background-color: var(--surface-raised);
  color: var(--text);
}

.btn-console-sm {
  min-height: 40px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-console-primary {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn-console-primary:hover,
.btn-console-primary:active {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-text);
}

.btn-console-secondary {
  background-color: var(--surface-raised);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-console-secondary:hover,
.btn-console-secondary:active {
  background-color: var(--bg);
  border-color: var(--text-muted);
  color: var(--text);
}

.btn-console-danger {
  background-color: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.btn-console-danger:hover,
.btn-console-danger:active {
  background-color: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

/* Status Chips (text + icon, never color-only, no glow) */
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-control);
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-chip-ok {
  background-color: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok);
}

.status-chip-danger {
  background-color: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.status-chip-neutral {
  background-color: var(--surface-raised);
  border-color: var(--border-strong);
  color: var(--text-muted);
}

/* Forms */
.console-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.console-input,
.console-select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  background-color: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  font-size: 0.95rem;
}

.console-input::placeholder {
  color: var(--text-muted);
  opacity: 0.85;
}

.console-input:disabled {
  background-color: var(--surface-raised);
  color: var(--text-muted);
}

/* Tables */
.console-table {
  width: 100%;
  border-collapse: collapse;
  color: var(--text);
}

.console-table th {
  text-align: left;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.console-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 0.92rem;
}

.console-table tbody tr:last-child td {
  border-bottom: none;
}

.console-table tbody tr:hover {
  background-color: var(--surface-raised);
}

.resi-code {
  font-family: var(--font-mono);
  font-weight: 600;
  word-break: break-word;
}

.thumb-btn {
  position: relative;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--bg);
  display: inline-flex;
  overflow: hidden;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  transition: border-color 0.18s var(--ease-emphasized), transform 0.22s var(--ease-spring);
}

.thumb-btn:hover {
  border-color: var(--accent);
  transform: scale(1.04);
}

.thumb-btn:active {
  transform: scale(0.95);
}

.thumb-img {
  display: block;
  object-fit: cover;
}

/* Alerts & Feedback */
.console-alert {
  padding: 12px 16px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border);
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.console-alert-ok {
  background-color: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok);
}

.console-alert-danger {
  background-color: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.console-alert a {
  color: inherit;
  font-weight: 700;
}

.empty-state {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state-title {
  color: var(--text);
  font-weight: 600;
  margin-bottom: 4px;
}

/* Scan Preview Box */
.scan-preview-box {
  margin-top: 8px;
  padding: 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-control);
  background-color: var(--bg);
  text-align: center;
}

.scan-preview-img {
  max-width: 100%;
  max-height: 280px;
  height: auto;
  border-radius: var(--radius-control);
}

/* Modal theming & M3 spring dialog entrance */
.modal.fade .modal-dialog {
  transform: scale(0.92) translateY(10px);
  transition: transform 0.28s var(--ease-spring), opacity 0.2s var(--ease-emphasized);
}

.modal.show .modal-dialog {
  transform: scale(1) translateY(0);
}

.console-modal {
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-panel);
}

.console-modal .modal-header,
.console-modal .modal-footer {
  border-color: var(--border);
}

[data-theme="dark"] .btn-close-themed {
  filter: invert(1) grayscale(100%) brightness(200%);
}

/* Live Toast Feedback */
.console-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1090;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border-strong);
  background-color: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(16px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.22s var(--ease-emphasized), transform 0.32s var(--ease-spring);
}

.console-toast.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Footer */
.console-footer {
  border-top: 1px solid var(--border);
  background-color: var(--surface);
  padding: 14px 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

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

.inline-link {
  color: var(--accent-ink);
  font-weight: 600;
  text-decoration: none;
}

.inline-link:hover {
  text-decoration: underline;
}

/* Responsive Breakpoints: 3 states (Desktop > 960px, Tablet 640-960px, Mobile < 640px) */
@media (max-width: 960px) {
  .desktop-nav {
    display: none;
  }

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

  .dashboard-top-grid {
    grid-template-columns: 1fr;
  }

  .telemetry-stack {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
}

@media (max-width: 639.98px) {
  .header-inner {
    gap: 8px;
  }

  .brand-link {
    min-width: 0;
    gap: 8px;
  }

  .brand-text {
    min-width: 0;
  }

  .brand-name {
    font-size: 0.94rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand-sub {
    font-size: 0.72rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .theme-prefix {
    display: none;
  }

  .theme-toggle-btn {
    min-height: 40px;
    padding: 6px 12px;
    font-size: 0.84rem;
  }

  .console-main {
    padding-top: 16px;
    padding-bottom: 28px;
  }

  .console-panel {
    padding: 16px;
  }

  .telemetry-stack {
    grid-template-columns: 1fr;
  }

  .header-quick-add {
    display: none;
  }

  .btn-console-sm {
    min-height: 44px;
    padding: 8px 12px;
  }

  .console-table th,
  .console-table td {
    padding: 10px 8px;
  }
}

@media (max-width: 399.98px) {
  .brand-sub {
    display: none;
  }
}

/* Respect reduced motion (R-39) */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
