:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --text: #151818;
  --muted: #5b6662;
  --line: #d8dfdc;
  --accent: #087f5b;
  --accent-2: #0b7285;
  --danger: #c92a2a;
  --warning: #b7791f;
  --shadow: 0 8px 24px rgba(20, 30, 28, 0.08);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  font-family: Arial, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  letter-spacing: 0;
  color: var(--text);
  background: var(--bg);
}

button, input, textarea, select {
  font: inherit;
  letter-spacing: 0;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--text);
  color: #fff;
  cursor: pointer;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 10px 14px;
  text-decoration: none;
  background: var(--text);
  color: #fff;
}

button.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.button-link.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
}

button.accent { background: var(--accent); }
button.info { background: var(--accent-2); }
button.danger { background: var(--danger); }
button.warning { background: var(--warning); }
button:disabled { cursor: not-allowed; opacity: 0.55; }

.demo-badge {
  display: inline-flex;
  width: fit-content;
  border: 1px solid #74b816;
  border-radius: 8px;
  padding: 4px 8px;
  color: #2b6b16;
  background: #ebfbee;
  font-size: 14px;
  font-weight: 700;
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
}

textarea { min-height: 120px; resize: vertical; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }

.app-shell {
  width: min(1720px, 100%);
  margin: 0 auto;
  padding: 20px;
}

body.is-authenticated .app-shell {
  width: min(1720px, 100%);
  display: block;
  min-height: auto;
  padding: 20px;
}

body.is-authenticated .sidebar {
  grid-area: sidebar;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  display: grid;
  gap: 12px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  padding: 16px 0 18px;
  border-bottom: 1px solid var(--line);
}

body.is-authenticated .topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  padding: 16px 0 18px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.eyebrow { margin: 0 0 6px; color: var(--accent); font-weight: 700; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: 32px; line-height: 1.1; }
h2 { margin: 0 0 14px; font-size: 24px; }
h3 { margin: 0 0 10px; font-size: 18px; }

body.is-authenticated h1 { font-size: 32px; }
body.is-authenticated .eyebrow { margin-bottom: 8px; }

.user-box {
  min-width: 260px;
  display: grid;
  gap: 8px;
  justify-items: end;
  color: var(--muted);
}

.user-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

body.is-authenticated .user-box {
  min-width: 260px;
  width: auto;
  justify-items: end;
}

body.is-authenticated .user-box button {
  width: auto;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 16px 0;
}

body.is-authenticated .tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 16px 0;
}

.tab {
  display: flex;
  justify-content: center;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

body.is-authenticated .tab {
  width: auto;
  text-align: center;
}

.tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.content, .stack {
  display: grid;
  gap: 18px;
  align-content: start;
}

body.is-authenticated .content {
  grid-area: app;
  min-width: 0;
  width: 100%;
}

.content > *, .stack > *, .panel, .item { min-width: 0; }

.grid {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 18px;
  align-items: start;
}

.objects-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.demo-panel {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  border: 1px solid #b2d8a5;
  border-radius: 8px;
  padding: 12px;
  color: #2b3a2a;
  background: #f1f8ee;
}

.object-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(66.666%, 1200px);
  margin: 0 auto;
  gap: 16px;
  align-items: stretch;
}

.object-tool-card {
  align-content: start;
}

.object-catalog {
  min-width: 0;
}

.object-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 340px));
  gap: 16px;
  align-items: start;
  justify-content: start;
}

.object-card {
  min-height: 220px;
  align-content: space-between;
}

.object-card-title {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  justify-content: space-between;
}

.object-card-title strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.icon-button {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
}

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

.inline-title-input {
  min-width: 0;
  flex: 1 1 auto;
  padding: 4px 8px;
  font-weight: 700;
}

.accent-icon {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.accent-icon:hover {
  color: #fff;
}

.object-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.object-card-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
}

.object-card-actions button {
  width: 100%;
}

.object-card-actions .object-delete-button {
  grid-column: 1 / -1;
}

.object-card-actions .object-wide-button {
  grid-column: 1 / -1;
}

.object-detail-page {
  min-width: 0;
}

.object-detail-nav {
  display: flex;
  justify-content: flex-start;
}

.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.panel, .item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.panel { box-shadow: var(--shadow); }
.item { display: grid; gap: 10px; padding: 12px; }
.item.selected { border-color: var(--accent); background: #edf8f4; }

.toolbar, .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: end;
}

.user-search-panel {
  min-height: 0;
}

.user-search-form {
  align-items: end;
}

.user-search-form label {
  flex: 1 1 560px;
  max-width: 820px;
}

.user-search-form button {
  flex: 0 0 auto;
}

.meta {
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}

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

.file-picker {
  position: relative;
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-picker span {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  cursor: pointer;
}

.file-chip {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--surface-2);
}

.file-chip span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.progress {
  display: grid;
  gap: 6px;
}

.inline-progress {
  min-width: min(260px, 100%);
  align-self: center;
}

.progress-bar {
  height: 12px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 120ms ease;
}

.note-textarea[readonly] {
  background: var(--surface-2);
}

.file-block {
  display: grid;
  gap: 10px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 24, 24, 0.36);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative;
  width: min(620px, calc(100% - 28px));
  margin: 8vh auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.modal-titlebar {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.modal-titlebar h2 {
  margin: 0;
}

.modal-close {
  margin-left: auto;
  flex: 0 0 auto;
}

.preview-panel {
  width: min(1040px, calc(100% - 28px));
  max-height: calc(100vh - 48px);
  overflow: auto;
}

.preview-body {
  display: grid;
  gap: 12px;
}

.preview-body img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 180px);
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.preview-body iframe {
  width: 100%;
  height: min(70vh, 760px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
}

.login { max-width: 520px; margin: 40px auto 0; }
.support-panel { max-width: 860px; margin: 0 auto; }
.note-text { white-space: pre-wrap; }

.photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  align-items: start;
}

.photo {
  min-width: 0;
  display: grid;
  gap: 8px;
  align-content: start;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface);
}

.file-preview-trigger,
.photo-preview,
.file-chip-main {
  width: 100%;
  min-width: 0;
  display: grid;
  gap: 8px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.file-preview-trigger {
  cursor: pointer;
}

.file-preview-trigger:hover .file-name,
.file-chip-main:hover span {
  color: var(--accent);
}

.photo img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.file-name {
  display: block;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.photo .actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
  align-items: stretch;
}

.photo .actions > * {
  width: 100%;
  min-width: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-2);
}

.stat strong { display: block; font-size: 24px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.toast.show { opacity: 1; }

@media (max-width: 860px) {
  .app-shell { padding: 14px; }
  body.is-authenticated .app-shell {
    display: block;
    padding: 14px;
  }
  body.is-authenticated .topbar,
  body.is-authenticated .tabs,
  body.is-authenticated .sidebar {
    position: static;
  }
  body.is-authenticated .topbar,
  .topbar, .grid, .objects-layout, .split {
    grid-template-columns: 1fr;
    display: grid;
  }
  body.is-authenticated .tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 14px 0;
  }
  body.is-authenticated .sidebar {
    max-height: none;
    overflow: visible;
  }
  .user-box { min-width: 0; justify-items: start; }
  .user-actions { justify-content: flex-start; }
  .object-tools {
    grid-template-columns: 1fr;
    width: 100%;
  }
  .object-card-grid {
    display: grid;
    grid-template-columns: 1fr;
  }
  .object-card {
    min-height: 0;
  }
  h1 { font-size: 26px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .toolbar, .actions, .tabs {
    display: grid;
    grid-template-columns: 1fr;
  }
  .stats { grid-template-columns: 1fr; }
}
