:root {
  --bg: #f5f5f3;
  --surface: #fff;
  --ink: #222;
  --muted: #666;
  --line: #d6d6d2;
  --accent: #1a5c4a;
  --accent-hover: #144839;
  --danger: #8a1f1f;
  --ok: #1a5c4a;
  --bad: #8a1f1f;
  --nav: #f0f0ee;
  --font: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --font-ui: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  animation: none !important;
  transition: none !important;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }
.view { min-height: 100vh; }

.login-box {
  width: min(360px, calc(100% - 1.5rem));
  margin: 8vh auto 2rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
}

.login-box h1 {
  margin: 0 0 0.25rem;
  font-size: 1.15rem;
  font-weight: 600;
}

#login-form button[type="submit"] {
  width: 100%;
  margin-top: 0.5rem;
}

label {
  display: block;
  margin: 0 0 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
}

input[type="password"],
input[type="text"],
input[type="file"] {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

input[type="file"] { padding: 0.3rem; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 0.4rem 0.7rem;
  border-radius: 0;
}

button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

button.ghost {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

button.ghost:hover { background: var(--nav); }

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

button.danger:hover { background: #f8eeee; }

button.tab {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.35rem 0.55rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

button.tab.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

button.tab:hover {
  background: transparent;
  color: var(--ink);
}

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.3rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-family: var(--font);
  line-height: 1;
}

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  font-family: var(--font-ui);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.brand strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

nav {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.1rem;
  align-items: center;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  scrollbar-width: none;
}

nav::-webkit-scrollbar {
  display: none;
}

.content {
  width: min(1100px, calc(100% - 1.5rem));
  margin: 0.85rem auto 2rem;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.brand,
.brand strong,
nav,
button,
label,
h1, h2, h3,
.model-item,
.model-item-name,
.model-detail,
.model-detail-row,
.images-heading,
.panel-head,
.panel-head-text,
.muted,
.hint,
.empty,
.notes-link,
.model-form-inline {
  font-family: var(--font-ui);
}

.fw-name {
  font-family: var(--font-ui);
  font-size: 0.92rem;
  font-weight: 600;
  word-break: break-all;
}

.badge {
  min-width: 1.25rem;
  padding: 0 0.35rem;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 0.75rem;
  text-align: center;
  font-family: var(--font);
  flex-shrink: 0;
}

.panel-head h2 {
  margin: 0 0 0.2rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.panel-head.spaced { margin-top: 1.5rem; }

.panel-head-images {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.panel-head-text {
  flex: 1;
  min-width: 12rem;
}

.model-form-inline {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  position: relative;
}

.model-form-inline input[type="text"] {
  width: 12rem;
  flex: 0 1 auto;
  min-width: 8rem;
  padding: 0.4rem 0.55rem;
}

.model-form-inline button {
  padding: 0.4rem 0.65rem;
  min-width: 2.2rem;
  flex-shrink: 0;
}

.model-form-inline .msg {
  position: absolute;
  top: calc(100% + 0.2rem);
  left: 0;
  margin: 0;
  font-size: 0.8rem;
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.error {
  color: var(--danger);
  margin: 0.6rem 0 0;
}

.msg {
  margin: 0.4rem 0;
  color: var(--accent);
  min-height: 1.2em;
}

/* —— Images: model nav + firmware panel —— */
.images-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-top: 0.85rem;
  align-items: start;
}

@media (min-width: 900px) {
  .images-layout {
    grid-template-columns: minmax(240px, 300px) 1fr;
    gap: 1rem;
  }
}

.model-nav {
  background: transparent;
  border: none;
}

.model-nav-title {
  padding: 0 0 0.4rem;
  border-bottom: none;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.model-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.model-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0.5rem 0.65rem;
  white-space: normal;
  height: auto;
  line-height: 1.35;
}

.model-item:last-child { border-bottom: 1px solid var(--line); }

.model-item:hover {
  background: var(--nav);
  border-color: var(--line);
}

.model-item.active {
  background: #e8f0ed;
  color: var(--accent);
  font-weight: 600;
  border-color: var(--accent);
}

.model-item-name {
  flex: 1;
  min-width: 0;
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 0.88rem;
}

.model-item-count {
  flex-shrink: 0;
  margin-top: 0.1rem;
  font-family: var(--font);
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 400;
}

.model-item.active .model-item-count { color: var(--accent); }

.empty-nav {
  padding: 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.model-panel {
  min-width: 0;
}

.model-detail {
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  margin-bottom: 0.75rem;
}

.model-detail-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.model-detail-row h3 {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.model-detail-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.btn-upload {
  white-space: nowrap;
}

.upload-files-hint {
  font-size: 0.8rem;
  white-space: nowrap;
}

.upload-status {
  margin: 0 0 0.75rem;
  padding: 0.7rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--line);
}

.upload-status.is-error {
  border-color: var(--bad, var(--danger));
}

.upload-status.is-ok {
  border-color: var(--ok);
}

.upload-status-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.upload-status-head strong {
  font-size: 0.85rem;
}

.upload-status-pct {
  font-family: var(--font);
  font-size: 0.75rem;
  color: var(--muted);
}

.upload-bar {
  height: 6px;
  background: var(--nav, #eee);
  border: 1px solid var(--line);
  overflow: hidden;
  margin-bottom: 0.55rem;
}

.upload-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent, #3a6);
  transition: width 0.12s linear;
}

.upload-status.is-error .upload-bar-fill {
  background: var(--bad, var(--danger));
}

.upload-status.is-ok .upload-bar-fill {
  background: var(--ok);
}

.upload-status.is-wait .upload-bar-fill {
  width: 100%;
  background: repeating-linear-gradient(
    -45deg,
    var(--accent, #3a6),
    var(--accent, #3a6) 8px,
    #5a8 8px,
    #5a8 16px
  );
  background-size: 22px 22px;
  animation: upload-stripe 0.6s linear infinite;
}

@keyframes upload-stripe {
  from { background-position: 0 0; }
  to { background-position: 22px 0; }
}

.upload-status-log {
  margin: 0;
  padding-left: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--font);
}

.upload-status-log li {
  word-break: break-word;
}

.upload-status-log li.ok {
  color: var(--ok);
}

.upload-status-log li.err {
  color: var(--bad, var(--danger));
}

.upload-status-log li.active {
  color: #222;
}

.btn-upload:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-icon.btn-del {
  color: var(--danger);
  border-color: var(--line);
  background: #fff;
  font-size: 1.15rem;
  font-weight: 500;
}

.btn-icon.btn-del:hover {
  background: #f8eeee;
  border-color: var(--danger);
  color: var(--danger);
}

.fw-row {
  display: block;
  padding: 0.65rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
}

.upload-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.notes-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.notes-row input {
  flex: 1;
  min-width: 12rem;
}

.notes-link {
  color: var(--accent);
  font-size: 0.85rem;
}

.hint,
.upload-hint {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.images-heading {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  margin: 0 0 0.5rem;
}

.images-heading h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.fw-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.fw-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.55rem;
  margin-bottom: 0.25rem;
}

.fw-notes {
  margin: 0.35rem 0;
}

.fw-size {
  margin-left: auto;
  font-family: var(--font);
  font-size: 0.78rem;
  color: var(--muted);
}

.fw-url {
  display: block;
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0.3rem 0.4rem;
  background: var(--nav);
  border: 1px solid var(--line);
  font-family: var(--font);
  font-size: 0.72rem;
  overflow-x: auto;
  white-space: nowrap;
}

.fw-url-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.btn-icon {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  padding: 0;
  min-width: 0;
  line-height: 1;
  font-size: 1rem;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-icon:hover {
  background: var(--nav);
  border-color: var(--line);
  color: var(--accent);
}

.btn-icon[data-state="done"] {
  color: var(--ok);
  border-color: var(--ok);
}

.integrity-pill {
  display: inline;
  padding: 0;
  border: none;
  font-family: var(--font);
  font-size: 0.72rem;
  min-width: 0;
  text-align: left;
  color: var(--muted);
}

.integrity-pill.ok {
  color: var(--ok);
}

.integrity-pill.bad {
  color: var(--bad);
}

.meta {
  font-family: var(--font);
  font-size: 0.75rem;
  color: var(--muted);
  word-break: break-all;
}

.meta-key {
  color: #444;
  font-weight: 600;
}

.meta-sep {
  margin: 0 0.25rem;
  color: #bbb;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 0.7rem 0.8rem;
}

.card.pending { border-left: 3px solid #a8842e; }
.card.approved,
.card.delivered { border-left: 3px solid var(--ok); }
.card.denied { border-left: 3px solid var(--bad); }
.card.rate_limited { border-left: 3px solid #6b6b6b; }

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: none;
}

.queue-count {
  font-weight: 400;
  font-size: 0.9rem;
}

.queue-row {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) auto auto;
  gap: 0.45rem 0.65rem;
  align-items: center;
  padding: 0.4rem 0.55rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left-width: 3px;
}

.queue-row.pending { border-left-color: #a8842e; }
.queue-row.approved { border-left-color: var(--ok); }
.queue-row.rate_limited { border-left-color: #6b6b6b; }

.queue-pos {
  font-family: var(--font);
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.queue-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}

.queue-title {
  font-weight: 600;
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-meta {
  font-family: var(--font);
  font-size: 0.72rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-client {
  font-family: var(--font);
  font-size: 0.72rem;
  color: #555;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

.queue-actions button {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

.queue-note {
  font-size: 0.75rem;
  white-space: nowrap;
}

.req-head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
  align-items: flex-start;
}

.req-head-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.req-actions {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.history-head h2 {
  margin: 0;
}

.req-details {
  margin-top: 0.35rem;
}

.req-details summary {
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--muted);
  user-select: none;
  list-style: none;
}

.req-details summary::-webkit-details-marker {
  display: none;
}

.req-details summary::before {
  content: "▸ ";
  color: #bbb;
}

.req-details[open] summary::before {
  content: "▾ ";
}

.req-details-body {
  margin-top: 0.35rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  background: var(--nav, #f7f7f5);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.req-details-body code {
  font-size: 0.72rem;
}

.empty {
  padding: 0.85rem;
  border: 1px dashed var(--line);
  color: var(--muted);
}

.kv {
  display: grid;
  grid-template-columns: minmax(9rem, 13rem) 1fr;
  gap: 0.45rem 0.85rem;
  margin: 0.85rem 0 0;
  padding: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--line);
}

.kv dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.kv dd {
  margin: 0;
  font-family: var(--font);
  font-size: 0.8rem;
  word-break: break-all;
}

.rate-form {
  display: grid;
  grid-template-columns: minmax(9rem, 16rem) 1fr;
  gap: 0.45rem 0.85rem;
  align-items: center;
  margin: 0.85rem 0 0;
  padding: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--line);
}

.rate-form label {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.rate-form input[type="number"],
.rate-form input[type="text"] {
  width: 100%;
  max-width: 28rem;
  font-family: var(--font);
  font-size: 0.85rem;
}

.rate-form .hint {
  grid-column: 2;
  margin: -0.15rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.rate-form-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.rate-form-actions .msg {
  margin: 0;
  font-size: 0.8rem;
}

.status-pill {
  display: inline-block;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--line);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-family: var(--font);
}

.status-pill.rate_limited {
  color: #555;
}

.card-actions button.btn-copy[data-state="done"],
.fw-actions button.btn-copy[data-state="done"] {
  color: var(--ok);
  border-color: var(--ok);
}

/* —— Responsive: phone + laptop —— */
@media (max-width: 899px) {
  .images-layout {
    grid-template-columns: 1fr;
  }

  .model-nav {
    max-height: 14rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 720px) {
  html, body {
    font-size: 15px;
  }

  .top {
    padding: 0.5rem 0.65rem;
    gap: 0.4rem;
  }

  .brand {
    width: 100%;
  }

  .brand strong {
    font-size: 0.95rem;
  }

  nav {
    width: 100%;
    gap: 0;
  }

  button.tab {
    flex: 1 1 auto;
    text-align: center;
    padding: 0.5rem 0.35rem;
    font-size: 0.85rem;
  }

  #logout-btn {
    flex: 0 0 auto;
    padding: 0.45rem 0.55rem;
    font-size: 0.8rem;
  }

  .content {
    width: calc(100% - 1rem);
    margin: 0.65rem auto 1.5rem;
  }

  .panel-head h2 {
    font-size: 1rem;
  }

  .panel-head-images {
    flex-direction: column;
    align-items: stretch;
  }

  .panel-head-text {
    min-width: 0;
  }

  .model-form-inline {
    width: 100%;
  }

  .model-form-inline input[type="text"] {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
  }

  .model-detail-row {
    flex-direction: column;
    align-items: stretch;
  }

  .model-detail-actions {
    width: 100%;
  }

  .upload-files-hint {
    white-space: normal;
  }

  .queue-row {
    grid-template-columns: 1.75rem minmax(0, 1fr);
    gap: 0.35rem 0.5rem;
    padding: 0.5rem 0.55rem;
  }

  .queue-row .status-pill {
    grid-column: 2;
    justify-self: start;
  }

  .queue-actions {
    grid-column: 1 / -1;
    width: 100%;
  }

  .queue-actions button {
    flex: 1 1 auto;
    min-height: 2.4rem;
    padding: 0.4rem 0.55rem;
  }

  .queue-title,
  .queue-meta,
  .queue-client {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    word-break: break-word;
  }

  .history-head {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .history-head button {
    width: 100%;
  }

  .req-head {
    flex-wrap: wrap;
  }

  .req-actions button {
    flex: 1 1 auto;
    min-height: 2.4rem;
  }

  .kv,
  .rate-form {
    grid-template-columns: 1fr;
    gap: 0.25rem 0;
    padding: 0.7rem;
  }

  .kv dt {
    margin-top: 0.45rem;
  }

  .kv dt:first-child {
    margin-top: 0;
  }

  .rate-form label {
    margin-top: 0.45rem;
  }

  .rate-form label:first-child {
    margin-top: 0;
  }

  .rate-form .hint {
    grid-column: 1;
  }

  .rate-form input[type="number"],
  .rate-form input[type="text"] {
    max-width: none;
  }

  .notes-row input {
    min-width: 0;
    width: 100%;
  }

  .fw-url-row {
    flex-wrap: wrap;
  }

  .fw-url {
    width: 100%;
    flex: 1 1 100%;
    white-space: normal;
    word-break: break-all;
  }

  .fw-size {
    margin-left: 0;
  }

  .card {
    padding: 0.6rem 0.65rem;
  }
}

@media (min-width: 721px) and (max-width: 1100px) {
  .content {
    width: calc(100% - 2rem);
  }

  .queue-row {
    grid-template-columns: 2rem minmax(0, 1fr) auto auto;
  }

  .rate-form {
    grid-template-columns: minmax(8rem, 14rem) 1fr;
  }

  .kv {
    grid-template-columns: minmax(8rem, 12rem) 1fr;
  }
}

@media (min-width: 1100px) {
  .images-layout {
    grid-template-columns: minmax(260px, 320px) 1fr;
  }
}
