:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-soft: #eef5f3;
  --text: #202124;
  --muted: #667085;
  --line: #d7dde5;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --ink: #111827;
  --warn: #a16207;
  --danger: #b42318;
  --blue: #1d4ed8;
  font-family: "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden], .is-hidden { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell { min-height: 100vh; }
.app-shell.is-loading { display: none; }

.auth-screen {
  align-items: center;
  background: linear-gradient(135deg, #f6f7f9 0%, #e9f3f1 52%, #f5efe7 100%);
  display: flex;
  min-height: 100vh;
  padding: 18px;
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(17, 24, 39, 0.14);
  display: grid;
  gap: 14px;
  margin: auto;
  max-width: 420px;
  padding: 22px;
  width: 100%;
}

.auth-card label, .invite-form label, .password-panel label, .public-url-field {
  display: grid;
  gap: 6px;
}

.auth-card label span, .invite-form span, .password-panel span, .public-url-field span, .link-panel > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.auth-help {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: 0;
}

.password-panel {
  display: grid;
  gap: 12px;
}

.generated-password {
  background: #f0f7f5;
  border: 1px solid #b7d8d0;
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 10px;
}

.generated-password span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.generated-password code {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-family: Consolas, "Cascadia Mono", monospace;
  padding: 8px;
  user-select: all;
}

.topbar {
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 16px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  padding: 16px 22px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1, h2, h3 {
  letter-spacing: 0;
  margin: 0;
}

h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 13px; }

.tabs {
  align-items: center;
  background: #edf0f4;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  justify-self: center;
  padding: 3px;
}

.tab {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  min-height: 34px;
  padding: 0 13px;
}

.tab.is-active {
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.08);
  color: var(--ink);
  font-weight: 700;
}

.session-box {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.session-box span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main { padding: 18px; }

.view { display: none; }
.view.is-active { display: block; }

.viewer-layout {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(280px, 350px) minmax(0, 1fr);
  height: calc(100vh - 112px);
  min-height: 540px;
}

.side-panel, .image-stage, .control-panel, .console-panel, .table-panel, .panel-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.side-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px;
}

.metric-row, .quality-metrics {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 14px;
}

.metric-row > div, .quality-metrics > div {
  background: var(--panel-soft);
  border: 1px solid #cfe4df;
  border-radius: 8px;
  padding: 10px;
}

.quality-metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0;
}

.quality-metrics span, .metric-label {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 4px;
}

.metric-row strong, .quality-metrics strong { font-size: 22px; }

.search-box, .inline-filter {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.inline-filter {
  align-items: center;
  grid-template-columns: auto minmax(180px, 260px);
  margin: 0;
}

.search-box span, .date-grid span, .limit-grid span, .inline-filter span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  min-height: 36px;
  padding: 7px 9px;
  width: 100%;
}

input:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid #14b8a6;
  outline-offset: 2px;
}

.record-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  list-style: none;
  margin: 0;
  min-height: 0;
  overflow: auto;
  padding: 0;
}

.record-list button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  display: grid;
  gap: 3px;
  min-height: 48px;
  padding: 8px;
  text-align: left;
  width: 100%;
}

.record-list button:hover, .record-list button.is-active {
  background: #f0f7f5;
  border-color: #b7d8d0;
}

.record-title {
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-meta {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-stage {
  display: grid;
  grid-template-rows: auto minmax(300px, 1fr) auto;
  min-width: 0;
  overflow: hidden;
}

.stage-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 14px 16px;
}

.stage-header h2 {
  max-width: 68vw;
  overflow-wrap: anywhere;
}

.nav-buttons, .modal-actions, .guest-actions {
  display: flex;
  gap: 8px;
}

.stage-tools {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-end;
}

.zoom-control {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: auto 150px 48px;
}

.zoom-control span,
.zoom-control strong {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.zoom-control input {
  min-height: auto;
  padding: 0;
}

.button {
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  min-height: 36px;
  padding: 0 14px;
}

.button.primary {
  background: var(--accent);
  color: #fff;
}

.button.primary:hover { background: var(--accent-strong); }

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

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

.button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.image-frame {
  background: #f9fafb;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  position: relative;
  width: 100%;
}

.image-frame img {
  display: none;
  height: auto;
  max-height: none;
  max-width: none;
  object-fit: initial;
}

.image-frame img.has-image { display: block; }

.empty-state {
  align-items: center;
  background: rgba(255, 255, 255, 0.86);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  justify-content: center;
  min-height: 180px;
  padding: 24px;
  width: min(460px, 100%);
}

.metadata-bar {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  min-height: 52px;
  padding: 10px 16px;
}

.metadata-bar a, td a, .image-tile a {
  color: var(--accent-strong);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.metadata-bar span {
  color: var(--muted);
  white-space: nowrap;
}

.quality-layout {
  display: grid;
  gap: 16px;
}

.panel-block { padding: 16px; }

.duplicate-list {
  display: grid;
  gap: 10px;
}

.duplicate-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 10px;
}

.duplicate-header {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.duplicate-header span {
  color: var(--muted);
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.duplicate-thumbs, .quality-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.image-tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 8px;
}

.image-tile.is-compact {
  grid-template-columns: 96px minmax(0, 1fr);
}

.image-tile.is-compact h3,
.image-tile.is-compact p,
.image-tile.is-compact a {
  grid-column: 2;
}

.tile-image-button {
  align-items: center;
  aspect-ratio: 4 / 3;
  background: #f3f5f7;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: zoom-in;
  display: flex;
  justify-content: center;
  min-width: 0;
  overflow: hidden;
  padding: 0;
  width: 100%;
}

.image-tile.is-compact .tile-image-button {
  grid-row: 1 / span 3;
  width: 96px;
}

.tile-image-button img {
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.tile-image-button span {
  color: var(--muted);
  font-size: 12px;
  padding: 8px;
}

.image-tile h3,
.image-tile p {
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-tile h3 {
  display: -webkit-box;
  font-size: 13px;
  line-height: 1.25;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.image-tile p {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
  white-space: nowrap;
}

.image-tile a {
  font-size: 12px;
}

.empty-inline {
  background: #f9fafb;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 16px;
}

.workbench, .guest-layout {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  min-height: calc(100vh - 112px);
}

.control-panel, .console-panel, .table-panel { padding: 16px; }

.date-grid,
.limit-grid,
.invite-form,
.public-url-field {
  display: grid;
  gap: 12px;
  margin: 16px 0;
}

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

.test-row {
  align-items: center;
  display: flex;
  gap: 8px;
  margin: 4px 0 0;
}

.test-row input {
  min-height: auto;
  width: auto;
}

.test-row span {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.field-warning {
  background: #fff8eb;
  border: 1px solid #f2d498;
  border-radius: 8px;
  color: var(--warn);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  margin: -8px 0 12px;
  padding: 9px 10px;
}

.status-strip {
  align-items: center;
  background: #fff8eb;
  border: 1px solid #f2d498;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
  padding: 10px;
}

.status-strip span {
  color: var(--warn);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.console-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.console-header, .table-header {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.console-header span, .table-header span {
  color: var(--muted);
  font-size: 13px;
}

.console-output {
  background: #171b20;
  border-radius: 8px;
  color: #d8dee9;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 13px;
  line-height: 1.5;
  min-height: 420px;
  overflow: auto;
  padding: 12px;
}

.console-line {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: grid;
  gap: 8px;
  grid-template-columns: 76px 86px minmax(0, 1fr);
  padding: 5px 0;
}

.console-line strong { color: #8bd5ca; }
.console-line[data-kind="error"] strong { color: #ffb4ab; }

.table-panel { min-height: calc(100vh - 112px); }
.table-scroll { overflow: auto; }
.compact-table { max-height: 420px; }

.table-button {
  min-height: 30px;
  padding: 0 10px;
}

.link-panel {
  background: #f0f7f5;
  border: 1px solid #b7d8d0;
  border-radius: 8px;
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 10px;
}

.copy-field,
.inline-link-copy {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.inline-link-copy input {
  min-width: 260px;
}

.user-status {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  white-space: nowrap;
}

.user-status.is-active {
  background: #e7f6ef;
  color: #087443;
}

.user-status.is-disabled {
  background: #fff1f0;
  color: var(--danger);
}

.muted-text {
  color: var(--muted);
  font-size: 12px;
}

.guest-actions {
  flex-wrap: wrap;
}

#guests table {
  min-width: 1080px;
}

table {
  border-collapse: collapse;
  min-width: 760px;
  width: 100%;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #eef5f3;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.image-modal {
  background: rgba(17, 24, 39, 0.72);
  display: none;
  inset: 0;
  padding: 18px;
  position: fixed;
  z-index: 30;
}

.image-modal.is-open {
  display: flex;
}

.modal-panel {
  background: var(--panel);
  border-radius: 8px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: calc(100vh - 36px);
  margin: auto;
  overflow: hidden;
  width: min(1180px, 100%);
}

.modal-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 14px 16px;
}

.modal-header h2 {
  max-width: 68vw;
  overflow-wrap: anywhere;
}

.modal-scroll {
  background: #0f1216;
  overflow: auto;
  padding: 24px;
}

.modal-scroll img {
  display: block;
  height: auto;
  margin: auto;
  max-width: none;
}

#toast {
  background: var(--danger);
  border-radius: 8px;
  bottom: 18px;
  color: #fff;
  display: none;
  font-weight: 700;
  max-width: 520px;
  padding: 12px 14px;
  position: fixed;
  right: 18px;
  z-index: 40;
}

#toast.is-visible { display: block; }

@media (max-width: 1000px) {
  .topbar {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .tabs, .session-box { justify-self: stretch; }
  .session-box { justify-content: space-between; }
}

@media (max-width: 900px) {
  .stage-header, .metadata-bar, .modal-header, .console-header, .table-header {
    align-items: stretch;
    flex-direction: column;
  }

  .tabs, .nav-buttons, .modal-actions, .stage-tools { width: 100%; }
  .tab, .nav-buttons .button, .modal-actions .button { flex: 1; }
  .viewer-layout, .workbench, .guest-layout { grid-template-columns: 1fr; }
  .viewer-layout { height: auto; }
  .side-panel { max-height: 340px; }
  .image-stage { min-height: 560px; }
  .zoom-control { grid-template-columns: auto minmax(120px, 1fr) 48px; width: 100%; }
  .stage-header h2, .modal-header h2 { max-width: 100%; }
  .quality-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inline-filter { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  main { padding: 10px; }
  .quality-metrics, .metric-row, .limit-grid, .copy-field, .inline-link-copy { grid-template-columns: 1fr; }
  .duplicate-thumbs, .quality-grid { grid-template-columns: 1fr; }
  .image-tile.is-compact { grid-template-columns: 1fr; }
  .image-tile.is-compact .tile-image-button {
    grid-row: auto;
    width: 100%;
  }
}
