/* ================================
   Base tokens (client CSS overrides these)
   ================================ */
:root{
  --bg: #f6f8fb;
  --surface: rgba(255,255,255,.72);
  --surface-strong: rgba(255,255,255,.92);
  --line: rgba(15,23,42,.10);
  --line-strong: rgba(15,23,42,.14);
  --text: #0f172a;
  --muted: rgba(15,23,42,.62);

  --radius: 18px;
  --shadow: 0 18px 45px rgba(15,23,42,.10);
  --shadow-soft: 0 10px 26px rgba(15,23,42,.08);

  --sidebar-w: 275px;

  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  --base-size: 14px;
  --line-height: 1.35;

  --btn-bg: #e2e2e2;
  --btn-bg-hover: #dcdcdc;
  --btn-text: #3a3a3a;
  --btn-border: rgba(0,0,0,0.06);

  --btn-primary-bg: #d6d6d6;
  --btn-primary-bg-hover: #cfcfcf;
  --btn-primary-text: #2f2f2f;

  --success: rgba(34,197,94,.90);
  --primary: rgba(37,99,235,.95);
}

/* ================================
   Global base
   ================================ */
*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: var(--font);
  font-size: var(--base-size);
  line-height: var(--line-height);
  color: var(--text);
  background:
    radial-gradient(1200px 520px at 12% 0%, rgba(37,99,235,.10), transparent 58%),
    radial-gradient(920px 520px at 100% 0%, rgba(34,197,94,.08), transparent 55%),
    var(--bg);
}

a{ color: inherit; }
button, input{ font: inherit; }

/* ================================
   Layout
   ================================ */
.layout{
  display:grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap:12px;
  padding:12px;
  min-height:100vh;
}

.bar{
  position: sticky;
  top: 12px;
  height: calc(100vh - 24px);

  display:flex;
  flex-direction:column;
  gap:12px;

  padding:12px;
  border:1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-soft);
  min-height:0;
}

.main{
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:12px;
}

.viewer{
  height: calc(100vh - 24px);
  border:1px solid var(--line);
  border-radius: var(--radius);
  overflow:hidden;
  background: rgba(255,255,255,.90);
  box-shadow: var(--shadow);
  position:relative;
}

#dfHost, #df_manual_book{ width:100%; height:100%; }

/* ================================
   Sidebar content
   ================================ */
.brand{
  display:flex;
  align-items:center;
  gap:10px;
  padding-bottom:10px;
  border-bottom:1px solid rgba(15,23,42,.08);
}

.navToggle{
  margin-left:auto;
  flex:0 0 auto;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:30px;
  height:30px;
  border-radius:9px;
  border:1px solid var(--line);
  background: rgba(255,255,255,.86);
  color: rgba(15,23,42,.72);
  cursor:pointer;
  box-shadow: 0 6px 14px rgba(15,23,42,.06);
  transition: background-color .15s ease, color .15s ease;
}
.navToggle:hover{ background: rgba(255,255,255,.98); color: var(--text); }
.navToggle:focus-visible{ outline:3px solid rgba(37,99,235,.18); outline-offset:2px; }

.navRestore{
  position:absolute;
  top:12px;
  left:12px;
  z-index:5;
  display:none;
  align-items:center;
  justify-content:center;
  width:40px;
  height:40px;
  border-radius:12px;
  border:1px solid var(--line);
  background: var(--surface-strong);
  color: rgba(15,23,42,.78);
  cursor:pointer;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
  transition: background-color .15s ease, color .15s ease, transform .12s ease;
}
.navRestore:hover{ color: var(--text); transform: translateY(-1px); }
.navRestore:focus-visible{ outline:3px solid rgba(37,99,235,.18); outline-offset:2px; }

.layout.nav-collapsed{ grid-template-columns: 1fr; }
.layout.nav-collapsed .bar{ display:none; }
.layout.nav-collapsed .navRestore{ display:inline-flex; }

/* you currently hide brand in HTML, but keep it styled */
.logo{
  width:40px;
  height:40px;
  border-radius:15px;
  background: linear-gradient(135deg, rgba(37,99,235,.95), rgba(34,197,94,.85));
  box-shadow: 0 14px 26px rgba(37,99,235,.16);
  flex:0 0 auto;
}
.btxt .h{
  margin:0;
  font-size:13.5px;
  font-weight:900;
}
.btxt .s{
  margin:5px 0 0;
  font-size:12px;
  color: var(--muted);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.pill{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  padding:7px 10px;
  border-radius:999px;
  border:1px solid var(--line);
  background: rgba(255,255,255,.86);
  color: rgba(15,23,42,.78);
  font-size:12px;
  box-shadow: 0 6px 14px rgba(15,23,42,.06);
  width:100%;
}
.dot{
  width:8px;
  height:8px;
  border-radius:999px;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(34,197,94,.16);
}

/* ================================
   Archive
   ================================ */
.archivePanel{
  border:1px solid var(--line);
  background: var(--surface);
  border-radius:14px;
  padding:10px;
  display:flex;
  flex-direction:column;
  gap:10px;
  min-height:0;
  flex:1;
}

.archiveHead{
  display:flex;
  justify-content:space-between;
  align-items:baseline;
  gap:10px;
}

.archiveTitle{
  font-size:12.5px;
  font-weight:900;
}
.archiveMeta{
  font-size:12px;
  color: var(--muted);
  white-space:nowrap;
}

.archiveSearch{
  border:1px solid var(--line);
  background: rgba(255,255,255,.96);
  border-radius:12px;
  padding:9px 10px;
  font-size:13px;
  outline:none;
  box-shadow: 0 6px 14px rgba(15,23,42,.06);
}

.archiveSearch:focus{
  border-color: rgba(37,99,235,.28);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12), 0 6px 14px rgba(15,23,42,.06);
}

.archiveIcons{
  overflow:auto;
  padding-right:4px;
  display:flex;
  flex-direction:column;
  gap:8px;
  min-height:0;
  flex:1;
}

.archiveIcon{
  width:100%;
  border:1px solid var(--line);
  background: rgba(255,255,255,.96);
  border-radius:14px;
  padding:10px 10px;
  cursor:pointer;
  user-select:none;
  box-shadow: 0 10px 18px rgba(15,23,42,.06);
  display:flex;
  align-items:center;
  gap:10px;
  text-align:left;
  outline:none;
}

.archiveIcon:focus-visible{
  outline: 3px solid rgba(37,99,235,.18);
  outline-offset: 2px;
}

.archiveIcon .icon{
  width:44px;
  height:44px;
  border-radius:8px;
  display:flex;
  align-items:center;
  justify-content:center;
  background: rgb(214 214 214);
  border:1px solid rgb(214 214 214);
  font-weight:700;
  letter-spacing:0.2px;
  color: rgb(58 58 58);
  flex:0 0 auto;
}

.archiveIcon .meta{
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:2px;
  flex:1;
}

.archiveIcon .year{
  font-weight:950;
  font-size:12px;
  line-height:1.1;
}

.archiveIcon .title{
  font-size:12px;
  color: rgba(15,23,42,.70);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.archiveIcon.is-selected{
  border-color: rgba(37,99,235,.30);
  box-shadow: 0 18px 30px rgba(37,99,235,.14);
}

.archiveIcon .badge{
  display:inline-block;
  margin-left:6px;
  padding:1px 6px;
  border-radius:999px;
  background: var(--success);
  color:#fff;
  font-size:10px;
  font-weight:800;
  letter-spacing:.2px;
  vertical-align:middle;
}

/* ================================
   Buttons
   ================================ */
.btnGrid{
  display:grid;
  grid-template-columns:minmax(0, 1fr) auto;
  gap:8px;
}

.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;

  padding:9px 12px;
  border-radius:12px;

  border:1px solid var(--btn-border);
  background: var(--btn-bg);

  color: var(--btn-text);
  font-size:13px;
  font-weight:600;
  letter-spacing:.2px;

  cursor:pointer;
  user-select:none;
  text-decoration:none;
  min-width:0;
  white-space:nowrap;

  box-shadow:
    0 1px 0 rgba(255,255,255,.6) inset,
    0 6px 14px rgba(0,0,0,.08);

  transition:
    background-color .15s ease,
    transform .12s ease,
    box-shadow .12s ease;
}

.btn:hover{
  background: var(--btn-bg-hover);
  transform: translateY(-1px);
  box-shadow:
    0 1px 0 rgba(255,255,255,.6) inset,
    0 10px 20px rgba(0,0,0,.12);
}

.btn:active{
  transform: translateY(0);
  box-shadow:
    0 1px 0 rgba(255,255,255,.6) inset,
    0 6px 14px rgba(0,0,0,.08);
}

.btn:focus-visible{
  outline: 3px solid rgba(0,0,0,.12);
  outline-offset: 2px;
}

.btn.is-loading{
  cursor: progress;
  opacity: .7;
  pointer-events: none;
}

.btnLabel{
  min-width:0;
  overflow:hidden;
  text-overflow:ellipsis;
}

.btn.iconOnly{
  position:relative;
}

.btn.iconOnly::after{
  content:attr(data-tooltip);
  position:absolute;
  inset-block-end:calc(100% + 8px);
  inset-inline-end:0;
  padding:6px 8px;
  border-radius:8px;
  background:var(--text);
  color:var(--surface-strong);
  font-size:12px;
  font-weight:600;
  line-height:1;
  opacity:0;
  pointer-events:none;
  transform:translateY(4px);
  transition:opacity .15s ease, transform .15s ease;
}

.btn.iconOnly:hover::after,
.btn.iconOnly:focus-visible::after{
  opacity:1;
  transform:translateY(0);
}

.btn.primary{
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}
.btn.primary:hover{
  background: var(--btn-primary-bg-hover);
}

/* ================================
   Toast
   ================================ */
.toast{
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);

  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.92);
  box-shadow: 0 16px 40px rgba(15,23,42,.18);
  font-size: 12.5px;
  color: rgba(15,23,42,.82);

  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 9999;
}

.toast.show{
  opacity: 1;
  transform: translateX(-50%) translateY(-2px);
}

/* ================================
   Responsive
   ================================ */
@media (max-width: 980px){
  .layout{
    grid-template-columns: 1fr;
  }
  .bar{
    position: relative;
    top: auto;
    height: auto;
  }
  .viewer{
    height: 70vh;
  }
}
