:root {
  color-scheme: light;
  --ground: #f4f3f1;
  --surface: #ffffff;
  --raised: #e9e8e6;
  --border: #deddd9;
  --rule: #ecebe8;
  --control: #cfceca;
  --text: #111110;
  --muted: #6b6a67;
  --accent: #141414;
  --data: #1d5fbf;
  --negative: #a62228;
  --positive: #245f35;
  --radius-card: 8px;
  --radius-control: 6px;
  --sidebar-width: 248px;
  --ease-out: cubic-bezier(.23, 1, .32, 1);
  font-family: "Geist", Inter, system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; color: var(--text); background: var(--ground); font-size: 14px; line-height: 1.45; }
button, input, select, textarea { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
.mobile-topbar { display: none; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 30px 20px 22px; display: flex; flex-direction: column; border-right: 1px solid var(--border); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-rule, .auth-brand > span, .admin-brand > span { width: 3px; height: 38px; flex: 0 0 auto; background: var(--data); border-radius: 2px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; font-weight: 500; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.sidebar-close { display: none; }
.nav-group { margin-top: 54px; }
.nav-label { margin: 0 10px 10px; color: var(--muted); font-size: 12px; }
.sidebar-nav { display: grid; gap: 2px; }
.nav-button { width: 100%; min-height: 34px; padding: 7px 10px; display: flex; align-items: center; gap: 10px; color: #4f4e4b; background: transparent; border: 0; border-radius: var(--radius-control); text-align: left; cursor: pointer; transition: color 140ms var(--ease-out), background-color 140ms var(--ease-out), transform 120ms var(--ease-out); }
.nav-button.active { color: var(--text); background: var(--raised); font-weight: 500; }
.nav-count { margin-left: auto; color: var(--muted); font-family: "Geist Mono", ui-monospace, monospace; font-size: 12px; font-variant-numeric: tabular-nums; }
.sidebar-foot { margin-top: auto; padding: 15px 10px 0; border-top: 1px solid var(--border); }
.sidebar-foot p { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.sidebar-foot form { display: inline; }
.quiet-link, .quiet-button { display: block; width: fit-content; margin: 0 0 7px; padding: 0; color: var(--text); background: none; border: 0; font-size: 12px; text-decoration: none; cursor: pointer; }

.content { width: min(100%, 1120px); min-width: 0; padding: 34px clamp(28px, 5vw, 64px) 80px; }
.page-header { min-height: 58px; display: flex; align-items: flex-start; justify-content: space-between; gap: 32px; }
h1 { margin: 0; font-size: 24px; line-height: 1.2; letter-spacing: -.025em; font-weight: 500; }
.page-header p { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.data-number { color: var(--data); font-family: "Geist Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; font-weight: 500; }
.catalog-date { display: grid; justify-items: end; gap: 2px; color: var(--muted); font-size: 12px; }
.catalog-date time { color: var(--text); font-family: "Geist Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.search-field { height: 44px; margin-top: 28px; padding: 0 12px; display: flex; align-items: center; gap: 10px; color: var(--muted); background: var(--surface); border: 1px solid var(--control); border-radius: var(--radius-card); transition: border-color 140ms var(--ease-out), outline-color 140ms var(--ease-out); }
.search-field:focus-within { border-color: var(--accent); outline: 3px solid rgba(20, 20, 20, .08); }
.search-field input { min-width: 0; flex: 1; color: var(--text); background: transparent; border: 0; outline: 0; }
.search-field input::placeholder { color: #8a8986; }
kbd { padding: 3px 6px; color: var(--muted); background: var(--ground); border: 1px solid var(--border); border-radius: 4px; font: 11px/1.1 "Geist Mono", ui-monospace, monospace; }
.mobile-filters { display: none; }
.toolbar { min-height: 52px; margin-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--border); }
#result-label { margin: 0; color: var(--muted); font-size: 12px; }
#result-label strong { color: var(--data); font-family: "Geist Mono", ui-monospace, monospace; font-weight: 500; font-variant-numeric: tabular-nums; }
.sort-field { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; }
.sort-field select { height: 34px; padding: 0 30px 0 10px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-control); outline: 0; }
.resource-list { display: grid; }
.resource-cover { display: none; }
.resource-logo { position: relative; width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); font-size: 12px; font-weight: 500; }
.resource-logo img { position: absolute; inset: 5px; width: 26px; height: 26px; object-fit: contain; background: white; border-radius: 3px; }
.catalog-controls { display: flex; align-items: center; gap: 16px; }
.view-switch { display: flex; padding: 3px; border: 1px solid var(--border); border-radius: 8px; }
.view-switch button { min-height: 30px; padding: 0 10px; color: var(--muted); background: transparent; border: 0; border-radius: 5px; cursor: pointer; font-size: 12px; }
.view-switch button[aria-pressed="true"] { color: var(--text); background: white; }
.resource-list.is-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; padding-top: 20px; }
.is-cards .resource-row { position: relative; display: flex; flex-direction: column; min-width: 0; padding: 0 0 18px; gap: 0; overflow: hidden; background: white; border: 1px solid var(--border); border-radius: 12px; }
.is-cards .resource-cover { position: relative; display: block; width: 100%; aspect-ratio: 16 / 9; background: #e1eaf2; overflow: hidden; }
.resource-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-caption { position: absolute; left: 12px; bottom: 12px; padding: 4px 8px; color: #252724; background: #fff; border-radius: 4px; font-size: 11px; }
.is-cards .resource-logo { margin: 16px 18px 12px; }
.is-cards .row-copy { padding: 0 18px; width: 100%; flex: 1; }
.is-cards .title-line { flex-wrap: wrap; }
.is-cards .description { min-height: 58px; margin-top: 9px; }
.is-cards .tags { margin: 12px 0; }
.is-cards .row-meta { display: flex; justify-content: space-between; width: 100%; margin-top: 12px; padding: 14px 18px 0; border-top: 1px solid var(--rule); font-size: 11px; }
.is-cards .row-actions { position: static; align-self: flex-end; margin: -36px 12px 0; }
.is-cards .row-meta { padding-right: 94px; min-height: 38px; }
.media-fields { display: grid; gap: 14px; }
.media-help { margin: 0; color: var(--muted); font-size: 13px; }
.image-upload { display: grid; gap: 10px; padding: 16px; border: 1px solid var(--border); border-radius: 8px; }
.upload-preview { width: 100%; aspect-ratio: 16 / 9; display: grid; place-items: center; overflow: hidden; border-radius: 6px; background: var(--ground); color: var(--muted); font-size: 13px; }
.upload-preview img { width: 100%; height: 100%; object-fit: contain; }
.upload-preview-logo { width: 120px; aspect-ratio: 1; }
.upload-preview-logo > span { padding: 12px; text-align: center; }
.image-upload input[type="file"] { width: 100%; min-width: 0; padding: 8px; font-size: 12px; }
.image-upload input::file-selector-button { margin-right: 10px; padding: 8px 12px; color: white; background: var(--accent); border: 0; border-radius: 5px; cursor: pointer; }
.upload-error { margin: 0; color: var(--negative); font-size: 13px; }
@media (max-width: 1150px) { .resource-list.is-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 800px) {
  .catalog-controls { gap: 8px; }
  .sort-field > span { display: none; }
  .resource-logo { width: 28px; height: 28px; font-size: 10px; }
  .resource-logo img { inset: 3px; width: 20px; height: 20px; }
  .is-cards .resource-logo { width: 38px; height: 38px; }
  .is-cards .resource-logo img { inset: 5px; width: 26px; height: 26px; }
}
@media (max-width: 520px) {
  .toolbar { flex-wrap: wrap; padding: 10px 0; }
  .catalog-controls { width: 100%; justify-content: space-between; }
  .resource-list.is-cards { grid-template-columns: 1fr; }
}
.resource-row { min-height: 112px; padding: 18px 8px; display: grid; grid-template-columns: 38px minmax(0, 1fr) 92px 76px; gap: 14px; align-items: start; border-bottom: 1px solid var(--border); transition: background-color 140ms var(--ease-out); }
.row-index { padding-top: 2px; color: #9b9a97; font: 12px/1.4 "Geist Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.row-copy { min-width: 0; }
.title-line { display: flex; align-items: center; gap: 8px; }
.resource-title { color: var(--text); font-size: 16px; line-height: 1.25; font-weight: 500; text-decoration: none; }
.description { max-width: 640px; margin: 6px 0 9px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.tags { display: flex; flex-wrap: wrap; gap: 5px 10px; }
.tag { color: #62615d; font-size: 12px; }
.tag + .tag::before { content: "·"; margin-right: 10px; color: #b3b2ae; }
.favorite-label { padding: 2px 6px; color: #3d3d3d; background: var(--raised); border-radius: 4px; font-size: 11px; }
.row-meta { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.row-meta time { font-family: "Geist Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.row-meta span { color: var(--text); }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.icon-button { width: 36px; height: 36px; padding: 0; display: inline-grid; place-items: center; color: #676663; background: transparent; border: 0; border-radius: var(--radius-control); cursor: pointer; text-decoration: none; transition: color 120ms var(--ease-out), background-color 120ms var(--ease-out), transform 120ms var(--ease-out); }
.favorite-button.active { color: var(--text); }
.favorite-button.active svg { fill: currentColor; }
.open-link { color: var(--text); }
.empty-state { max-width: 440px; margin: 84px auto; text-align: center; }
.empty-state > svg { width: 28px; height: 28px; color: var(--muted); }
.empty-state h2 { margin: 15px 0 5px; font-size: 18px; font-weight: 500; }
.empty-state p { margin: 0; color: var(--muted); }

.primary-button, .secondary-button { min-height: 38px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-control); font-weight: 500; text-decoration: none; cursor: pointer; transition: transform 120ms var(--ease-out), background-color 120ms var(--ease-out); }
.primary-button { color: #fff; background: var(--accent); border: 1px solid var(--accent); }
.secondary-button { color: var(--text); background: var(--raised); border: 1px solid var(--raised); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.auth-body { min-height: 100vh; padding: 36px 20px; display: grid; place-items: center; }
.auth-card { width: min(100%, 420px); padding: 30px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
.setup-card { width: min(100%, 480px); }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand strong, .auth-brand small { display: block; }
.auth-brand strong { font-weight: 500; }
.auth-brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.auth-card h1 { margin-top: 44px; }
.auth-copy { margin: 8px 0 24px; color: var(--muted); }
.form-stack { display: grid; gap: 16px; }
.form-stack label, .editor-form label, .inline-form label, .user-form label { display: grid; gap: 6px; }
.form-stack label > span, .editor-form label > span, .inline-form label > span, .user-form label > span, fieldset legend { font-size: 12px; font-weight: 500; }
.form-stack small, .editor-form small { color: var(--muted); font-size: 12px; }
input, textarea, select { color: var(--text); background: var(--surface); border: 1px solid var(--control); border-radius: var(--radius-control); outline: 0; }
input, select { min-height: 40px; padding: 0 11px; }
textarea { padding: 10px 11px; resize: vertical; }
.form-error, .flash { margin-bottom: 18px; padding: 11px 12px; border: 1px solid var(--border); border-radius: var(--radius-control); font-size: 13px; }
.form-error { color: #6f181d; background: #fff4f3; border-color: #e9c9c7; }
.flash-success { color: #174d27; background: #f1f8f3; border-color: #c9dfcf; }

.admin-body { background: #f7f7f6; }
.admin-topbar { min-height: 58px; padding: 0 24px; display: flex; align-items: center; gap: 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.admin-brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 500; text-decoration: none; }
.admin-brand > span { height: 28px; }
.admin-topbar nav { display: flex; align-items: center; gap: 20px; }
.admin-topbar nav a { color: var(--muted); font-size: 13px; text-decoration: none; }
.nav-logout { margin: 0; }
.nav-logout button { padding: 0; color: var(--muted); background: none; border: 0; font-size: 13px; cursor: pointer; }
.admin-topbar > small { margin-left: auto; color: var(--muted); font-size: 12px; }
.admin-content { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 36px 0 80px; }
.admin-title { display: flex; align-items: center; justify-content: space-between; min-height: 42px; }
.admin-actions { margin: -42px 0 20px; display: flex; justify-content: flex-end; }
.stats-grid { margin-top: 22px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stats-grid > div { min-height: 112px; padding: 18px; display: flex; flex-direction: column; justify-content: space-between; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
.stats-grid span { color: var(--muted); font-size: 12px; }
.stats-grid strong { font: 500 30px/1 "Geist Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.admin-section { margin-top: 28px; padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
.compact-section { max-width: 880px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.admin-section h2 { margin: 0 0 16px; font-size: 16px; font-weight: 500; }
.section-heading h2 { margin: 0; }
.section-heading a, .field-link { color: var(--text); font-size: 12px; }
.admin-table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th { padding: 9px 10px; color: var(--muted); border-bottom: 1px solid var(--border); text-align: left; font-size: 12px; font-weight: 400; white-space: nowrap; }
.admin-table td { padding: 13px 10px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table td strong, .admin-table td small { display: block; }
.admin-table td strong { font-weight: 500; }
.admin-table td small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.admin-table a, .text-button, .danger-link { color: var(--text); background: none; border: 0; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.danger-link { color: var(--negative); }
.table-actions { position: relative; display: flex; justify-content: flex-end; align-items: center; gap: 10px; white-space: nowrap; }
.table-actions form { display: inline-flex; align-items: center; gap: 8px; }
.status { padding: 3px 7px; color: #4e4d49; background: var(--raised); border-radius: 4px; font-size: 11px; white-space: nowrap; }
.status-live { color: #174d27; background: #e5f2e8; }
.inline-form { display: grid; grid-template-columns: minmax(240px, 1fr) 120px auto; gap: 12px; align-items: end; }
.user-form { display: grid; grid-template-columns: repeat(3, minmax(130px, 1fr)) 150px auto; gap: 12px; align-items: end; }
.order-input { width: 78px; }
.editor-form { margin-top: 22px; display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 18px; align-items: start; }
.form-main, .form-side { padding: 22px; display: grid; gap: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
fieldset { margin: 0; padding: 0; border: 0; }
fieldset legend { margin-bottom: 9px; }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.check-row, .switch-row { min-height: 34px; display: flex !important; grid-template-columns: auto 1fr; flex-direction: row; align-items: center; gap: 8px !important; }
.check-row input, .switch-row input { min-height: 0; width: 16px; height: 16px; }
.field-link { display: inline-block; margin-top: 10px; }
.form-buttons { display: flex; gap: 8px; }
.password-form { padding: 8px; position: absolute; right: 20px; z-index: 5; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-control); }

@media (hover: hover) and (pointer: fine) {
  .nav-button:hover { color: var(--text); background: #ecebe8; }
  .resource-row:hover { background: rgba(255, 255, 255, .48); }
  .resource-title:hover, .quiet-link:hover, .quiet-button:hover, .admin-topbar nav a:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
  .icon-button:hover { color: var(--text); background: var(--raised); }
  .nav-button:active, .icon-button:active, .primary-button:active, .secondary-button:active { transform: scale(.97); }
}

@media (max-width: 800px) {
  body:not(.auth-body):not(.admin-body) { padding-top: 48px; }
  body.menu-open { overflow: hidden; }
  .mobile-topbar { position: fixed; inset: 0 0 auto; z-index: 30; height: 48px; padding: 0 12px; display: grid; grid-template-columns: 36px 1fr 36px; align-items: center; gap: 8px; background: var(--ground); border-bottom: 1px solid var(--border); font-size: 14px; font-weight: 500; }
  .mobile-topbar .icon-button { justify-self: start; }
  .mobile-topbar .data-number { justify-self: end; font-size: 12px; }
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0; z-index: 40; width: 100%; height: 100dvh; padding: 24px 20px; background: var(--ground); transform: translateX(-100%); visibility: hidden; transition: transform 180ms var(--ease-out), visibility 0s linear 180ms; }
  .sidebar.is-open { transform: translateX(0); visibility: visible; transition-delay: 0s; }
  .sidebar-close { display: inline-grid; }
  .nav-group { margin-top: 42px; }
  .nav-button { min-height: 44px; font-size: 15px; }
  .content { width: 100%; padding: 26px 16px 56px; }
  .page-header { min-height: 0; }
  h1 { font-size: 22px; }
  .catalog-date { display: none; }
  .search-field { margin-top: 22px; }
  .mobile-filters { margin: 12px -16px 0; padding: 0 16px 4px; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
  .mobile-filters::-webkit-scrollbar { display: none; }
  .mobile-filter { min-height: 34px; padding: 0 10px; flex: 0 0 auto; color: var(--muted); background: transparent; border: 1px solid var(--border); border-radius: var(--radius-control); font-size: 13px; }
  .mobile-filter.active { color: var(--text); background: var(--raised); border-color: var(--raised); }
  .toolbar { margin-top: 8px; }
  #result-label { font-size: 13px; }
  .resource-row { min-height: 0; padding: 17px 0; grid-template-columns: 28px minmax(0, 1fr) 72px; gap: 10px; }
  .row-meta { display: none; }
  .row-actions { gap: 0; }
  .description { margin-top: 5px; }
  .admin-topbar { padding: 12px 16px; align-items: flex-start; flex-wrap: wrap; }
  .admin-topbar nav { width: 100%; overflow-x: auto; gap: 16px; }
  .admin-topbar nav a { white-space: nowrap; }
  .admin-topbar > small { display: none; }
  .admin-content { width: min(100% - 24px, 1180px); padding-top: 24px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .editor-form { grid-template-columns: 1fr; }
  .inline-form, .user-form { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  kbd { display: none; }
  .sort-field > span { display: none; }
  .resource-row { grid-template-columns: 24px minmax(0, 1fr) 36px; }
  .open-link { display: none; }
  .favorite-button { width: 34px; height: 34px; }
  .resource-title { font-size: 15px; }
  .description { font-size: 13px; }
  .tag { font-size: 13px; }
  .auth-card { padding: 24px 20px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stats-grid > div { min-height: 92px; padding: 14px; }
  .admin-section { padding: 14px; }
  .check-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
