/* table-embed.css — styles for inline table embeds and the tables library page */

/* ── Embed container ─────────────────────────────────────────────────────── */

.te-embed {
  border: 1px solid var(--line-2, rgba(255,255,255,.10));
  border-radius: var(--radius-md, 12px);
  overflow: hidden;
  background: var(--bg-elev, #14171f);
  margin: 8px 0;
}

.te-missing {
  padding: 16px;
  color: var(--fg-dim, #5c6474);
  font-size: 13px;
}

/* ── Embed header ────────────────────────────────────────────────────────── */

.te-embed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line, rgba(255,255,255,.06));
  background: var(--bg-elev-2, #1b1f2a);
  gap: 10px;
}

.te-embed-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg, #eef0f4);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.te-fork-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(139,92,246,.15);
  color: #a78bfa;
  border: 1px solid rgba(139,92,246,.25);
}

.te-embed-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.te-action-link,
.te-action-btn {
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  color: var(--fg-mute, #9aa3b2);
  background: none;
  border: 1px solid var(--line, rgba(255,255,255,.06));
  border-radius: 5px;
  padding: 3px 8px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.te-action-link:hover,
.te-action-btn:hover {
  color: var(--fg, #eef0f4);
  border-color: var(--line-2, rgba(255,255,255,.10));
}

/* ── Table ───────────────────────────────────────────────────────────────── */

.te-table-wrap {
  overflow-x: auto;
}

.te-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: auto;
}

/* ── Headers ─────────────────────────────────────────────────────────────── */

.te-th {
  padding: 0;
  background: var(--bg-elev-2, #1b1f2a);
  border-right: 1px solid var(--line, rgba(255,255,255,.06));
  border-bottom: 1px solid var(--line-2, rgba(255,255,255,.10));
  white-space: nowrap;
  min-width: 120px;
  position: relative;
}

.te-th-num {
  width: 36px;
  min-width: 36px;
  border-right: 1px solid var(--line-2, rgba(255,255,255,.10));
}

.te-th-add {
  width: 36px;
  min-width: 36px;
  text-align: center;
  border-right: none;
}

.te-th-inner {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  cursor: default;
}

.te-col-icon {
  font-size: 10px;
  font-weight: 700;
  color: var(--fg-dim, #5c6474);
  width: 12px;
  text-align: center;
  flex-shrink: 0;
}

.te-col-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-mute, #9aa3b2);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.te-col-menu-btn {
  opacity: 0;
  background: none;
  border: none;
  color: var(--fg-mute, #9aa3b2);
  font-size: 11px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  border-radius: 3px;
  transition: opacity .15s, background .15s;
}
.te-th:hover .te-col-menu-btn { opacity: 1; }
.te-col-menu-btn:hover { background: var(--hover, rgba(255,255,255,.04)); }

.te-add-col-btn {
  width: 100%;
  background: none;
  border: none;
  color: var(--fg-dim, #5c6474);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color .15s;
}
.te-add-col-btn:hover { color: var(--fg, #eef0f4); }

/* ── Rows & cells ────────────────────────────────────────────────────────── */

.te-row:hover { background: var(--hover, rgba(255,255,255,.03)); }
.te-row:hover .te-row-del { opacity: 1; }

.te-td {
  border-right: 1px solid var(--line, rgba(255,255,255,.06));
  border-bottom: 1px solid var(--line, rgba(255,255,255,.06));
  padding: 0;
  vertical-align: middle;
}

.te-td-num {
  width: 36px;
  min-width: 36px;
  text-align: center;
  position: relative;
  border-right: 1px solid var(--line-2, rgba(255,255,255,.10));
}

.te-row-num {
  font-size: 11px;
  color: var(--fg-dim, #5c6474);
  user-select: none;
}

.te-row-del {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  background: none;
  border: none;
  color: var(--fg-dim, #5c6474);
  font-size: 14px;
  cursor: pointer;
  transition: opacity .15s, color .15s;
}
.te-row-del:hover { color: #f87171; }

.te-td-spacer {
  border-right: none;
  width: 36px;
}

.te-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--fg, #eef0f4);
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  box-sizing: border-box;
}
.te-input:focus { background: rgba(99,102,241,.06); }

.te-td-number .te-input { text-align: right; }

.te-checkbox {
  display: block;
  margin: 0 auto;
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: var(--accent, #6366f1);
}

.te-select {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--fg, #eef0f4);
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239aa3b2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}
.te-select:focus { background-color: rgba(99,102,241,.06); }

/* Add row */
.te-add-row-tr td { border-right: none; border-bottom: none; padding: 0; }
.te-add-row-btn {
  width: 100%;
  background: none;
  border: none;
  color: var(--fg-dim, #5c6474);
  font: inherit;
  font-size: 12px;
  padding: 6px 12px;
  text-align: left;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.te-add-row-btn:hover { color: var(--fg, #eef0f4); background: var(--hover, rgba(255,255,255,.03)); }

/* ── Column menu (dropdown) ──────────────────────────────────────────────── */

.te-col-menu {
  position: fixed;
  z-index: 500;
  background: var(--bg-elev-2, #1b1f2a);
  border: 1px solid var(--line-2, rgba(255,255,255,.10));
  border-radius: 10px;
  padding: 10px;
  min-width: 220px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.te-col-menu-input {
  width: 100%;
  background: var(--bg-elev, #14171f);
  border: 1px solid var(--line-2, rgba(255,255,255,.10));
  border-radius: 6px;
  color: var(--fg, #eef0f4);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 9px;
  outline: none;
  box-sizing: border-box;
}
.te-col-menu-input:focus { border-color: var(--accent, #6366f1); }

.te-col-menu-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--fg-dim, #5c6474);
  margin-bottom: 4px;
}

.te-col-menu-types { display: flex; flex-direction: column; gap: 2px; }

.te-col-type-btns { display: flex; flex-direction: column; gap: 2px; }

.te-col-type-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--fg-mute, #9aa3b2);
  font: inherit;
  font-size: 12px;
  padding: 5px 8px;
  cursor: pointer;
  text-align: left;
  transition: background .12s, color .12s, border-color .12s;
}
.te-col-type-btn:hover { background: var(--hover, rgba(255,255,255,.04)); color: var(--fg, #eef0f4); }
.te-col-type-btn.active {
  background: rgba(99,102,241,.12);
  border-color: rgba(99,102,241,.3);
  color: var(--accent, #6366f1);
}
.te-col-type-btn .te-col-icon { font-weight: 700; }

.te-col-menu-textarea {
  width: 100%;
  background: var(--bg-elev, #14171f);
  border: 1px solid var(--line-2, rgba(255,255,255,.10));
  border-radius: 6px;
  color: var(--fg, #eef0f4);
  font: inherit;
  font-size: 12px;
  padding: 6px 9px;
  outline: none;
  resize: vertical;
  box-sizing: border-box;
}
.te-col-menu-textarea:focus { border-color: var(--accent, #6366f1); }

.te-col-menu-del {
  width: 100%;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #f87171;
  font: inherit;
  font-size: 12px;
  padding: 5px 8px;
  cursor: pointer;
  text-align: left;
  transition: background .12s, border-color .12s;
}
.te-col-menu-del:hover { background: rgba(248,113,113,.08); border-color: rgba(248,113,113,.2); }

/* ── Tables library page ─────────────────────────────────────────────────── */

.tables-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg, #0d0f14);
  color: var(--fg, #eef0f4);
  font-family: var(--font-sans, system-ui, sans-serif);
}

.tables-sidebar {
  width: 240px;
  flex-shrink: 0;
  border-right: 1px solid var(--line, rgba(255,255,255,.06));
  display: flex;
  flex-direction: column;
  background: var(--bg-soft, #10131a);
  overflow: hidden;
}

.tables-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 10px;
  border-bottom: 1px solid var(--line, rgba(255,255,255,.06));
  flex-shrink: 0;
}

.tables-sidebar-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--fg, #eef0f4);
  letter-spacing: -.01em;
}

.tables-new-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent, #6366f1);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  transition: filter .15s;
}
.tables-new-btn:hover { filter: brightness(1.1); }

.tables-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.tables-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  cursor: pointer;
  border-radius: 0;
  transition: background .12s;
  border-left: 2px solid transparent;
}
.tables-list-item:hover { background: var(--hover, rgba(255,255,255,.04)); }
.tables-list-item.active {
  background: rgba(99,102,241,.08);
  border-left-color: var(--accent, #6366f1);
}

.tables-list-name {
  font-size: 13px;
  color: var(--fg, #eef0f4);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tables-list-fork {
  font-size: 10px;
  color: #a78bfa;
  flex-shrink: 0;
}

.tables-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tables-main-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line, rgba(255,255,255,.06));
  background: var(--bg-elev, #14171f);
  flex-shrink: 0;
}

.tables-back-link {
  font-size: 12px;
  color: var(--fg-mute, #9aa3b2);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.tables-back-link:hover { color: var(--fg, #eef0f4); }

.tables-title-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--fg, #eef0f4);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
}
.tables-title-input::placeholder { color: var(--fg-dim, #5c6474); }

.tables-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.tables-fork-btn,
.tables-del-btn {
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.tables-fork-btn {
  background: none;
  border: 1px solid var(--line-2, rgba(255,255,255,.10));
  color: var(--fg-mute, #9aa3b2);
}
.tables-fork-btn:hover { border-color: var(--accent, #6366f1); color: var(--fg, #eef0f4); }

.tables-del-btn {
  background: none;
  border: 1px solid transparent;
  color: #f87171;
}
.tables-del-btn:hover { background: rgba(248,113,113,.08); border-color: rgba(248,113,113,.2); }

.tables-content {
  flex: 1;
  overflow: auto;
  padding: 20px;
}

.tables-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--fg-dim, #5c6474);
  font-size: 14px;
}

.tables-lineage {
  font-size: 11px;
  color: var(--fg-dim, #5c6474);
  margin-bottom: 12px;
}
.tables-lineage a { color: var(--accent, #6366f1); text-decoration: none; }
.tables-lineage a:hover { text-decoration: underline; }

/* ── Doc block integration ───────────────────────────────────────────────── */

.doc-table-block {
  margin: 4px 0;
}

.doc-table-block .te-embed {
  margin: 0;
}

/* Table picker modal */
.table-picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}

.table-picker {
  background: var(--bg-elev, #14171f);
  border: 1px solid var(--line-2, rgba(255,255,255,.10));
  border-radius: 14px;
  width: 380px;
  max-width: calc(100vw - 32px);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0,0,0,.5);
  overflow: hidden;
}

.table-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line, rgba(255,255,255,.06));
  flex-shrink: 0;
}

.table-picker-title {
  font-size: 14px;
  font-weight: 700;
}

.table-picker-close {
  background: none;
  border: none;
  color: var(--fg-mute, #9aa3b2);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
}

.table-picker-body { overflow-y: auto; padding: 10px; flex: 1; }

.table-picker-new {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: rgba(99,102,241,.1);
  border: 1px dashed rgba(99,102,241,.3);
  border-radius: 8px;
  color: var(--accent, #6366f1);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 10px;
  transition: background .15s;
}
.table-picker-new:hover { background: rgba(99,102,241,.16); }

.table-picker-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 9px 12px;
  background: none;
  border: 1px solid var(--line, rgba(255,255,255,.06));
  border-radius: 8px;
  color: var(--fg, #eef0f4);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 6px;
  text-align: left;
  transition: background .12s, border-color .12s;
}
.table-picker-item:hover { background: var(--hover, rgba(255,255,255,.04)); border-color: var(--line-2); }
.table-picker-item-name { font-weight: 600; }
.table-picker-item-meta { font-size: 11px; color: var(--fg-dim, #5c6474); }
