/* =========================================
   Table Component
   ========================================= */
table {
  border-collapse: collapse;
  width: 100%;
  margin: 0;
  table-layout: fixed;
}

table thead {
  background-color: var(--bg-surface-alt);
  border-bottom: 2px solid var(--border-color-strong);
}

table th,
table td {
  padding: 0.75em 1em;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  border-right: 2px solid var(--border-color);
  border-left: 2px solid var(--border-color);
  position: relative;
  /* Allow wrapping up to 3 lines */
  max-height: 4.8em;
  overflow: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
  text-overflow: ellipsis;
  white-space: normal;
}

table th:first-child,
table td:first-child {
  border-left: none;
}

table th:last-child,
table td:last-child {
  border-right: none;
}

table th {
  font-weight: 600;
  color: var(--text-main);
  user-select: none; /* Resize handle requirement */
}

table tbody tr:hover {
  background-color: var(--bg-surface-hover);
}

/* Remove bottom border from last row */
table tbody tr:last-child td {
  border-bottom: none;
}

/* Wrapper & Scroll */
.table-wrapper {
  margin: 1.5em 0;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  max-width: 100%;
}

.table-scroll-container {
  overflow-x: auto;
  overflow-y: visible;
}

.table-wrapper table {
  margin: 0;
  border: none;
}

/* =========================================
   Interactive Features (Drag/Resize)
   ========================================= */

/* Highlight borders that can be resized */
table th.resize-left {
  border-left: 2px solid var(--color-primary);
}
table th.resize-right {
  border-right-color: var(--color-primary);
}

/* Drag feedback */
table th.dragging {
  opacity: 0.4;
}

table th.drag-over-left {
  border-left: 4px solid var(--color-primary) !important;
  box-shadow: -2px 0 4px var(--color-primary-transparent);
}

table th.drag-over-right {
  border-right: 4px solid var(--color-primary) !important;
  box-shadow: 2px 0 4px var(--color-primary-transparent);
}

/* =========================================
   Table Control Panel
   ========================================= */
.table-control-panel {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.3em 1em;
  background-color: var(--bg-surface-alt);
  border-top: 1px solid var(--border-color);
  gap: 0.3em;
}

.filter-controls {
  display: flex;
  gap: 1em;
  flex-wrap: wrap;
  align-items: flex-start;
  flex: 1;
}

/* Buttons */
.filter-btn,
.font-btn,
.table-copy-btn {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color-strong);
  color: var(--text-main);
  padding: 0.3em 0.8em;
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 0.85em;
  font-weight: 500;
  border-radius: 3px;
  transition: all 0.2s;
}

.table-copy-btn.copied {
  color: var(--color-primary);
}

/* Specific component tweaks */
.font-btn {
  min-width: 32px;
  padding: 0.3em 0.6em;
}
.table-copy-btn {
  background: none;
  border: none;
  display: flex;
  align-items: center;
}
.table-copy-btn svg {
  width: 20px;
  height: 20px;
  pointer-events: none;
}

/* Hover states */
.filter-btn:hover,
.font-btn:hover,
.table-copy-btn:hover {
  background-color: var(--bg-surface-hover);
  border-color: #bbb; /* Keep slight generic darken on hover */
}
body.dark-mode .filter-btn:hover,
body.dark-mode .font-btn:hover,
body.dark-mode .table-copy-btn:hover {
  border-color: #555;
}

/* Dropdowns (Column Selector & Hints) */
.column-selector,
.row-selector {
  position: relative;
}

.column-dropdown,
.hint-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0.25em;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color-strong);
  border-radius: 3px;
  box-shadow: 0 4px 12px var(--shadow-color, rgba(0, 0, 0, 0.15));
  z-index: 1000;
}
body.dark-mode .column-dropdown,
body.dark-mode .hint-dropdown {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.column-dropdown {
  padding: 0.5em;
  min-width: 180px;
  max-height: 300px;
  overflow-y: auto;
}

.column-option {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.3em 0.5em;
  cursor: pointer;
  border-radius: 3px;
  transition: background-color 0.2s;
  font-size: 0.85em;
}
.column-option:hover {
  background-color: var(--bg-surface-hover);
}
.column-option span {
  user-select: none;
}

/* Row Search Input */
.row-selector {
  display: flex;
  gap: 0.5em;
  align-items: center;
}

.row-input {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color-strong);
  color: var(--text-main);
  padding: 0.3em 0.6em;
  font-family: var(--font-main);
  font-size: 0.85em;
  border-radius: 3px;
  width: 220px;
}
.row-input::placeholder {
  color: var(--text-muted);
  font-size: 0.9em;
}
.row-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* Hint System */
.hint-btn {
  background-color: var(--color-primary);
  border: none;
  color: white; /* Always white text on primary button */
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 0.85em;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
  flex-shrink: 0;
}
.hint-btn:hover {
  background-color: var(--color-primary-hover);
}

.hint-dropdown {
  padding: 0.75em;
  min-width: 300px;
  max-width: 400px;
  max-height: 300px;
  overflow-y: auto;
  font-size: 0.85em;
}

.hint-header {
  font-weight: 600;
  margin-bottom: 0.5em;
  color: var(--text-main);
}

.hint-item {
  padding: 0.3em 0.2em;
  color: var(--text-main);
}

.hint-item code {
  background-color: var(--bg-surface-hover);
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-family: var(--font-mono);
  color: var(--color-primary);
  font-size: 0.95em;
}

.hint-original {
  color: var(--text-muted);
  font-size: 0.9em;
  font-style: italic;
}

.hint-example {
  margin-top: 0.75em;
  padding-top: 0.75em;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.9em;
}

.hint-example code {
  background-color: var(--bg-surface-hover);
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-family: var(--font-mono);
  color: var(--text-main);
  font-size: 0.95em;
  display: inline-block;
  margin-top: 0.25em;
}

/* Font & Copy Controls */
.font-controls,
.copy-controls,
.table-controls-group,
.input-btns-group {
  display: flex;
  gap: 0.5em;
  align-items: center;
}
.table-controls-group {
  flex-direction: row;
}

.font-size-display {
  font-size: 0.85em;
  color: var(--text-muted);
  min-width: 40px;
  text-align: center;
}

.reset-cols-btn {
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 0.85em;
  text-decoration: underline;
  padding: 0;
}

/* Table Responsive */
@media (max-width: 768px) {
  table {
    font-size: 0.9em;
  }
  table th,
  table td {
    padding: 0.5em 0.7em;
  }

  .table-control-panel {
    flex-direction: column;
    align-items: flex-start;
  }
  .filter-controls {
    width: 100%;
  }
  .row-input {
    flex: 1;
    min-width: 150px;
  }
  .hint-dropdown {
    min-width: 280px;
    max-width: 90vw;
  }

  .font-controls,
  .copy-controls {
    width: 100%;
  }
  .table-copy-btn {
    width: 30%;
  }
}
