:root{
  --bg:#ffffff;
  --text:#111827;
  --muted:#6b7280;
  --card:#f9fafb;
  --border:#e5e7eb;
  --primary:#2563eb;
  --danger:#dc2626;
  --hover-size:480px;
}

body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  background:var(--bg);
  color:var(--text);
  min-height:100vh;
  display:flex;
  flex-direction:column;
}

body.has-page-background{
  background-color:var(--bg);
  background-image:
    linear-gradient(rgba(255,255,255,0.72), rgba(255,255,255,0.72)),
    var(--page-background-image);
  background-repeat:no-repeat;
  background-position:center center;
  background-size:cover;
  background-attachment:fixed;
}

html,
body{
  scrollbar-width:none;
  -ms-overflow-style:none;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar{
  width:0;
  height:0;
  display:none;
}

body.theme-dark{
  --bg:#0b1020;
  --text:#e5e7eb;
  --muted:#9ca3af;
  --card:#0f172a;
  --border:#243046;
}

body.theme-dark.has-page-background{
  background-image:
    linear-gradient(rgba(11,16,32,0.72), rgba(11,16,32,0.72)),
    var(--page-background-image);
}

a{ color:var(--primary); text-decoration:none; }
a:hover{ text-decoration:underline; }

.topbar{
  display:grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap:16px;
  align-items:center;
  padding:0 16px;
  min-height:56px;
  border-bottom:1px solid var(--border);
  background:var(--card);
  z-index:20;
}

.brand a{ font-weight:700; color:var(--text); }
.brand-link,
.topbar .nav a,
.topbar .nav-right .btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:32px;
  line-height:1;
  box-sizing:border-box;
  white-space:nowrap;
}

.brand-link{
  gap:8px;
}

.brand-logo{
  width:22px;
  height:22px;
  object-fit:contain;
  display:block;
}

.topbar .nav{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:12px;
  min-width:0;
  flex-wrap:wrap;
}

.topbar .nav a{
  margin-right:0;
  color:var(--text);
  opacity:.9;
}

.topbar .nav a:hover{ opacity:1; text-decoration:none; }

.topbar-actions,
.topbar .nav-right{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:nowrap;
}

.topbar .nav-right form{
  display:flex;
  margin:0;
}

.topbar .nav-right .btn{
  padding:0 12px;
}

@media (min-width: 1101px){
  .topbar{
    position:fixed;
    top:0;
    left:0;
    right:0;
  }

  body{
    padding-top:56px;
  }
}

@media (max-width: 1100px){
  .topbar{
    position:sticky;
    top:0;
    display:flex;
    flex-wrap:wrap;
  }

  .topbar .nav{
    order:3;
    flex:1 1 100%;
    justify-content:flex-start;
  }

  .topbar .nav-right{
    margin-left:auto;
  }

  body{
    padding-top:0;
  }
}

.container{
  padding:16px;
  max-width: 1200px;
  margin:0 auto;
  width:100%;
  box-sizing:border-box;
  flex:1 0 auto;
}

body.media-page .container{
  max-width: 1520px;
}

.site-footer{
  margin-top:auto;
  padding:14px 16px 18px;
  border-top:1px solid var(--border);
  color:var(--muted);
  text-align:center;
  font-size:12px;
  letter-spacing:0;
}

.card{
  border:1px solid var(--border);
  background:var(--card);
  border-radius:10px;
  padding:14px;
  margin:14px 0;
}

h1{ font-size:20px; margin:0 0 12px 0;}
h2{ font-size:16px; margin:0 0 10px 0;}

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

.grid-2{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
}
.grid-span-2{
  grid-column:1 / -1;
}
@media(max-width: 900px){
  .grid-2{ grid-template-columns: 1fr; }
}

label{
  display:flex;
  flex-direction:column;
  gap:6px;
  font-size:13px;
}

input, select, textarea{
  padding:8px 10px;
  border:1px solid var(--border);
  border-radius:8px;
  background:transparent;
  color:var(--text);
  outline:none;
}
textarea{ resize:vertical; }

.form-inline{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:flex-end;
}
.form-inline label{ width:auto; }

.checkbox{
  flex-direction:row;
  align-items:center;
  gap:8px;
}

.btn{
  background:var(--primary);
  color:white;
  border:none;
  border-radius:8px;
  padding:8px 12px;
  cursor:pointer;
  text-decoration:none;
  display:inline-block;
  font-size:13px;
}
.btn:hover{ filter:brightness(1.05); }
.btn-secondary{
  background:transparent;
  color:var(--text);
  border:1px solid var(--border);
}
.btn-danger{
  background:var(--danger);
}

.actions{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items:center;
}

.table-wrap{
  overflow:auto;
  border:1px solid var(--border);
  border-radius:10px;
}
.table{
  width:100%;
  border-collapse:collapse;
  font-size:13px;
}
.table th, .table td{
  padding:10px 8px;
  border-bottom:1px solid var(--border);
  vertical-align:top;
}
.table thead th{
  position:sticky;
  top:0;
  background:var(--card);
  z-index:5;
}
.table tbody tr:hover{
  background: rgba(37,99,235,0.08);
  cursor:pointer;
}

.models-viewbar{
  display:flex;
  justify-content:flex-end;
  align-items:center;
  margin:10px 0 12px;
}
.view-switch{
  display:inline-grid;
  grid-template-columns: repeat(2, minmax(78px, 1fr));
  border:1px solid var(--border);
  border-radius:8px;
  overflow:hidden;
  background:var(--card);
}
.view-switch-btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:36px;
  padding:0 12px;
  color:var(--muted);
  text-decoration:none;
  border-right:1px solid var(--border);
  font-weight:600;
  white-space:nowrap;
}
.view-switch-btn:last-child{
  border-right:0;
}
.view-switch-btn.active{
  background:var(--primary);
  color:white;
}
.models-grid{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap:14px;
  align-items:start;
}
.model-tile{
  position:relative;
  min-width:0;
  border:1px solid var(--border);
  background:var(--card);
  border-radius:8px;
  overflow:hidden;
  cursor:pointer;
  transition:transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.model-tile:hover{
  transform:translateY(-1px);
  border-color:var(--primary);
  box-shadow:0 8px 24px rgba(15,23,42,.12);
}
.model-tile-check{
  position:absolute;
  top:8px;
  left:8px;
  z-index:2;
  width:28px;
  height:28px;
  display:flex;
  align-items:center;
  justify-content:center;
  border:1px solid var(--border);
  border-radius:8px;
  background:rgba(255,255,255,.88);
}
body.dark .model-tile-check{
  background:rgba(15,23,42,.88);
}
.model-tile-image{
  position:relative;
  aspect-ratio:1 / 1;
  background:rgba(107,114,128,.12);
}
.model-tile-image img{
  width:100%;
  height:100%;
  display:block;
  object-fit:contain;
}
.model-tile-empty{
  position:absolute;
  right:8px;
  bottom:8px;
  padding:3px 7px;
  border-radius:999px;
  background:rgba(220,38,38,.92);
  color:white;
  font-size:12px;
  font-weight:700;
}
.model-tile-body{
  padding:10px 11px 12px;
}
.model-tile-title{
  font-weight:700;
  line-height:1.25;
  overflow-wrap:anywhere;
}
.model-tile-data{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap:4px 10px;
  margin-top:8px;
  color:var(--muted);
  font-size:12px;
  line-height:1.35;
}
.model-tile-data span{
  min-width:0;
  overflow-wrap:anywhere;
}
@media(max-width: 560px){
  .models-viewbar{
    justify-content:stretch;
  }
  .view-switch{
    width:100%;
  }
  .models-grid{
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap:10px;
  }
  .model-tile-body{
    padding:8px;
  }
  .model-tile-data{
    grid-template-columns:1fr;
  }
}

.flash-area{ margin:10px 0; }
.flash{
  border:1px solid var(--border);
  background: var(--card);
  padding:10px;
  border-radius:10px;
  margin-bottom:8px;
}
.flash.ok{ border-color: rgba(16,185,129,0.4); }
.flash.error{ border-color: rgba(220,38,38,0.4); }

.broadcast-notice{
  position:fixed;
  inset:0;
  z-index:10020;
  display:none;
}
.broadcast-notice-backdrop{
  position:absolute;
  inset:0;
  background:rgba(0,0,0,0.52);
}
.broadcast-notice-panel{
  position:relative;
  width:min(720px, calc(100% - 32px));
  max-height:min(80vh, 760px);
  margin:8vh auto 0;
  display:flex;
  flex-direction:column;
  gap:14px;
  border:1px solid var(--border);
  border-radius:12px;
  background:var(--card);
  box-shadow:0 16px 50px rgba(0,0,0,0.28);
  padding:18px;
  overflow:hidden;
}
.broadcast-notice-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
}
.broadcast-notice-body{
  overflow:auto;
  padding-right:4px;
  line-height:1.7;
}
.broadcast-notice-actions{
  justify-content:flex-end;
  padding-top:2px;
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4{
  margin:0 0 10px;
  line-height:1.3;
}
.markdown-body p{
  margin:0 0 10px;
}
.markdown-body ul,
.markdown-body ol{
  margin:0 0 10px 20px;
  padding:0;
}
.markdown-body li{
  margin:4px 0;
}
.markdown-body code{
  padding:2px 4px;
  border-radius:4px;
  background:rgba(127,127,127,0.12);
}
.markdown-body pre{
  margin:0 0 10px;
  padding:12px;
  border-radius:10px;
  overflow:auto;
  background:rgba(127,127,127,0.12);
}
.markdown-body pre code{
  padding:0;
  background:transparent;
}
.markdown-body a{
  word-break:break-all;
}

.hover-preview{
  position:fixed;
  z-index:9999;
  pointer-events:none;
  border:1px solid var(--border);
  background:var(--card);
  border-radius:10px;
  padding:6px;
  box-shadow:0 8px 30px rgba(0,0,0,.25);
}
.hover-preview img{
  display:block;
  max-width: var(--hover-size);
  max-height: var(--hover-size);
  width:auto;
  height:auto;
  border-radius:8px;
}

.thumb{
  max-width:110px;
  max-height:90px;
  border-radius:8px;
  border:1px solid var(--border);
}

.file-thumb{
  width:110px;
  height:90px;
  object-fit:cover;
}

.browser-toolbar{
  display:flex;
  gap:12px;
  flex-wrap:wrap;
  align-items:flex-end;
  margin:8px 0 12px;
}

.browser-path{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items:flex-end;
}

.browser-upload{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items:flex-end;
}

.browser-bulk{
  align-items:center;
}

.browser-directory-tools{
  display:flex;
  gap:12px;
  flex-wrap:wrap;
  align-items:flex-end;
  margin:10px 0 12px;
}

.browser-folder-add{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items:flex-end;
}

.browser-directory-wrap{
  max-height: min(58vh, 640px);
}

.browser-clipboard{
  padding:6px 10px;
  border:1px dashed var(--border);
  border-radius:8px;
  color:var(--muted);
}

.browser-folder,
.browser-file-badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:72px;
  min-height:32px;
  padding:0 10px;
  border-radius:8px;
  border:1px solid var(--border);
  background:rgba(37,99,235,0.06);
  color:var(--text);
}

.file-name{
  max-width:420px;
  word-break:break-all;
}

.file-browser-table td{
  vertical-align:middle;
}

.file-browser-select-head{
  display:inline-flex;
  align-items:center;
  gap:6px;
}

.kv{
  width:100%;
  border-collapse:collapse;
}
.kv th{
  text-align:left;
  width:110px;
  color:var(--muted);
  font-weight:600;
}
.kv td, .kv th{
  padding:8px 6px;
  border-bottom:1px solid var(--border);
}

.page-head{ display:flex; align-items:flex-end; justify-content:space-between; gap:10px; }
.grid-2 > section{ min-width:0; }

body.media-page .media-grid{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap:14px;
  margin:14px 0;
  align-items:start;
}

body.media-page .media-card{
  margin:0;
  min-width:0;
}

body.media-page .media-actions{
  margin-bottom:12px;
}

body.media-page .media-report-grid{
  display:grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap:14px;
  align-items:start;
}

body.media-page .media-card .table-wrap{
  min-width:0;
}

@media(max-width: 1100px){
  body.media-page .media-grid,
  body.media-page .media-report-grid{
    grid-template-columns: 1fr;
  }
}

.carousel-main{
  display:flex;
  align-items:center;
  gap:10px;
}
.carousel-img{
  max-width:100%;
  max-height:420px;
  border-radius:10px;
  border:1px solid var(--border);
  background:transparent;
}
.carousel-caption{ margin-top:8px; }

.cases{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap:10px;
}
@media(max-width: 900px){
  .cases{ grid-template-columns: repeat(2, 1fr); }
}
@media(max-width: 560px){
  .cases{ grid-template-columns: 1fr; }
}
.case-item{
  border:1px solid var(--border);
  border-radius:10px;
  overflow:hidden;
  background:transparent;
}
.case-item img{
  width:100%;
  height:180px;
  object-fit:cover;
  display:block;
}
.case-meta{ padding:10px; }
.case-title{ font-weight:700; margin-bottom:6px; }

/* table header sort links */
.table thead th a{ color:var(--text); text-decoration:none; }
.table thead th a:hover{ text-decoration:underline; }

/* click-to-view hints */
.carousel-img, .case-item img{ cursor:zoom-in; }

/* image viewer (lightbox) */
.img-viewer{
  position:fixed;
  inset:0;
  z-index:10000;
}
.img-viewer-backdrop{
  position:absolute;
  inset:0;
  background:rgba(0,0,0,0.65);
}
.img-viewer-panel{
  position:relative;
  width:calc(100% - 40px);
  height:calc(100% - 40px);
  margin:20px auto;
  background:var(--card);
  border:1px solid var(--border);
  border-radius:12px;
  overflow:hidden;
  display:flex;
  flex-direction:column;
}
.img-viewer-toolbar{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  padding:10px;
  border-bottom:1px solid var(--border);
  flex-wrap:wrap;
}
.img-viewer-actions{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items:center;
}
.img-viewer-body{
  flex:1;
  overflow:auto;
  background:rgba(0,0,0,0.08);
}

.img-viewer-stage{
  min-width:100%;
  min-height:100%;
  display:flex;
  align-items:flex-start;
  justify-content:flex-start;
  padding:20px;
  box-sizing:border-box;
}
body.theme-dark .img-viewer-body{
  background:rgba(255,255,255,0.05);
}
#imgViewerImg{
  display:block;
  max-width:none;
  max-height:none;
  width:auto;
  height:auto;
  /* auto margin centers the image when smaller than the viewer,
     while keeping it scrollable when larger */
  margin:auto;
}
.img-viewer-toast{
  position:absolute;
  top:56px;
  left:12px;
  background:var(--card);
  border:1px solid var(--border);
  padding:6px 10px;
  border-radius:10px;
  font-size:12px;
  color:var(--text);
  box-shadow:0 8px 30px rgba(0,0,0,.25);
}

/* marker for models without any linked/uploaded images */
.noimg{
  color: var(--danger);
  font-weight:700;
  margin-right:2px;
}


/* Back to top */
.back-to-top{
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.12);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
body.theme-dark .back-to-top{
  border-color: rgba(255,255,255,0.16);
}
.back-to-top:active{
  transform: translateY(1px);
}

/* Upload compression status */
.compress-status{
  display: inline-block;
  margin-left: 10px;
  font-size: 12px;
  opacity: 0.75;
}

/* Upload progress UI (compression + upload) */
.upload-progress{
  display: none;
  margin-top: 8px;
  gap: 8px;
  flex-direction: column;
}
.upload-progress-row{
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.upload-progress .progress-text{
  font-size: 12px;
  opacity: 0.8;
  min-width: 160px;
}
.upload-progress progress{
  width: 260px;
  height: 12px;
}
