/* Load the exact "Segoe UI Web" font Office/Excel uses (see chat.css). Repeated
   here because spreadsheet.css is also loaded standalone by the Excel add-in
   column-picker dialog (excel_plugin/picker_dialog.html). */
@font-face {
  font-family: "Segoe UI Web (West European)";
  src: url("https://static2.sharepointonline.com/files/fabric/assets/fonts/segoeui-westeuropean/segoeui-regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Segoe UI Web (West European)";
  src: url("https://static2.sharepointonline.com/files/fabric/assets/fonts/segoeui-westeuropean/segoeui-semibold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Segoe UI Web (West European)";
  src: url("https://static2.sharepointonline.com/files/fabric/assets/fonts/segoeui-westeuropean/segoeui-bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* Excel / Fluent theme tokens. Mirrors the set defined in chat.css so that the
   column-picker popup matches the chat UI. Duplicated here (with identical
   values) because spreadsheet.css is also loaded standalone by the Excel
   add-in dialog (excel_plugin/picker_dialog.html), which does not load chat.css. */
:root {
  --xl-accent:          #107c41;  /* Excel green */
  --xl-accent-hover:    #0e6b39;
  --xl-accent-pressed:  #0b5a30;
  --xl-accent-tint:     #eaf4ee;

  --xl-canvas:          #faf9f8;
  --xl-surface:         #ffffff;
  --xl-subtle:          #f3f2f1;
  --xl-subtle-hover:    #edebe9;

  --xl-border:          #edebe9;
  --xl-border-strong:   #d2d0ce;

  --xl-text:            #323130;
  --xl-text-secondary:  #605e5c;
  --xl-text-disabled:   #a19f9d;

  --xl-radius:          4px;
  --xl-shadow:          0 1.6px 3.6px rgba(0,0,0,.10), 0 0.3px 0.9px rgba(0,0,0,.07);

  --xl-font: "Segoe UI Web (West European)", "Segoe UI", -apple-system,
             BlinkMacSystemFont, system-ui, Roboto, "Helvetica Neue", sans-serif;
}

.ss-drag-over {
  border-color: var(--xl-accent) !important;
  background: var(--xl-accent-tint) !important;
}

.ss-file-card {
  background: var(--xl-surface);
  border: 1px solid var(--xl-border);
  border-radius: 8px;
  box-shadow: var(--xl-shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.ss-file-header {
  padding: 14px 20px;
  background: var(--xl-accent);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ss-file-header .ss-badge {
  background: rgba(255, 255, 255, 0.22);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 500;
}
.ss-sheet-section { border-bottom: 1px solid var(--xl-border); }
.ss-sheet-section:last-child { border-bottom: none; }
.ss-sheet-name {
  padding: 12px 20px;
  font-weight: 600;
  font-size: 14px;
  background: var(--xl-subtle);
  border-bottom: 1px solid var(--xl-border);
  color: var(--xl-text-secondary);
}
.ss-columns-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 4px;
  padding: 12px 16px;
}
.ss-column-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 14px;
}
.ss-column-item:hover { background: var(--xl-subtle); }
.ss-column-item input[type="checkbox"] {
  accent-color: var(--xl-accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.ss-column-label {
  user-select: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ss-modal-actions {
  display: flex;
  gap: 12px;
  flex: none;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--xl-border);
}
.ss-apply-btn {
  display: none;
  padding: 12px 24px;
  background: var(--xl-accent);
  color: #fff;
  border: none;
  border-radius: var(--xl-radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
}
.ss-apply-btn:hover { background: var(--xl-accent-hover); }
.ss-apply-btn:active { background: var(--xl-accent-pressed); }
.ss-cancel-btn {
  padding: 12px 24px;
  background: var(--xl-surface);
  color: var(--xl-text);
  border: 1px solid var(--xl-border-strong);
  border-radius: var(--xl-radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.ss-cancel-btn:hover { background: var(--xl-subtle); }
.ss-preview-wrap {
  overflow-x: auto;
  padding: 0 16px 4px;
}
.ss-preview-note {
  padding: 0 16px 12px;
  color: var(--xl-text-secondary);
  font-size: 12px;
}
.ss-preview-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  margin-top: 4px;
}
.ss-preview-table th,
.ss-preview-table td {
  padding: 6px 10px;
  border: 1px solid var(--xl-border);
  text-align: left;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ss-preview-table th {
  background: var(--xl-subtle);
  font-weight: 600;
  color: var(--xl-text-secondary);
  cursor: pointer;
}
.ss-preview-table th:hover { background: var(--xl-canvas); }
/* Header hover highlights the whole column (encrypted cells keep their own
   stronger highlight via !important, so they're unaffected). */
.ss-col-hover { background: var(--xl-canvas); }
/* Header cell doubles as the column selector: the whole <th> is the hitbox,
   with the checkbox + name laid out together. */
.ss-th-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  user-select: none;
  max-width: 100%;
  vertical-align: middle;
}
.ss-th-label input[type="checkbox"] {
  accent-color: var(--xl-accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
  flex: none;
}
.ss-th-label-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Encrypted column highlight — used in both the selection modal preview
   and the spreadsheet-link preview dialog. */
.ss-col-encrypted-header {
  background: #ede9fe !important;
  color: #5b21b6 !important;
  border-color: #d9d9d9 !important;
}
/* Reserve space for the lock on every header cell so toggling the encrypted
   class doesn't shift column widths or row height. The glyph is the same in
   both states — only its visibility changes — so the line-box stays identical. */
.ss-preview-table th::after,
.ss-link-sheet-content table tr:first-child > *::after,
.ss-col-encrypted-header::after {
  content: "🔒";
  display: inline-block;
  margin-left: 2px;
  vertical-align: middle;
  visibility: hidden;
}
.ss-col-encrypted-header::after {
  visibility: visible !important;
}
.ss-col-encrypted-cell {
  background: #ede9fe !important;
  color: #5b21b6 !important;
  border-color: #d9d9d9 !important;
}

/* Bracket the column with two violet rails on the left/right edges only,
   mirroring the Excel conditional format: a full-column range can't close into
   a box, so the workbook marks the column with vertical rails and leaves the
   top/bottom as plain gray row separators (the #d9d9d9 border-color above).
   We match that here instead of drawing a closed rectangle. 1px (not 2px)
   because Excel's ConditionalRangeBorder is always hairline, and at that weight
   its dashed rail renders as short dots — so CSS `dotted` matches its look. */
.ss-col-encrypted-header,
.ss-col-encrypted-cell {
  border-left: 1px dotted #a78bfa !important;
  border-right: 1px dotted #a78bfa !important;
}
.ss-empty-sheet {
  padding: 16px 20px;
  color: var(--xl-text-disabled);
  font-style: italic;
  font-size: 14px;
}

.ss-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 20px;
}
.ss-modal-overlay.open { display: flex; }
.ss-modal-content {
  background: var(--xl-canvas);
  border-radius: 8px;
  width: 100%;
  max-width: 840px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  padding: 24px;
  position: relative;
  font-family: var(--xl-font);
  color: var(--xl-text);
}
/* Only the results scroll; the title and the action footer stay pinned so the
   Cancel/Apply buttons remain visible no matter how many sheets are listed.
   min-height:0 lets this flex child shrink below its content and scroll. */
.ss-modal-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.ss-modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--xl-text-secondary);
  line-height: 1;
  padding: 4px 8px;
  border-radius: var(--xl-radius);
}
.ss-modal-close:hover {
  background: var(--xl-subtle-hover);
  color: var(--xl-text);
}
.ss-modal-title {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 600;
  color: var(--xl-text);
}

html.ss-dialog,
html.ss-dialog body { height: 100%; margin: 0; }
/* Size the modal by flexbox, not by height/max-height. Inside the Office web
   dialog iframe neither percentage nor vh max-height reliably constrains the
   content (the fixed overlay's height isn't treated as a definite containing
   block for height resolution), so the content kept growing past the viewport
   and clipped the footer. Instead make the fixed-size overlay a flex column and
   let the content fill it with flex:1 + min-height:0 — flex sizing is computed
   from the overlay's actual laid-out size, so the content can't exceed it and
   its own body scrolls while the footer stays pinned. */
.ss-dialog .ss-modal-overlay {
  position: fixed;
  inset: 0;
  background: #f5f5f5;
  padding: 16px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
}
.ss-dialog .ss-modal-content {
  max-width: none;
  max-height: none;
  flex: 1 1 auto;
  min-height: 0;
  box-sizing: border-box;
  box-shadow: none;
}
.ss-dialog .ss-modal-close { display: none; }

/* Spreadsheet link with preview button */
spreadsheet-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.ss-link-preview-btn {
  font-size: 11px;
  padding: 1px 7px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  color: #475569;
  line-height: 1.6;
}

.ss-link-preview-btn:hover {
  background: #f1f5f9;
}

/* Preview dialog */
.ss-link-dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(90vw, 900px);
  max-height: 85vh;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.ss-link-dialog[open] {
  display: flex;
  flex-direction: column;
}

.ss-link-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.ss-link-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: #1e293b;
  color: #fff;
  flex-shrink: 0;
}

.ss-link-dialog-title {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ss-link-dialog-close {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
}

.ss-link-dialog-close:hover {
  color: #fff;
}

.ss-link-dialog-body {
  overflow: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.ss-link-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #e5e7eb;
  background: #f8fafc;
  flex-shrink: 0;
}

.ss-link-tab {
  padding: 8px 16px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: #64748b;
}

.ss-link-tab:hover {
  background: #f1f5f9;
}

.ss-link-tab.active {
  color: #1e293b;
  border-bottom-color: #3b82f6;
  font-weight: 600;
}

.ss-link-sheet-content {
  overflow: auto;
  padding: 12px 16px;
}

.ss-link-sheet-content table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  font-family: ui-sans-serif, system-ui;
}

.ss-link-sheet-content td,
.ss-link-sheet-content th {
  padding: 5px 10px;
  border: 2px solid #e5e7eb;
  white-space: nowrap;
}

/* Generic helper */
.ss-hidden { display: none; }

/* Inline text-style button (e.g. "try an example", "Select a table") */
.ss-link-btn {
  background: none;
  border: none;
  padding: 0;
  margin-left: 6px;
  color: var(--xl-accent);
  cursor: pointer;
  font-size: inherit;
  text-decoration: underline;
}

/* Apply button visible state (base .ss-apply-btn defaults to display: none) */
.ss-apply-btn.ss-visible { display: block; }

/* Import / select-table button width */
.ss-import-btn { min-width: 13em; }

/* Example picker dialog */
.ss-example-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ss-example-dialog {
  position: relative;
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  max-width: 620px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  font-family: ui-sans-serif, system-ui;
}
.ss-example-title {
  margin: 0 0 16px 0;
  font-size: 18px;
  color: #222;
}
.ss-example-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #666;
  line-height: 1;
}
.ss-example-item {
  padding: 12px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  margin-bottom: 10px;
  cursor: pointer;
}
.ss-example-item:hover { background: #f5f5f5; }
.ss-example-name {
  font-weight: 600;
  font-size: 14px;
  color: #111;
  margin-bottom: 4px;
}
.ss-example-desc {
  font-size: 13px;
  color: #555;
  line-height: 1.4;
}

/* Attached-spreadsheets list (above the chat input) */
.ss-attached-list {
  padding: 6px 10px;
  background: #f0f4f8;
  border-radius: 6px;
  margin-bottom: 6px;
  font-family: ui-sans-serif, system-ui;
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.ss-attached-label {
  font-weight: 600;
  color: #555;
}
.ss-attached-chip {
  background: #dce6f0;
  padding: 2px 8px;
  border-radius: 4px;
  color: #333;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Settings panel rows — aligned to the flyout-menu item padding (see
   .ss-menu-item in chat.css) so headings, radios and actions line up. */
.ss-settings-heading {
  padding: 6px 10px 4px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--xl-text-secondary);
}
.ss-settings-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
}
.ss-settings-radio:hover {
  background: var(--xl-subtle);
  border-radius: var(--xl-radius);
}

/* Excel add-in welcome screen */
.ss-welcome-card {
  max-width: 420px;
  margin: 0 auto;
  /* Top space lives in padding, not margin: a top margin would collapse
     through the full-height #chat and push it down, adding a scrollbar. */
  padding: 48px 24px 24px;
  text-align: center;
  font-family: var(--xl-font);
  color: var(--xl-text);
}
.ss-welcome-heading {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 600;
  color: var(--xl-text);
}
.ss-welcome-message {
  margin: 0 0 20px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--xl-text-secondary);
}
/* Match Excel's own Fluent buttons: 32px tall, 14px regular weight. */
.ss-welcome-btn {
  height: 32px;
  padding: 0 16px;
  background: var(--xl-accent);
  color: #fff;
  border: 1px solid var(--xl-accent);
  border-radius: var(--xl-radius);
  font-family: var(--xl-font);
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
}
.ss-welcome-btn:hover {
  background: var(--xl-accent-hover);
  border-color: var(--xl-accent-hover);
}
.ss-welcome-btn:active {
  background: var(--xl-accent-pressed);
  border-color: var(--xl-accent-pressed);
}

/* In-page alert overlay (Office dialog has no window.alert) */
.ss-alert-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  font-family: ui-sans-serif, system-ui;
}
.ss-alert-card {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  max-width: 80%;
  max-height: 80%;
  padding: 16px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.ss-alert-text {
  margin: 0 0 16px;
  white-space: pre-wrap;
  overflow: auto;
  font-size: 14px;
  line-height: 1.4;
}
.ss-alert-btn {
  align-self: flex-end;
  padding: 6px 20px;
  border: none;
  border-radius: 4px;
  background: var(--xl-accent);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}
.ss-alert-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.ss-alert-btn-secondary {
  background: var(--xl-surface);
  color: var(--xl-text);
  border: 1px solid var(--xl-border-strong);
}
