/*
 * Quill task pane — icon-rail redesign.
 * Self-contained styles (no external Fabric dependency). The ms-* class names
 * are retained purely as styling/JS hooks and are defined locally below.
 */

/* ------------------------------------------------------------------ */
/*  Design tokens                                                     */
/* ------------------------------------------------------------------ */
:root {
  --bg:            #faf9f5;  /* warm paper */
  --surface:       #ffffff;
  --surface-soft:  #f5f4ee;
  --border:        #ecebe3;
  --border-strong: #dddbd0;

  --text:          #1f1e1c;
  --text-muted:    #6b6a64;
  --text-faint:    #9a988f;

  --accent:        #2563b0;  /* Quill blue */
  --accent-hover:  #1d4e8c;
  --accent-soft:   #eaf1fa;
  --accent-border: #c5d8ef;

  --success-bg:    #e9f6ec;  --success-fg: #1d7a33;  --success-bd: #bfe6c7;
  --error-bg:      #fdecec;  --error-fg:   #b3261e;  --error-bd:   #f3c4c1;
  --info-bg:       #eef3fb;  --info-fg:    #2563b0;  --info-bd:    #cdddf2;

  --radius:    12px;
  --radius-sm: 8px;
  --radius-xs: 6px;

  --rail-w:    54px;

  --shadow-sm: 0 1px 2px rgba(31, 30, 28, .05);
  --shadow:    0 4px 16px rgba(31, 30, 28, .07);

  --font-sans:  -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}

/* ------------------------------------------------------------------ */
/*  Base                                                              */
/* ------------------------------------------------------------------ */
* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;            /* the shell owns scrolling, not the page */
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Local definitions for the legacy ms-font-* hooks */
.ms-font-su { font-size: 1.5rem; }
.ms-font-xl { font-size: 0.95rem; }
.ms-font-l  { font-size: 0.85rem; }
.ms-font-m  { font-size: 0.875rem; }

/* ------------------------------------------------------------------ */
/*  Sideload notice                                                   */
/* ------------------------------------------------------------------ */
.ms-welcome__main {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 20px;
}

#sideload-msg {
  margin: 24px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  color: var(--text-muted);
}

#sideload-msg a { color: var(--accent); }

/* ------------------------------------------------------------------ */
/*  Shell: rail + content                                             */
/* ------------------------------------------------------------------ */
#app-shell {
  display: flex;
  align-items: stretch;
  height: 100vh;
  overflow: hidden;
}

#rail {
  flex: 0 0 var(--rail-w);
  width: var(--rail-w);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 0;
  background: var(--surface-soft);
  border-right: 1px solid var(--border);
  /* full-height fixed column; stretches with the shell, never scrolls */
}

.rail-brand {
  width: 30px;
  height: 30px;
  margin-bottom: 10px;
}

.rail-tab {
  position: relative;
  appearance: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}

.rail-tab svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Typographic glyph icons (H, Ω) instead of line art */
.rail-tab svg.glyph { stroke: none; }
.rail-tab svg.glyph text {
  fill: currentColor;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 17px;
  text-anchor: middle;
  dominant-baseline: central;
}

.rail-tab:hover {
  background: var(--surface);
  color: var(--text);
}

.rail-tab.is-active {
  background: var(--accent-soft);
  color: var(--accent-hover);
  border-color: var(--accent-border);
}

/* Active accent bar at the rail's left edge */
.rail-tab.is-active::after {
  content: "";
  position: absolute;
  left: -7px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.rail-tab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Hover tooltip */
.rail-tip {
  position: absolute;
  left: calc(100% + 9px);
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  background: var(--text);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease;
  z-index: 20;
}

.rail-tab:hover .rail-tip,
.rail-tab:focus-visible .rail-tip { opacity: 1; }

/* Content column — the only scroll container */
#content {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  scrollbar-gutter: stable;    /* reserve the gutter so it can't pop in/out with width */
  padding: 14px 14px 28px;
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------------------------ */
/*  Search box                                                        */
/* ------------------------------------------------------------------ */
.search-wrap {
  position: relative;
  margin-bottom: 14px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  fill: var(--text-faint);
  pointer-events: none;
}

#toolSearch {
  width: 100%;
  padding: 9px 12px 9px 34px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  transition: border-color .12s ease, box-shadow .12s ease;
}

#toolSearch::placeholder { color: var(--text-faint); }

#toolSearch:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ------------------------------------------------------------------ */
/*  Panels & groups                                                   */
/* ------------------------------------------------------------------ */
.panel { display: none; }

.panel.is-active,
main.searching .panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tool-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px 16px;
}

.group-title {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* Search mode: hide non-tool content within surviving groups */
main.searching #input-rows,
main.searching .btn-row,
main.searching details.advanced { display: none; }

.search-hidden { display: none !important; }

.search-empty-msg {
  margin: 4px 6px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ------------------------------------------------------------------ */
/*  Button groups                                                     */
/* ------------------------------------------------------------------ */
.btn-row,
.heading-buttons,
.numbered-heading-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
}

/* The H1–H6 grids: responsive columns that drop 3 → 2 → 1 as the pane
   narrows, instead of fixed thirds that let "Num H1" overflow its cell. */
.heading-buttons,
.numbered-heading-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(62px, 1fr));
}

.btn-row {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

/* ------------------------------------------------------------------ */
/*  Buttons                                                           */
/* ------------------------------------------------------------------ */
.ms-Button {
  appearance: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease, box-shadow .12s ease, transform .04s ease;
  white-space: nowrap;
}

.ms-Button:hover {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-hover);
}

.ms-Button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.ms-Button:active { transform: translateY(1px); }

/* Grid groups: fill the cell; tighter padding + clip safety so labels
   like "Num H1" never walk off the cell. */
.heading-buttons .ms-Button,
.numbered-heading-buttons .ms-Button {
  width: 100%;
  min-width: 0;
  padding: 8px 6px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Command lists: Insert / Text actions as a tidy full-width menu.
   Long, variable-length labels read far better stacked than wrapped. */
.document-tlf-buttons,
.document-fields-buttons,
.document-text-buttons,
.document-page-buttons {
  display: flex;
  flex-direction: column;
  /* pull rows flush so hairline separators read as one list inside the card */
  margin: -4px -6px;
}

.document-tlf-buttons .ms-Button,
.document-fields-buttons .ms-Button,
.document-text-buttons .ms-Button,
.document-page-buttons .ms-Button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-start;
  text-align: left;
  white-space: normal;
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  padding: 10px 8px;
  font-weight: 500;
}

/* Hairline separators between consecutive rows */
.document-tlf-buttons .ms-Button + .ms-Button,
.document-fields-buttons .ms-Button + .ms-Button,
.document-text-buttons .ms-Button + .ms-Button,
.document-page-buttons .ms-Button + .ms-Button {
  border-top: 1px solid var(--border);
  border-radius: 0;
}

.document-tlf-buttons .ms-Button:hover,
.document-fields-buttons .ms-Button:hover,
.document-text-buttons .ms-Button:hover,
.document-page-buttons .ms-Button:hover {
  background: var(--surface-soft);
  border-color: var(--border);   /* keep the separator neutral, not accent */
  color: var(--accent-hover);
}

/* Destructive action (e.g. Delete Instructional Text) */
.ms-Button.cmd-danger { color: var(--error-fg); }
.ms-Button.cmd-danger:hover {
  background: var(--error-bg);
  color: var(--error-fg);
}

/* PK characters: uniform grid of equal-width tokens.
   Min track width keeps the longest label (e.g. "AUC0-last") on one line
   before a new column is added, so nothing truncates. */
#special-char-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
}

#special-char-buttons .ms-Button {
  width: 100%;
  min-width: 0;
  padding: 8px 6px;
  font-size: 12px;
}

/* Symbols: square character-map grid for single glyphs */
#special-symbol-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 6px;
}

#special-symbol-buttons .ms-Button {
  width: 100%;
  min-width: 0;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 16px;
}

/* Descriptive symbols (dashes, spaces) get their own full-width rows */
#special-symbol-buttons .ms-Button.named {
  grid-column: 1 / -1;
  aspect-ratio: auto;
  justify-content: flex-start;
  place-items: center start;
  padding: 8px 12px;
  font-size: 13px;
}

/* Primary action */
#applyBtn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
#applyBtn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

/* ------------------------------------------------------------------ */
/*  Template field inputs                                             */
/* ------------------------------------------------------------------ */
#input-rows { display: flex; flex-direction: column; gap: 10px; }

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  align-items: center;
  column-gap: 10px;
}

.input-row label {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.input-row.unwrap label {
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
}

.input-row input[type="text"] {
  width: 100%;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  transition: border-color .12s ease, box-shadow .12s ease;
}

.input-row input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Empty-state hint when no template fields are present */
#input-rows:empty::before {
  content: "No template fields found in this document.";
  display: block;
  color: var(--text-faint);
  font-size: 13px;
  font-style: italic;
}

/* ------------------------------------------------------------------ */
/*  Style-mapping disclosure (advanced, secondary)                    */
/* ------------------------------------------------------------------ */
details.advanced {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

details.advanced > summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--text-muted);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

details.advanced > summary::-webkit-details-marker { display: none; }

details.advanced > summary::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--text-faint);
  border-bottom: 2px solid var(--text-faint);
  transform: rotate(-45deg);
  transition: transform .18s ease;
}

details.advanced[open] > summary::before { transform: rotate(45deg); }

.heading-style-rows,
.numbered-style-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.style-map-row {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  align-items: center;
  column-gap: 8px;
}

.style-map-row label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.style-map-row select {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.style-map-row select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ------------------------------------------------------------------ */
/*  Status message                                                    */
/* ------------------------------------------------------------------ */
#status-message {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  border-left-width: 3px;
  font-size: 13px;
}

#status-message:empty { display: none; }

.status-success { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-bd); }
.status-error   { background: var(--error-bg);   color: var(--error-fg);   border-color: var(--error-bd); }
.status-info    { background: var(--info-bg);    color: var(--info-fg);    border-color: var(--info-bd); }
