:root {
  color-scheme: dark;
  --bg: #1c1917;
  --surface: #292524;
  --surface-hover: #33302e;
  --border: #3c3835;
  --text: #e7e0d8;
  --text-muted: #78716c;
  --accent: #3d9ee5;
  --accent-hover: #2d8ad4;
  --danger: #d4534a;
  --radius: 20px;
  --radius-sm: 14px;
  --radius-btn: 12px;
  --shadow: 0 32px 80px rgba(0, 0, 0, 0.5);
  --sans: 'DM Sans', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sidebar-w: 240px;
  font-family: var(--sans);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-family: var(--sans);
}

body {
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; font-family: var(--sans); }
input, textarea, select { font: inherit; color: inherit; font-family: var(--sans); }

[hidden] { display: none !important; }

/* Topbar */

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 18px 28px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(28, 25, 23, 0.85);
  backdrop-filter: saturate(140%) blur(14px);
}

.topbar-toggle {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: transparent;
  color: var(--text-muted);
}
.topbar-toggle:hover { background: var(--surface); color: var(--text); }

.brand {
  display: flex;
  flex-direction: column;
  gap: 0;
  text-decoration: none;
  margin-left: 4px;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.3px;
  line-height: 1.1;
  color: var(--text);
}

.brand p {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.search-input {
  padding: 10px 20px;
  background: var(--surface);
  border: 0;
  border-radius: var(--radius-sm);
  width: 260px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: background 0.15s ease;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { background: var(--surface-hover); }

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 22px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.btn:hover { background: var(--surface-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 14px; font-size: 12px; border-radius: 10px; }

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

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn.ghost:hover { background: var(--surface); color: var(--text); }

.btn.danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius-btn);
  padding: 8px 20px;
}
.btn.danger:hover { background: rgba(212, 83, 74, 0.1); }

.btn-plus {
  font-size: 16px;
  font-weight: 400;
  line-height: 1;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--border);
  color: var(--text-muted);
  border: 0;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

/* Layout */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  flex: 1;
  min-height: 0;
}
body.sidebar-collapsed .layout { grid-template-columns: 0 1fr; }
body.sidebar-collapsed .sidebar { transform: translateX(-100%); pointer-events: none; }

.sidebar {
  position: sticky;
  top: 72px;
  align-self: flex-start;
  height: calc(100vh - 72px);
  width: var(--sidebar-w);
  border-right: 1px solid var(--border);
  background: var(--bg);
  overflow: hidden;
  transition: transform 0.2s ease;
  z-index: 3;
}

.sidebar-inner {
  height: 100%;
  overflow-y: auto;
  padding: 12px 12px 32px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-inner::-webkit-scrollbar { width: 6px; }
.sidebar-inner::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s ease;
  width: 100%;
  min-width: 0;
}
.sidebar-item:hover { background: var(--surface); }
.sidebar-item.active {
  background: var(--surface);
  color: var(--text);
}
.sidebar-item.active::before {
  content: "";
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: var(--accent);
  flex-shrink: 0;
  margin-left: -3px;
  margin-right: 4px;
}

.sidebar-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-count {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 16px;
}

.sidebar-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px 6px;
}

.sidebar-section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sidebar-add {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  border: 0;
  cursor: pointer;
  font-size: 16px;
  font-weight: 400;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sidebar-add:hover { background: var(--surface); color: var(--text); }

.sidebar-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-item.editing {
  background: var(--surface);
  padding: 6px 10px;
}

.sidebar-rename {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  min-width: 0;
}
.sidebar-rename:focus { border-color: var(--accent); }

.sidebar-actions {
  display: none;
  gap: 4px;
  flex-shrink: 0;
}
.sidebar-item:hover .sidebar-actions,
.sidebar-item.active .sidebar-actions { display: inline-flex; }

.sidebar-action {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sidebar-action:hover { background: var(--bg); color: var(--text); }
.sidebar-action.danger:hover { color: var(--danger); }
.sidebar-action[disabled] { opacity: 0.3; cursor: not-allowed; }

.sidebar-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 12px;
  font-style: italic;
}

/* Filter banner */

.filter-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  margin: 0 0 12px;
  background: var(--surface);
  border-radius: 12px;
  font-size: 13px;
  color: var(--text);
}

.filter-banner b { color: var(--accent); font-weight: 600; }

/* Main */

main {
  flex: 1;
  padding: 16px 28px 80px;
  min-width: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.card {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
  display: flex;
  flex-direction: column;
  user-select: none;
  position: relative;
}

.card:hover {
  background: var(--surface-hover);
  transform: translateY(-2px);
}

.card.dragging { opacity: 0.4; }
.card.drag-over { outline: 2px solid var(--accent); outline-offset: -2px; }

.card-thumb {
  position: relative;
  aspect-ratio: 9 / 16;
  width: 100%;
  overflow: hidden;
  background: var(--border);
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-title {
  padding: 10px 14px 12px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  letter-spacing: -0.1px;
}

.card-folder-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(28, 25, 23, 0.78);
  backdrop-filter: blur(8px);
  color: var(--text);
  letter-spacing: 0.02em;
  pointer-events: none;
  max-width: calc(100% - 16px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card .placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 11px;
  background: var(--border);
}

.empty-state {
  margin: 80px auto;
  text-align: center;
  color: var(--text-muted);
  max-width: 460px;
  font-size: 14px;
  line-height: 1.5;
  font-weight: 400;
}

.sentinel { height: 1px; }

.status {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  margin: 24px 0;
  min-height: 18px;
}

/* Dialog */

.dialog {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--text);
  max-width: 100%;
  max-height: 100%;
}
.dialog::backdrop {
  background: rgba(28, 25, 23, 0.7);
  backdrop-filter: blur(12px);
}
.dialog-card {
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

/* Add modal */

.add-card {
  width: min(640px, 92vw);
  max-height: 86vh;
  overflow: auto;
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.dialog-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.2px;
  color: var(--text);
}

.dialog-body {
  padding: 24px;
  display: grid;
  gap: 16px;
}

.dialog-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  bottom: 0;
}

.dialog-foot .btn { margin-left: auto; }
.dialog-foot .btn:first-child { margin-left: 0; }

/* Form fields */

.field { display: grid; gap: 8px; }

.field > span {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.field input[type="text"],
.field input[type="url"],
.field textarea,
.select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 10px 14px;
  outline: none;
  width: 100%;
  resize: vertical;
  font-size: 13px;
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.field input:focus,
.field textarea:focus,
.select:focus {
  border-color: var(--accent);
  background: var(--surface);
}

.field input::placeholder,
.field textarea::placeholder { color: var(--text-muted); }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  cursor: pointer;
}

.select-compact {
  padding: 6px 30px 6px 10px;
  font-size: 12px;
  border-radius: 8px;
  width: auto;
  min-width: 120px;
  background-position: right 8px center;
}

.url-row { display: flex; gap: 10px; }
.url-row input { flex: 1; }
.url-row .btn { flex-shrink: 0; }

.error {
  margin: 0;
  padding: 10px 14px;
  border-radius: var(--radius-btn);
  background: rgba(212, 83, 74, 0.1);
  color: #f08a82;
  border: 1px solid rgba(212, 83, 74, 0.3);
  font-size: 13px;
}

/* Add preview */

.preview {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 18px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.preview-thumb {
  position: relative;
  aspect-ratio: 9 / 16;
  border-radius: 14px;
  overflow: hidden;
  background: var(--border);
}

.preview-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-upload {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(28, 25, 23, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  z-index: 2;
}
.thumb-upload:hover { background: var(--surface-hover); }
.thumb-upload[data-state="uploading"] { opacity: 0.5; pointer-events: none; }

.preview-meta { display: grid; gap: 12px; align-content: start; }

/* Multi-select dropdown */

.multi-select { position: relative; display: flex; }
.multi-select-compact { flex: 1; min-width: 0; }

.ms-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  width: 100%;
  text-align: left;
  font-family: inherit;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.ms-trigger:hover { background: var(--surface); }
.ms-trigger.is-open,
.ms-trigger:focus-visible { outline: none; border-color: var(--accent); background: var(--surface); }

.ms-trigger-compact {
  padding: 6px 8px 6px 10px;
  font-size: 12px;
  border-radius: 8px;
  min-width: 0;
}

.ms-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ms-label.placeholder { color: var(--text-muted); }

.ms-trigger > svg {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}
.ms-trigger.is-open > svg { transform: rotate(180deg); }

.ms-pill-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  padding: 0 6px;
  height: 18px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  margin-right: 2px;
  flex-shrink: 0;
}

.ms-panel {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  min-width: 240px;
  max-width: 360px;
  max-height: 320px;
  overflow: hidden;
  margin: 0;
}

.ms-search {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text);
  outline: none;
  font-family: inherit;
}
.ms-search:focus { border-color: var(--accent); }
.ms-search::placeholder { color: var(--text-muted); }

.ms-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  max-height: 240px;
}
.ms-list::-webkit-scrollbar { width: 6px; }
.ms-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.ms-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  text-align: left;
  width: 100%;
  font-family: inherit;
}
.ms-option:hover,
.ms-option[data-active="1"] { background: var(--bg); }

.ms-check {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  border: 1.5px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: transparent;
  color: transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.ms-check svg { width: 11px; height: 11px; }
.ms-option.checked .ms-check {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ms-option-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ms-option-count {
  color: var(--text-muted);
  font-size: 11px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.ms-option-create {
  margin-top: 4px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  border-radius: 0;
}
.ms-option-create:hover { background: var(--bg); }
.ms-option-create .ms-check {
  border-style: dashed;
  color: var(--accent);
  background: transparent;
  font-size: 14px;
  font-weight: 400;
  line-height: 1;
}
.ms-option-create .ms-check::before { content: "+"; }
.ms-option-create .ms-option-name { color: var(--accent); font-weight: 500; }

.ms-empty {
  padding: 14px 10px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

/* Detail modal */

.detail-card {
  width: 620px;
  max-width: 92vw;
  flex-direction: row;
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.drag-handle { display: none; }

.detail-thumb {
  width: 260px;
  flex-shrink: 0;
  aspect-ratio: 9 / 16;
  align-self: flex-start;
  display: block;
  position: relative;
  background: #000;
  cursor: pointer;
  text-decoration: none;
}

.detail-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transition: filter 0.2s ease;
}

.detail-thumb:hover img { filter: brightness(0.85); }

.thumb-upload-detail {
  bottom: 12px;
  left: 12px;
  right: auto;
  padding: 6px 10px;
}

.detail-body {
  flex: 1;
  min-width: 0;
  padding: 28px 28px 24px;
  display: flex;
  flex-direction: column;
  position: relative;
  gap: 8px;
}

.detail-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border: 0;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  z-index: 2;
}
.detail-close:hover { background: var(--surface-hover); color: var(--text); }

.inline-title {
  background: transparent;
  border: 0;
  outline: none;
  padding: 0;
  margin: 0;
  width: 100%;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.3px;
  line-height: 1.2;
  color: var(--text);
  padding-right: 44px;
}
.inline-title::placeholder { color: var(--text-muted); }

.inline-description {
  background: transparent;
  border: 0;
  outline: none;
  padding: 0;
  width: 100%;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text-muted);
  resize: none;
  min-height: 50px;
}
.inline-description::placeholder { color: var(--text-muted); opacity: 0.7; }

.detail-meta-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
  margin-top: 6px;
}

.detail-actions {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.detail-status {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
  text-align: center;
}
.detail-status[data-state="dirty"] { color: var(--accent); }
.detail-status[data-state="saved"] { color: #8aae8a; }
.detail-status[data-state="saving"] { color: var(--text-muted); }

.btn[data-state="copied"] { background: var(--surface-hover); color: var(--text); }

/* ──────────────────────────────────────────
   Mobile (≤ 760px)
   ────────────────────────────────────────── */

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    column-gap: 10px;
    row-gap: 12px;
    padding: 14px 18px;
  }

  .topbar-toggle { grid-column: 1; grid-row: 1; }
  .brand { grid-column: 2; grid-row: 1; margin-left: 0; }
  #add-button { grid-column: 3; grid-row: 1; }
  .search-input {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    border-radius: var(--radius-btn);
    padding: 10px 16px;
  }

  .brand h1 { font-size: 20px; }
  .brand p { font-size: 10px; margin-top: 1px; }

  #add-button {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-btn);
    justify-content: center;
  }
  #add-button .btn-label { display: none; }
  #add-button .btn-plus { font-size: 22px; }

  .layout {
    display: block;
    position: relative;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 84vw);
    height: 100dvh;
    background: var(--bg);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 30;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  }

  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 20;
  }

  body.sidebar-collapsed .layout { grid-template-columns: 1fr; }

  main { padding: 0 18px 80px; }

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

  .card { border-radius: 16px; }
  .card-title { padding: 8px 10px 10px; font-size: 11px; }
  /* Detail modal becomes a bottom sheet */

  #detail-dialog[open] {
    inset: auto 0 0 0;
    margin: 0;
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    padding: 0;
  }

  #detail-dialog .detail-card {
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    border-radius: 24px 24px 0 0;
    max-height: 92dvh;
    box-shadow: 0 -24px 60px rgba(0, 0, 0, 0.5);
  }

  .drag-handle {
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin: 12px auto 8px;
  }

  .detail-thumb {
    width: 200px;
    height: auto;
    aspect-ratio: 9 / 16;
    margin: 0 20px 16px;
    border-radius: 16px;
    overflow: hidden;
    align-self: flex-start;
  }
  .detail-thumb img { border-radius: 16px; }

  .detail-body { padding: 0 20px 0; gap: 6px; }

  .detail-close { display: none; }

  .inline-title {
    font-size: 20px;
    letter-spacing: -0.2px;
    padding-right: 0;
  }
  .inline-description {
    font-size: 14px;
    min-height: 44px;
  }

  .detail-meta-row {
    margin-top: 8px;
    gap: 6px;
  }
  .select-compact { font-size: 11px; padding: 5px 26px 5px 8px; }
  .chips-input-compact { font-size: 11px; padding: 4px 6px; }

  .detail-actions {
    margin: 16px -20px 0;
    padding: 16px 20px calc(16px + env(safe-area-inset-bottom, 16px));
    border-top: 1px solid var(--border);
  }
  .detail-actions .btn { font-size: 14px; padding: 10px 22px; }
  .detail-actions .btn.danger { padding: 9px 22px; }

  /* Add modal full-width on mobile */
  #add-dialog .add-card {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  #add-dialog[open] {
    inset: 0;
    margin: 0;
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    padding: 0;
  }

  .preview { grid-template-columns: 1fr; gap: 14px; padding: 14px; }
  .preview-thumb { width: min(180px, 60%); align-self: center; }
}

@media (min-width: 761px) {
  body:not(.sidebar-collapsed) main { /* default has sidebar */ }
}
