/*
 * CONFIG
 *
 * This section defines a handful of CSS variables that control the look and feel of
 * the citation widget.  If you wish to customise the colours or font to match
 * your own visual identity, modify the values below.  For example, change
 * --resref-primary to your brand's primary colour or --resref-font to a different
 * font stack.  These variables are consumed throughout the stylesheet via
 * corresponding shorthand variables (--p, --s, --a) on the .resref-cits root.
 */
:root{
  --resref-primary:#062B80;
  --resref-secondary:#126AC6;
  --resref-accent:#4FB9FC;
  --resref-font:Inter,system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
}

/* ResRef brand + responsive fit */
.resref-cits{
  /* Map configurable colours to internal shorthand variables.  If you change
   * --resref-primary/secondary/accent above, the entire widget will adopt
   * your new colour palette. */
  --p: var(--resref-primary);
  --s: var(--resref-secondary);
  --a: var(--resref-accent);
  --bg:#fff;
  --ink:#0b0c10;
  --muted:#5a667a;
  --border:#e7edf5;
  font-family: var(--resref-font);
  color:var(--ink);
  max-width:100%;
  box-sizing:border-box;
}
.resref-cits *{box-sizing:border-box}
.cits-shell{display:grid;grid-template-columns:minmax(180px,220px) 1fr minmax(300px,380px);gap:16px;max-width:100%}
.cits-left,.cits-center,.cits-right{background:#fff;border:1px solid var(--border);border-radius:14px;padding:12px;min-width:0}
.left-actions{display:flex;gap:6px;flex-wrap:wrap}
.btn-primary{background:linear-gradient(90deg,var(--p),var(--s));color:#fff;border:none;border-radius:999px;padding:8px 12px;cursor:pointer}
.btn-outline{background:#fff;border:1px solid var(--border);border-radius:999px;padding:8px 12px;cursor:pointer}
.btn-ghost{background:#fff;border:1px solid transparent;border-radius:999px;padding:6px 10px;cursor:pointer}
.btn-ghost.danger{color:#b00020}
.muted{color:var(--muted)} .small{font-size:12px}
.title{font-weight:700}
.style-select{border:1px solid var(--border);border-radius:999px;padding:6px 10px;margin-left:8px;max-width:100%}
.cits-head{display:flex;align-items:center;gap:8px;flex-wrap:wrap}

/* Position the Tools button at the start of the header and allow the rest of
 * the header elements to follow naturally. */
#cits-tools{
  margin-right:8px;
}
.cits-search{
  display:flex;
  gap:8px;
  /* Center the generator controls within the available width.  The max‑width
   * prevents the input from stretching indefinitely on large screens. */
  margin:10px auto;
  max-width:600px;
}
#cits-q{flex:1;border:1px solid var(--border);border-radius:999px;padding:10px 14px;outline:none;min-width:0}
#cits-q:focus{border-color:var(--s);box-shadow:0 0 0 3px rgba(18,106,198,.15)}
.cits-actions{
  display:flex;
  gap:12px;
  flex-wrap:wrap;
  /* Center action buttons below the search bar */
  margin:0 auto 10px auto;
  max-width:600px;
}
.cits-list-head{font-weight:600;margin-bottom:6px;display:flex;justify-content:space-between;align-items:center;gap:8px}
.cits-list .ref{border:1px solid var(--border);border-radius:10px;padding:10px;margin-bottom:8px;background:#f6fffa;display:flex;gap:8px;align-items:flex-start}

/* Smooth movement when dragging and dropping list items and references.  The
 * transform transition gives a subtle animation effect as items reorder. */
.cits-list .ref, #cits-lists li{
  transition: transform 0.2s ease, background-color 0.2s ease;
}

/* Highlight drop targets when dragging over them.  This improves the UX by
 * providing a visual cue about where the dragged item will land. */
.drag-over{
  border:2px dashed var(--s) !important;
}
.cits-list .num{font-weight:600;margin-right:6px;min-width:24px;text-align:right}
.cits-card{border:1px solid var(--border);border-radius:12px;padding:12px;background:#fff}
.detail-title{font-weight:700;margin:6px 0;word-break:break-word}
.detail-tools{display:flex;gap:8px;margin-bottom:10px;flex-wrap:wrap}
.tabs{display:flex;gap:8px;margin-bottom:6px;flex-wrap:wrap}
.tab{border:1px solid var(--border);border-radius:999px;padding:4px 10px;background:#fff;cursor:pointer}
.tab.active{border-color:#126AC6;color:#126AC6}
.cite-text{background:#f8fbff;border:1px dashed var(--border);border-radius:10px;padding:10px;margin-bottom:8px;word-break:break-word}
.inline-tools{display:flex;gap:8px;flex-wrap:wrap}
.num-cite{border-top:1px solid var(--border);margin-top:8px;padding-top:8px}
#cits-lists{list-style:none;padding-left:0;margin-top:10px}
#cits-lists li{display:flex;align-items:center;gap:8px;padding:8px;border:1px solid var(--border);border-radius:8px;margin-bottom:6px;cursor:grab;background:#fff}
#cits-lists li.active{border-color:#126AC6;background:#f4f9ff}
.handle{font-family:monospace;cursor:grab}
.ref .handle{user-select:none}
.ref .actions{margin-left:auto;display:flex;gap:6px}
.icon-btn{border:1px solid var(--border);background:#fff;border-radius:8px;padding:4px 8px;cursor:pointer}
.icon-btn.danger{color:#b00020}

/* When an icon button contains an image (e.g. the delete button), ensure
 * the image scales appropriately and the button dimensions collapse around it.
 */
.icon-btn img{
  width:16px;
  height:16px;
  display:block;
}

/* Render the delete icon in white so it stands out on coloured backgrounds.  The
 * filter inversion transforms the dark glyph into a light one without the
 * need for a separate asset. */
.icon-btn.danger img{
  filter: brightness(0) invert(1);
}

/* Dropdown menu for consolidated actions (export/import/copy).  The wrapper
 * positions the menu relative to the actions button.  The menu is hidden by
 * default (via the hidden attribute) and appears over other elements when
 * shown.  Each button within the menu spans the full width and displays
 * with minimal padding for easy clicking. */
.cits-menu-wrapper{position:relative;display:inline-block}
.cits-menu-wrapper .cits-dropdown{
  position:absolute;
  top:100%;
  right:0;
  background:var(--bg);
  border:1px solid var(--border);
  border-radius:8px;
  box-shadow:0 4px 8px rgba(0,0,0,.1);
  display:flex;
  flex-direction:column;
  min-width:160px;
  z-index:1000;
  padding:4px 0;
}
.cits-menu-wrapper .cits-dropdown button{
  width:100%;
  text-align:left;
  border:none;
  background:none;
  padding:8px 12px;
  cursor:pointer;
  font-size:14px;
  color:var(--ink);
}
.cits-menu-wrapper .cits-dropdown button:hover{
  background:rgba(18,106,198,.05);
}
.cits-menu-wrapper .cits-dropdown button:not(:last-child){
  border-bottom:1px solid var(--border);
}

/* Ensure that dropdowns are hidden when the hidden attribute is present.  The
 * HTML5 hidden attribute sets display:none by default, but our base styles
 * may override that.  Use !important to guarantee that hidden menus do not
 * render until toggled via JavaScript. */
.cits-menu-wrapper .cits-dropdown[hidden]{
  display:none !important;
}
img.emoji{
  max-width: fit-content !important;
}
.grow{flex:1}
/* Modal */
.cits-modal[hidden]{display:none}
.cits-modal{position:fixed;inset:0;background:rgba(0,0,0,.45);display:flex;align-items:center;justify-content:center;z-index:9999}
.cits-modal-card{background:#fff;border:1px solid var(--border);border-radius:14px;max-width:760px;width:92%;padding:12px}
.cits-modal-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;gap:8px}
.form-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:10px}
.form-grid .full{grid-column:1 / -1}
.input{display:flex;flex-direction:column;gap:4px}
.input label{font-size:12px;color:var(--muted)}
.input input,.input textarea{border:1px solid var(--border);border-radius:10px;padding:8px 10px;width:100%}
.modal-actions{margin-top:10px;display:flex;justify-content:flex-end}
/* Responsive */
@media (max-width:1100px){.cits-shell{grid-template-columns:1fr;}.cits-right{order:3}}