/* SCC Bibliography — embeddable styles.
   Everything is scoped under #scc-app so it cannot collide with the host page
   (which defines its own body, .container, .panel-body, h3, .table, etc.). */

#scc-app {
  background: #f8f5f0;
  padding: 15px;
  border-radius: 6px;
  color: #333;
  font-size: 14px;
  line-height: 1.4;
}
#scc-app h3 { margin-top: 0; font-size: 20px; color: #333; }

/* Layout: sidebar + main */
#scc-app .app-wrap { display: flex; flex-wrap: wrap; gap: 20px; }
#scc-app .sidebar {
  flex: 0 0 20%;
  background: #f8f5f0;
  border: 1px solid #dfd7ca;
  border-radius: 6px;
  padding: 15px;
  max-width: 20%;
}
#scc-app .mainpanel {
  flex: 1 1 78%;
  min-width: 0;
  max-width: 78%;
}
@media (max-width: 900px) {
  #scc-app .sidebar, #scc-app .mainpanel { flex: 1 1 100%; max-width: 100%; }
}

/* Coloured section buttons — palette from original app.R */
#scc-app .btn-section {
  color: #fff !important;
  border: 1px solid transparent;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  margin-bottom: 6px;
  border-radius: 4px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#scc-app .btn-section:hover { filter: brightness(1.08); }
#scc-app .btn-section .chev { transition: transform 0.2s; font-size: 12px; }
#scc-app .btn-section.collapsed .chev { transform: rotate(-90deg); }

/* Palette from app.R */
#scc-app .bg-basic     { background-color: #583532; }
#scc-app .bg-advanced  { background-color: #294547; }
#scc-app .bg-period    { background-color: #325558; }
#scc-app .bg-cats      { background-color: #3b6568; }
#scc-app .bg-keywords  { background-color: #447578; }
#scc-app .bg-typelit   { background-color: #606c38; }
#scc-app .bg-curia     { background-color: #41542c; }
#scc-app .bg-comp      { background-color: #936639; }
#scc-app .bg-sub       { background-color: #a68a64; }
#scc-app .bg-praxis    { background-color: #bc6c25; }

/* Own panel body class (host page also has .panel-body — scoping wins) */
#scc-app .panel-body {
  padding: 10px 12px;
  border: 1px solid #dfd7ca;
  border-top: none;
  border-radius: 0 0 4px 4px;
  margin-top: -6px;
  margin-bottom: 8px;
  background: #ffffff;
}
#scc-app .panel-body.nested { background: #fbfaf7; }

/* Checkbox groups */
#scc-app .checkgroup { display: flex; flex-direction: column; gap: 3px; margin: 6px 0; }
#scc-app .checkgroup label {
  margin: 0;
  font-weight: normal;
  font-size: 13px;
  line-height: 1.35;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}
#scc-app .checkgroup input[type="checkbox"] { margin-top: 3px; flex-shrink: 0; }

#scc-app .subcols { display: flex; flex-wrap: wrap; gap: 12px; margin-left: 6px; }
#scc-app .subcols > div { flex: 1 1 100%; min-width: 0; }

#scc-app hr.thin { margin: 8px 0; border-top: 1px dashed #dfd7ca; }

#scc-app .select-all-btn {
  font-size: 12px;
  padding: 3px 10px;
  margin-bottom: 6px;
  background: #f0eae0;
  border: 1px solid #ccc4b7;
  border-radius: 3px;
  cursor: pointer;
}
#scc-app .select-all-btn:hover { background: #e6ddce; }

/* Slider */
#scc-app .slider-wrap { padding: 20px 8px 10px; }
#scc-app .noUi-connect { background: #447578; }
#scc-app .noUi-handle { background: #325558; border-color: #294547; box-shadow: none; }
#scc-app .year-vals {
  display: flex; justify-content: space-between; font-size: 13px;
  margin-top: 8px; color: #325558; font-weight: 600;
}

/* Select2 tweaks (dropdown is parented to #scc-app, so this applies) */
#scc-app .select2-container { width: 100% !important; margin-bottom: 8px; }
#scc-app .filter-label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-top: 6px;
  margin-bottom: 2px;
  color: #333;
}

/* DataTable */
#scc-app table.dataTable {
  font-size: 13px;
  table-layout: fixed;   /* honour explicit per-column widths */
  margin: 0 !important;
}
#scc-app .dataTables_scrollHead table.dataTable,
#scc-app .dataTables_scrollBody table.dataTable {
  table-layout: fixed;
}
#scc-app table.dataTable td {
  vertical-align: top;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Height-clamp for long text fields — click to expand */
#scc-app .dt-clamp {
  line-height: 1.4;
  max-height: 7em;          /* ~5 lines */
  overflow: hidden;
  cursor: pointer;
  position: relative;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  line-clamp: 5;
  -webkit-box-orient: vertical;
}
#scc-app .dt-clamp.expanded {
  max-height: none;
  -webkit-line-clamp: unset;
  line-clamp: unset;
  display: block;
}
#scc-app .dt-clamp:not(.expanded)::after {
  content: "";
  position: absolute;
  bottom: 0; right: 0;
  width: 100%; height: 1.4em;
  background: linear-gradient(transparent, rgba(255,255,255,0.95));
  pointer-events: none;
}
#scc-app tr.selected .dt-clamp:not(.expanded)::after,
#scc-app tr:hover .dt-clamp:not(.expanded)::after { display: none; }

/* Selected row highlight (DataTables default has no Select ext here) */
#scc-app table.dataTable tr.selected td { background: #d7e9ea !important; }

/* Button colours from callback */
#scc-app button.buttons-copy    { background: #c47841 !important; color: #fff !important; border: none !important; }
#scc-app button.buttons-print   { background: #6e5622 !important; color: #fff !important; border: none !important; }
#scc-app button.buttons-colvis  { background: #ccb072 !important; color: #fff !important; border: none !important; }
#scc-app button.buttons-excel   { background: #e67a5c !important; color: #fff !important; border: none !important; }
#scc-app button.buttons-pdf     { background: #783d2c !important; color: #fff !important; border: none !important; }
#scc-app button.bibexport,
#scc-app button.buttons-bibexport {
  background: #4d0000 !important; color: #fff !important; border: none !important;
}
#scc-app button.bibexport:hover,
#scc-app button.buttons-bibexport:hover { background: #4d0000 !important; }

#scc-app .dt-buttons .dt-button {
  margin: 3px 3px 3px 0; padding: 5px 12px; border-radius: 3px; font-size: 13px;
}

/* Hide default dataTables filter (custom search box is used instead) */
#scc-app .dataTables_filter { display: none; }

/* Layout row for dom '<"top"...>' */
#scc-app .dt-top { margin-bottom: 10px; }
#scc-app .dt-top .row {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 10px;
}
#scc-app .dt-top .left-col { flex: 1 1 auto; }
#scc-app .dt-top .right-col { flex: 0 0 auto; }
#scc-app .dt-bottom { margin-top: 10px; }
#scc-app .dt-bottom .row {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 10px;
}

/* Modal for BibTeX download (appended inside #scc-app) */
#scc-app .modal-backdrop-custom {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 3000;
  display: flex; align-items: center; justify-content: center;
}
#scc-app .modal-box {
  background: #fff; padding: 25px; border-radius: 6px; max-width: 500px;
  box-shadow: 0 5px 25px rgba(0,0,0,.3); color: #333;
}
#scc-app .modal-box h4 { margin-top: 0; }
#scc-app .modal-box .actions { display: flex; gap: 10px; margin-top: 15px; flex-wrap: wrap; }
#scc-app .modal-box button.close-x {
  position: absolute; top: 10px; right: 15px; background: transparent;
  border: none; font-size: 22px; cursor: pointer;
}
#scc-app .dl-btn {
  background: #4d0000; color: #fff; border: none;
  padding: 8px 14px; border-radius: 3px; cursor: pointer;
}
#scc-app .dl-btn:hover { background: #690000; }
#scc-app .cancel-btn {
  background: #999; color: #fff; border: none;
  padding: 8px 14px; border-radius: 3px; cursor: pointer;
}

/* Global search under Basic */
#scc-app .global-search {
  width: 100%; padding: 6px 10px; border: 1px solid #ccc4b7;
  border-radius: 3px; font-size: 14px;
}

/* ---------------------------------------------------------------- phones */
@media (max-width: 767.98px) {
  #scc-app { padding: 12px 10px; border-radius: 0; }
  #scc-app .app-wrap { gap: 14px; }
  #scc-app .sidebar { padding: 12px; }
  #scc-app .btn-section { min-height: 44px; padding: 10px 12px; }
  #scc-app .checkgroup label { font-size: 14px; padding: 3px 0; }
  #scc-app .select-all-btn { min-height: 36px; }
  #scc-app .global-search { min-height: 42px; font-size: 16px; }   /* 16px stops iOS zooming in */

  /* toolbar: buttons wrap, pagination on its own line, info under it */
  #scc-app .dt-top .row,
  #scc-app .container-fluid > .row { flex-direction: column; align-items: stretch; gap: 8px; margin: 0; }
  #scc-app .dt-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
  #scc-app .dt-buttons .dt-button { margin: 0; min-height: 38px; }
  #scc-app .dataTables_paginate { text-align: center; }
  #scc-app .dataTables_paginate .paginate_button { min-width: 36px; padding: 6px 8px !important; }
  #scc-app .dataTables_length,
  #scc-app .dataTables_info { text-align: center; float: none; }
  #scc-app .container-fluid { padding: 0; }

  /* the table scrolls inside its frame once more columns are switched on */
  #scc-app .dataTables_scrollBody { -webkit-overflow-scrolling: touch; }
  #scc-app table.dataTable { font-size: 14px; }
  #scc-app table.dataTable td { padding: 8px 6px; }

  #scc-app .modal-box { margin: 0 16px; padding: 20px; }
  #scc-app .modal-box .actions { flex-direction: column; }
}

/* Phones: the table lays itself out by content, so the long title takes most
   of the width and the year only what it needs. (On desktop the fixed
   per-column widths stay; DataTables re-derives them under scrollX anyway.) */
@media (max-width: 767.98px) {
  #scc-app table.dataTable,
  #scc-app .dataTables_scrollHead table.dataTable,
  #scc-app .dataTables_scrollBody table.dataTable { table-layout: auto; }
  #scc-app table.dataTable td.col-YEAR { white-space: nowrap; }
  #scc-app table.dataTable td.col-AUTHOR { min-width: 96px; }
}
