:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-strong: #eef3fb;
  --text: #172033;
  --muted: #5d6b82;
  --border: #d8e0ed;
  --primary: #174ea6;
  --primary-dark: #0f3d82;
  --accent: #fbbc04;
  --danger: #b42318;
  --ok: #0f7b58;
  --shadow: 0 10px 24px rgba(23, 32, 51, 0.08);
  --control-height: 38px;
  --control-x: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  min-height: var(--control-height);
  border: 0;
  border-radius: 8px;
  padding: 0 var(--control-x);
  color: #fff;
  background: var(--primary);
  font-weight: 700;
  line-height: 1.15;
  touch-action: manipulation;
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  color: var(--primary);
  background: #e7eef9;
}

button.warning {
  color: #221800;
  background: var(--accent);
}

button.danger {
  background: var(--danger);
}

button.ghost {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
}

button.show-controls {
  color: #fff;
  background: var(--ok);
  border-color: var(--ok);
}

button.small {
  min-height: var(--control-height);
  padding: 0 var(--control-x);
  font-size: 14px;
}

button:disabled {
  opacity: 0.55;
}

input,
select {
  width: 100%;
  min-height: var(--control-height);
  height: var(--control-height);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  padding: 0 var(--control-x);
}

textarea {
  width: 100%;
  min-height: 84px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  padding: 8px var(--control-x);
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(100%, 420px);
  display: grid;
  gap: 18px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-panel h1,
.auth-panel p {
  margin: 0;
}

.auth-panel h1 {
  margin-top: 4px;
  font-size: 24px;
  line-height: 1.15;
}

.auth-panel p {
  color: var(--muted);
  line-height: 1.5;
}

.auth-panel button {
  width: 100%;
}

.eyebrow {
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 14px 12px;
  background: rgba(246, 248, 251, 0.96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  text-align: center;
}

.topbar-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
  min-width: 0;
}

.topbar-actions button {
  min-width: 0;
  padding: 0 10px;
}

.auth-chip {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.page {
  display: grid;
  gap: 14px;
  padding: 14px;
  padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
}

.home-console {
  height: calc(100vh - 58px);
  min-height: 0;
  grid-template-rows: auto auto auto auto 1fr;
  gap: 8px;
  overflow: hidden;
  padding: 10px;
  padding-bottom: calc(env(safe-area-inset-bottom) + 10px);
}

.home-console.controls-hidden {
  grid-template-rows: auto auto auto 1fr;
}

.home-console.controls-hidden .optional-controls {
  display: none;
}

.folded-strip {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 0 10px;
  border: 1px dashed #9fb3ce;
  color: var(--primary-dark);
  background: #eaf2ff;
  font-size: 12px;
  font-weight: 800;
}

.folded-strip span {
  height: 1px;
  background: repeating-linear-gradient(90deg, #9fb3ce 0 6px, transparent 6px 10px);
}

.quick-panel {
  display: grid;
  gap: 8px;
}

.compact-row {
  display: grid;
  grid-template-columns: minmax(82px, auto) minmax(0, 1fr) 64px;
  gap: 6px;
  align-items: center;
}

.compact-row label {
  display: block;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.compact-row input {
  min-width: 0;
  min-height: var(--control-height);
  height: var(--control-height);
  padding: 0 var(--control-x);
}

.compact-row input:disabled {
  background: #e8edf5;
  color: var(--muted);
  opacity: 1;
}

.quick-actions {
  display: grid;
  gap: 8px;
}

.quick-actions.two {
  grid-template-columns: 1fr 1fr;
}

.rule {
  height: 1px;
  background: var(--border);
}

.list-space {
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.65);
  padding: 8px;
}

.list-stack {
  display: grid;
  gap: 8px;
}

.compact-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 8px;
}

.compact-card.open {
  align-items: start;
}

.compact-card .mini-media {
  width: 58px;
  min-height: 50px;
}

.compact-card:has(.mini-media) {
  grid-template-columns: 58px minmax(0, 1fr) auto;
}

.compact-body {
  display: grid;
  min-width: 0;
  gap: 3px;
  font-size: 13px;
}

.compact-body strong,
.compact-body span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-photo {
  width: 58px;
  height: 50px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.compact-form {
  box-shadow: none;
}

.inline-edit-form {
  border: 0;
  border-radius: 0;
  padding: 8px 0 0;
  background: transparent;
  box-shadow: none;
}

.compact-detail {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.brand {
  padding: 20px 0 8px;
}

.brand h2 {
  margin: 0;
  font-size: 30px;
  line-height: 1.05;
}

.brand p,
.hint,
.meta {
  color: var(--muted);
}

.brand p {
  margin: 8px 0 0;
}

.panel,
.asset-card,
.record-card,
.preset-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.button-stack {
  display: grid;
  gap: 12px;
}

.toolbar {
  display: grid;
  gap: 10px;
}

.inline {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.asset-list,
.record-list,
.preset-list,
.search-results {
  display: grid;
  gap: 10px;
}

.asset-card,
.record-card,
.preset-card {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.asset-main {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.asset-title {
  margin: 0;
  font-size: 17px;
}

.asset-id {
  color: var(--primary);
  font-weight: 800;
}

.badge {
  align-self: start;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--primary-dark);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.thumbs {
  display: flex;
  gap: 8px;
  min-height: 56px;
  overflow-x: auto;
}

.thumb {
  width: 64px;
  height: 56px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-strong);
}

.empty {
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  padding: 14px;
  background: rgba(12, 19, 33, 0.48);
}

.modal {
  width: min(100%, 720px);
  max-height: 88vh;
  overflow: auto;
  border-radius: 12px 12px 8px 8px;
  background: var(--surface);
  box-shadow: 0 22px 60px rgba(12, 19, 33, 0.28);
}

.modal-header {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.modal-body {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.preview-image {
  width: 100%;
  max-height: 75vh;
  object-fit: contain;
  border-radius: 8px;
  background: #111827;
}

#qr-reader {
  width: 100%;
  min-height: 280px;
}

.status {
  border-radius: 8px;
  padding: 10px 12px;
  background: #ecfdf3;
  color: var(--ok);
  font-weight: 700;
}

.error {
  background: #fef3f2;
  color: var(--danger);
}

.check-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.check-row input {
  width: 22px;
  min-height: 22px;
  height: 22px;
  margin-top: 2px;
}

@media (min-width: 660px) {
  .page {
    padding: 20px;
  }

  .toolbar {
    grid-template-columns: 1fr auto auto;
    align-items: end;
  }

  .form-grid {
    grid-template-columns: 1fr 1fr;
  }

  .form-grid .wide {
    grid-column: 1 / -1;
  }
}
