:root {
  --bg: #ffffff;
  --bg-soft: #f6f8fa;
  --border: #e3e6ea;
  --text: #1f2328;
  --text-dim: #656d76;
  --accent: #1a73e8;
  --accent-soft: #e8f0fe;
  --shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 1px 2px rgba(0, 0, 0, .08);
  --topbar-h: 56px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); overflow: hidden; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; }

/* ---- topbar ---- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: relative;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 18px; }
.brand-mark { color: var(--accent); font-size: 20px; }
.status { font-size: 13px; color: var(--text-dim); display: flex; align-items: center; gap: 10px; }
.status .pill { background: var(--bg-soft); border: 1px solid var(--border); padding: 3px 10px; border-radius: 999px; }
.status .warn { color: #9a6700; background: #fff8c5; border-color: #efd88a; }
.status a { color: var(--accent); text-decoration: none; }

/* ---- layout ---- */
.layout { display: flex; height: calc(100vh - var(--topbar-h)); }

.sidebar {
  width: 260px;
  flex: 0 0 260px;
  border-right: 1px solid var(--border);
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 8px; font-size: 13px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-dim);
}
.btn-add {
  border: 1px solid var(--border); background: var(--bg); color: var(--accent);
  border-radius: 8px; padding: 4px 10px; font-size: 12px; font-weight: 600;
}
.btn-add:hover { background: var(--accent-soft); }
.album-list { overflow-y: auto; padding: 4px 8px 20px; flex: 1; }

.album {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer; user-select: none;
}
.album:hover { background: rgba(0, 0, 0, .04); }
.album.active { background: var(--accent-soft); }
.album-icon { width: 34px; height: 34px; border-radius: 8px; background: #dfe3e8; display: grid; place-items: center; font-size: 16px; flex: 0 0 34px; }
.album.active .album-icon { background: var(--accent); color: #fff; }
.album-body { flex: 1; min-width: 0; }
.album-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.album-sub { font-size: 12px; color: var(--text-dim); }
.album-sync { border: none; background: transparent; color: var(--text-dim); font-size: 15px; border-radius: 6px; padding: 4px; }
.album-sync:hover { background: rgba(0, 0, 0, .08); color: var(--text); }
.album-sync.spinning { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- main ---- */
.main { flex: 1; overflow-y: auto; position: relative; }
.main-head {
  position: sticky; top: 0; z-index: 3; background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(6px); padding: 14px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; min-height: 30px;
}
.main-head:empty { display: none; }
.main-head h1 { font-size: 20px; margin: 0; font-weight: 600; }
.main-head .meta { font-size: 13px; color: var(--text-dim); }
.head-actions { display: flex; gap: 8px; align-items: center; }
.btn {
  border: 1px solid var(--border); background: var(--bg); border-radius: 8px;
  padding: 7px 14px; font-size: 13px; font-weight: 600; color: var(--text);
}
.btn:hover { background: var(--bg-soft); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1765cc; }
.uploader-filter {
  border: 1px solid var(--border); background: var(--bg); border-radius: 8px;
  padding: 7px 12px; font-size: 13px; font-weight: 500; color: var(--text);
  max-width: 220px; cursor: pointer; font-family: inherit;
}
.uploader-filter:hover { background: var(--bg-soft); }
.uploader-filter:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.gallery { padding: 8px 24px 60px; }
.day-group { margin-top: 18px; }
.day-label { font-size: 14px; font-weight: 600; margin: 6px 2px 10px; color: var(--text); }
.row { display: flex; margin-bottom: 4px; }
.tile {
  position: relative; overflow: hidden; background: var(--bg-soft); cursor: pointer;
  margin-right: 4px; border-radius: 3px; flex: 0 0 auto;
}
.tile:last-child { margin-right: 0; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; background: #e9edf1; }
.tile.noimg { display: grid; place-items: center; color: var(--text-dim); font-size: 26px; }
.tile:hover { filter: brightness(.94); }
.badge {
  position: absolute; bottom: 6px; right: 6px; background: rgba(0, 0, 0, .62); color: #fff;
  font-size: 11px; padding: 1px 6px; border-radius: 4px; display: flex; gap: 4px; align-items: center;
  font-variant-numeric: tabular-nums;
}
.play {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
}
.play span { width: 44px; height: 44px; border-radius: 50%; background: rgba(0, 0, 0, .45); color: #fff; display: grid; place-items: center; font-size: 18px; padding-left: 3px; }

.sentinel { height: 1px; }
.empty { padding: 60px 24px; text-align: center; color: var(--text-dim); font-size: 15px; line-height: 1.6; }
.empty code { background: var(--bg-soft); padding: 2px 8px; border-radius: 6px; border: 1px solid var(--border); font-size: 13px; }
.empty.hidden { display: none; }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); display: grid; place-items: center; z-index: 40; }
.modal.hidden { display: none; }
.modal-card { background: var(--bg); width: 460px; max-width: 92vw; max-height: 80vh; border-radius: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; }
.icon-btn { border: none; background: transparent; font-size: 16px; color: var(--text-dim); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--bg-soft); }
.search { margin: 14px 18px 6px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; }
.dialog-list { overflow-y: auto; padding: 6px 10px 14px; }
.dialog {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px; cursor: pointer;
}
.dialog:hover { background: var(--bg-soft); }
.dialog .d-icon { width: 36px; height: 36px; border-radius: 50%; background: #dfe3e8; display: grid; place-items: center; font-size: 15px; flex: 0 0 36px; }
.dialog .d-body { flex: 1; min-width: 0; }
.dialog .d-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dialog .d-kind { font-size: 12px; color: var(--text-dim); text-transform: capitalize; }
.dialog .d-added { font-size: 12px; color: var(--text-dim); }

/* ---- lightbox ---- */
.lightbox { position: fixed; inset: 0; background: rgba(15, 17, 20, .96); z-index: 50; display: flex; flex-direction: column; }
.lightbox.hidden { display: none; }
.lb-stage { flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; padding: 40px 64px 8px; overflow: hidden; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; border-radius: 4px; }
.lb-loading { color: #cfd4da; font-size: 14px; }
.lb-btn { position: absolute; background: rgba(255, 255, 255, .1); color: #fff; border: none; border-radius: 50%; width: 44px; height: 44px; font-size: 22px; display: grid; place-items: center; z-index: 2; }
.lb-btn:hover { background: rgba(255, 255, 255, .22); }
.lb-close { top: 18px; right: 20px; }
.lb-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 16px; top: 50%; transform: translateY(-50%); }
.lb-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 24px 20px; color: #e7eaee; }
.lb-caption { font-size: 14px; max-width: 70%; white-space: pre-wrap; overflow: hidden; max-height: 60px; }
.lb-download { background: rgba(255, 255, 255, .12); padding: 9px 16px; border-radius: 8px; text-decoration: none; font-size: 13px; font-weight: 600; white-space: nowrap; }
.lb-download:hover { background: rgba(255, 255, 255, .24); }

/* ---- selection & multi-select ---- */
.tile-checkbox {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 5;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid #fff;
  background: rgba(0, 0, 0, .3);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
  user-select: none;
}
.selection-mode .tile-checkbox {
  display: flex;
}
.tile.selected .tile-checkbox {
  background: var(--accent);
  border-color: var(--accent);
}
.tile.selected {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}
.selection-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2328;
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .24);
  z-index: 100;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s linear;
}
.selection-bar.hidden {
  transform: translate(-50%, 100px);
  opacity: 0;
  pointer-events: none;
}
.selection-bar span {
  font-size: 14px;
  font-weight: 500;
}
.btn-selection {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, .3);
  color: #fff;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.btn-selection:hover {
  background: rgba(255, 255, 255, .12);
}
.btn-selection-primary {
  background: var(--accent);
  border-color: var(--accent);
}
.btn-selection-primary:hover {
  background: #1765cc;
}

/* ---- document tile ---- */
.tile.noimg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #e9edf1;
  color: var(--text-dim);
  padding: 12px;
  text-align: center;
}
.tile.noimg div:first-child {
  font-size: 32px;
  margin-bottom: 6px;
}
.tile-doc-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 4px 6px 0;
  border-top: 1px solid rgba(0,0,0,0.06);
  position: absolute;
  bottom: 8px;
  left: 0;
  box-sizing: border-box;
}

/* ---- lightbox document card ---- */
.lb-document-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #24292f;
  border: 1px solid #30363d;
  padding: 48px 32px;
  border-radius: 12px;
  max-width: 440px;
  width: 90%;
  color: #fff;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .6);
}
.lb-doc-icon {
  font-size: 64px;
  margin-bottom: 16px;
}
.lb-doc-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  word-break: break-all;
  line-height: 1.4;
}
.lb-doc-size {
  font-size: 13px;
  color: #8b949e;
  margin-bottom: 24px;
}

/* ---- hamburger toggle (hidden on desktop) ---- */
.sidebar-toggle {
  display: none;
  border: none;
  background: transparent;
  font-size: 22px;
  color: var(--text);
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.sidebar-toggle:hover { background: var(--bg-soft); }

/* ---- sidebar overlay backdrop (mobile only) ---- */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  z-index: 5;
}
.sidebar-backdrop.visible { display: block; }

/* ---- responsive: tablets & phones ---- */
@media (max-width: 768px) {
  .sidebar-toggle { display: block; }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    z-index: 6;
    width: 280px;
    box-shadow: 4px 0 16px rgba(0, 0, 0, .15);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }

  .main-head {
    padding: 10px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .main-head h1 { font-size: 16px; }
  .head-actions {
    flex-wrap: wrap;
    gap: 6px;
  }
  .head-actions .btn,
  .head-actions .uploader-filter {
    font-size: 12px;
    padding: 6px 10px;
  }
  .uploader-filter { max-width: 160px; }

  .gallery { padding: 4px 6px 60px; }
  .day-label { font-size: 13px; margin: 4px 2px 6px; }

  /* lightbox adjustments */
  .lb-stage { padding: 50px 4px 4px; }
  .lb-bar { padding: 8px 12px 16px; flex-wrap: wrap; gap: 8px; }
  .lb-caption { max-width: 100%; font-size: 13px; }
  .lb-download { font-size: 12px; padding: 7px 12px; }
  .lb-prev { left: 4px; }
  .lb-next { right: 4px; }
  .lb-close { top: 8px; right: 8px; }
  .lb-btn { width: 36px; height: 36px; font-size: 18px; }

  /* selection bar */
  .selection-bar { padding: 8px 14px; gap: 10px; bottom: 16px; }
  .selection-bar span { font-size: 13px; }
  .btn-selection { font-size: 12px; padding: 5px 10px; }
}

/* ---- responsive: small phones ---- */
@media (max-width: 480px) {
  .topbar { padding: 0 12px; }
  .brand-name { font-size: 15px; }
  .status .pill { font-size: 11px; padding: 2px 8px; }

  .gallery { padding: 2px 2px 60px; }
  .row { margin-bottom: 2px; }
  .tile { margin-right: 2px; border-radius: 2px; }

  .play span { width: 32px; height: 32px; font-size: 14px; }
  .badge { font-size: 10px; bottom: 4px; right: 4px; padding: 1px 4px; }
}
