:root {
  --bg: #0d0e11;
  --panel: #15171b;
  --panel-2: #1c1f25;
  --border: #272b33;
  --text: #ecedf0;
  --muted: #9097a3;
  --faint: #5d636e;
  --accent: #e5322d;
  --accent-2: #ff4b45;
  --accent-soft: rgba(229, 50, 45, 0.14);
  --ok: #2fbf71;
  --radius: 12px;
  --side: 232px;
  --top: 60px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- login ---------- */
#login { position: fixed; inset: 0; display: grid; place-items: center; z-index: 100;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(229,50,45,.18), transparent 60%), var(--bg); }
.login-card { width: min(380px, 92vw); background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 32px; }
.login-card h1 { margin: 14px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), #8f1512);
  display: grid; place-items: center; box-shadow: 0 6px 20px rgba(229,50,45,.35); }
.logo svg { width: 17px; height: 17px; stroke: #fff; }
.field { width: 100%; padding: 11px 13px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; outline: none; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 10px; background: var(--panel-2);
  border: 1px solid var(--border); white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: #242830; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: #ff7b76; }
.btn.block { width: 100%; justify-content: center; margin-top: 12px; padding: 11px; }
.btn.icon { padding: 8px; }
.err { color: #ff7b76; min-height: 20px; margin-top: 8px; font-size: 13px; }

/* ---------- layout ---------- */
#app { display: grid; grid-template-columns: var(--side) 1fr; height: 100%; }
#side { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 12px; gap: 4px; }
#side .brand { padding: 4px 8px 18px; }
.nav { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; color: var(--muted); font-weight: 500; }
.nav:hover { background: var(--panel-2); color: var(--text); }
.nav.active { background: var(--accent-soft); color: #fff; }
.nav.active svg { stroke: var(--accent-2); }
.side-spacer { flex: 1; }
.storage { padding: 12px; border-top: 1px solid var(--border); margin-top: 8px; color: var(--muted); font-size: 12px; }
.meter { height: 5px; background: var(--panel-2); border-radius: 4px; margin: 8px 0 6px; overflow: hidden; }
.meter > div { height: 100%; background: var(--accent); width: 0; transition: width .4s; }
.link-btn { color: var(--muted); font-size: 12px; margin-top: 10px; display: inline-flex; gap: 6px; align-items: center; }
.link-btn:hover { color: var(--text); }

#main { display: flex; flex-direction: column; min-width: 0; height: 100%; }
#top { height: var(--top); display: flex; align-items: center; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--border); flex: none; }
.search { flex: 1; max-width: 560px; position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search input { width: 100%; padding: 9px 12px 9px 38px; background: var(--panel); border: 1px solid var(--border); border-radius: 22px; outline: none; }
.search input:focus { border-color: var(--accent); }
.top-actions { margin-left: auto; display: flex; gap: 8px; }
#content { flex: 1; overflow: auto; padding: 18px 22px 120px; position: relative; }
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; min-height: 38px; }
.page-head h2 { margin: 0; font-size: 20px; font-weight: 650; }
.page-head .grow { flex: 1; }
.crumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 18px; font-weight: 600; }
.crumbs a { color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.crumbs a:hover { background: var(--panel-2); color: var(--text); }
.crumbs a:last-child { color: var(--text); }
.crumbs .sep { color: var(--faint); }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 2px; }
.seg button { padding: 6px 8px; border-radius: 8px; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); }
select.field { width: auto; padding: 7px 10px; }

/* ---------- selection bar ---------- */
#selbar { position: sticky; top: -18px; z-index: 20; margin: -18px -22px 14px; padding: 10px 22px; background: rgba(21,23,27,.96);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#selbar .count { font-weight: 600; margin-right: 8px; }

/* ---------- file list ---------- */
.list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.row { display: grid; grid-template-columns: 34px 44px 1fr 160px 100px 40px; align-items: center; gap: 8px; padding: 6px 10px;
  border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--panel-2); }
.row.sel { background: var(--accent-soft); }
.row.head { cursor: default; color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; background: transparent; }
.row.head:hover { background: transparent; }
.row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.row .sub { color: var(--muted); font-size: 12.5px; }
.ficon { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; background: var(--panel-2); overflow: hidden; }
.ficon img { width: 100%; height: 100%; object-fit: cover; }
.ficon.folder { background: rgba(229,50,45,.12); color: var(--accent-2); }
.check { width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--faint); display: grid; place-items: center; }
.sel .check, .tile.sel .check { background: var(--accent); border-color: var(--accent); }
.check svg { width: 12px; height: 12px; stroke: #fff; stroke-width: 3; opacity: 0; }
.sel .check svg { opacity: 1; }
.more { opacity: .6; }
.row:hover .more { opacity: 1; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; position: relative; user-select: none; }
.card:hover { border-color: #3a3f49; }
.card.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.card .thumb { aspect-ratio: 4/3; background: var(--panel-2); display: grid; place-items: center; color: var(--muted); }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .thumb svg { width: 40px; height: 40px; stroke-width: 1.4; }
.card .meta { padding: 9px 11px; }
.card .meta .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.card .meta .sub { color: var(--muted); font-size: 12px; }
.card .check { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.4); opacity: 0; }
.card:hover .check, .card.sel .check, .selecting .card .check { opacity: 1; }

.empty { text-align: center; color: var(--muted); padding: 70px 20px; }
.empty svg { width: 48px; height: 48px; stroke-width: 1.3; color: var(--faint); margin-bottom: 10px; }
.empty h3 { color: var(--text); margin: 4px 0; font-weight: 600; }

/* ---------- photo timeline ---------- */
.day { margin-bottom: 18px; }
.day-head { display: flex; align-items: center; gap: 10px; font-weight: 600; margin: 4px 0 8px; font-size: 14px; }
.day-head .check { opacity: 0; cursor: pointer; }
.day:hover .day-head .check, .selecting .day-head .check { opacity: 1; }
.month-head { font-size: 22px; font-weight: 700; margin: 26px 0 12px; }
.month-head:first-child { margin-top: 0; }
.justify { display: flex; flex-wrap: wrap; gap: 4px; }
.justify::after { content: ""; flex-grow: 999999; }
.tile { position: relative; height: 200px; overflow: hidden; background: var(--panel-2); cursor: pointer; border-radius: 3px; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.tile.sel img { transform: scale(.9); border-radius: 8px; }
.tile.sel { background: var(--accent-soft); }
.tile .check { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.35); border-color: #fff; opacity: 0; transition: opacity .15s; }
.tile:hover .check, .tile.sel .check, .selecting .tile .check { opacity: 1; }
.tile .badge { position: absolute; bottom: 6px; right: 7px; font-size: 11px; font-weight: 600; background: rgba(0,0,0,.55); padding: 2px 6px; border-radius: 6px; display: flex; align-items: center; gap: 4px; }
.tile .badge svg { width: 12px; height: 12px; }
.tile .fav { position: absolute; bottom: 6px; left: 7px; color: #fff; }
.tile .fav svg { width: 15px; height: 15px; fill: #fff; }
.tile .noimg { width: 100%; height: 100%; display: grid; place-items: center; color: var(--faint); }
#sentinel { height: 40px; }

/* ---------- albums ---------- */
.album-card .thumb { aspect-ratio: 1; }
.album-new .thumb { border: 2px dashed var(--border); background: transparent; }

/* ---------- viewer ---------- */
#viewer { position: fixed; inset: 0; background: #000; z-index: 72; display: flex; }
#viewer .stage { flex: 1; position: relative; display: grid; place-items: center; min-width: 0; }
#viewer .stage img, #viewer .stage video { max-width: 100%; max-height: 100vh; object-fit: contain; display: block; }
#viewer .stage iframe { width: min(1000px, 100%); height: calc(100vh - 64px); margin-top: 64px; border: 0; background: #fff; }
#viewer .stage pre { max-width: min(1000px, 94vw); max-height: 86vh; overflow: auto; background: var(--panel); padding: 20px; border-radius: 10px; white-space: pre-wrap; font: 13px/1.5 ui-monospace, Menlo, monospace; }
.vbar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 6px; padding: 12px 14px;
  background: linear-gradient(rgba(0,0,0,.65), transparent); z-index: 3; }
.vbar .title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.vbtn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; }
.vbtn:hover { background: rgba(255,255,255,.14); }
.vbtn.on svg { stroke: var(--accent-2); }
.vbtn.fav.on svg { fill: var(--accent-2); }
.vnav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 3; width: 48px; height: 48px; background: rgba(0,0,0,.4); }
.vnav.prev { left: 14px; } .vnav.next { right: 14px; }
.vother { text-align: center; color: var(--muted); }
.vother svg { width: 70px; height: 70px; stroke-width: 1.2; }
.vother h3 { color: #fff; margin: 12px 0 4px; }
#vinfo { width: 340px; background: var(--panel); border-left: 1px solid var(--border); overflow: auto; padding: 20px; flex: none; }
#vinfo h4 { margin: 0 0 16px; font-size: 16px; }
.irow { display: flex; gap: 14px; margin-bottom: 16px; }
.irow svg { color: var(--muted); margin-top: 2px; }
.irow .k { font-weight: 500; word-break: break-word; }
.irow .v { color: var(--muted); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 3px 9px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 20px; font-size: 12px; color: var(--muted); }
.chip:hover { color: var(--text); }
.spinner { width: 28px; height: 28px; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modals, menus, toasts ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 80; display: grid; place-items: center; padding: 16px; }
.modal { width: min(460px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 22px; max-height: 88vh; display: flex; flex-direction: column; }
.modal h3 { margin: 0 0 14px; font-size: 18px; }
.modal .body { overflow: auto; flex: 1; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal label { display: block; color: var(--muted); font-size: 13px; margin: 12px 0 6px; }
.pick { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; cursor: pointer; }
.pick:hover { background: var(--panel-2); }
.pick.on { background: var(--accent-soft); }
.linkbox { display: flex; gap: 8px; margin-top: 10px; }
.linkbox input { flex: 1; }
#menu { position: fixed; z-index: 90; background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 6px; min-width: 200px; box-shadow: 0 14px 40px rgba(0,0,0,.5); }
#menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; text-align: left; }
#menu button:hover { background: #2a2e36; }
#menu button.danger { color: #ff7b76; }
#menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px 2px; }
#toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 95; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #24272e; border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: up .2s; }
@keyframes up { from { transform: translateY(10px); opacity: 0; } }

/* ---------- uploads ---------- */
#uploads { position: fixed; right: 20px; bottom: 20px; width: 360px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; z-index: 70;
  box-shadow: 0 20px 50px rgba(0,0,0,.5); overflow: hidden; }
#uploads .uh { display: flex; align-items: center; gap: 8px; padding: 12px 14px; font-weight: 600; border-bottom: 1px solid var(--border); }
#uploads .uh .grow { flex: 1; }
#uploads .ul { max-height: 280px; overflow: auto; }
#uploads.min .ul { display: none; }
.uitem { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 9px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.uitem .n { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.uitem .s { color: var(--muted); font-size: 12px; }
.uitem .bar { grid-column: 1 / -1; height: 3px; background: var(--panel-2); border-radius: 2px; overflow: hidden; }
.uitem .bar div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.uitem.done .bar div { background: var(--ok); }
.uitem.fail .s { color: #ff7b76; }
#dropzone { position: fixed; inset: 0; z-index: 75; background: rgba(229,50,45,.12); border: 3px dashed var(--accent); display: grid; place-items: center; pointer-events: none; }
#dropzone div { background: var(--panel); padding: 18px 26px; border-radius: 14px; font-weight: 600; font-size: 16px; display: flex; gap: 10px; align-items: center; }

/* ---------- mobile ---------- */
@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; grid-template-rows: minmax(0,1fr) auto; height: 100dvh; }
  #main { height: auto; min-height: 0; }
  #side { order: 2; flex-direction: row; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border); gap: 0; justify-content: space-around; }
  #side .brand, .side-spacer, .storage, .nav.desk { display: none; }
  .nav { flex-direction: column; gap: 3px; font-size: 10.5px; padding: 6px 8px; flex: 1; align-items: center; }
  .nav.active { background: transparent; color: var(--accent-2); }
  #top { padding: 0 12px; gap: 8px; }
  #top .brand-m { display: flex !important; }
  .top-actions .label { display: none; }
  #content { padding: 14px 12px 100px; }
  #selbar { margin: -14px -12px 12px; padding: 10px 12px; top: -14px; }
  #selbar .label { display: none; }
  .row { grid-template-columns: 30px 40px 1fr 36px; }
  .row .c-date, .row .c-size { display: none; }
  .tile { height: 110px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  #viewer { flex-direction: column; }
  #vinfo { width: 100%; max-height: 45vh; border-left: 0; border-top: 1px solid var(--border); }
  .vnav { display: none; }
  #uploads { right: 10px; left: 10px; width: auto; bottom: 74px; }
}
