.word-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    height:100%;
}

.word-links {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.word-links a {
    background: var(--card);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    text-decoration-line: none;
}

.word-controls {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    gap: 20px;
}

.label-input-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

#wordLanguageSelector {
    width: 120px;
}

#lessonSelector {
    width: 120px;
}

.search-container {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

#searchSelector {
    border: none;
}

#searchInput {
    width: 200px;
    border: none;
    border-left: 1px solid var(--border);
    border-radius: unset;
    background-color: unset;
}

.clear-btn {
    border: none;
    color: var(--muted);
    font-size: 1.5em;
    padding: 0 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    visibility: hidden;
}

.clear-btn.show {
    visibility: visible;
    opacity: 1;
}

.clear-btn:hover {
    color: var(--fg);
}

.action-menu-container {
    position: relative;
    display: inline-block;
}

.action-menu {
    position: absolute;
    top: 100%;
    right: 0;
    width: max-content;
    background-color: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
    z-index: 10;
    margin-top: 5px;
}

.action-menu.hidden {
    display: none;
}

.action-menu .menu-item {
    padding: 6px 12px;
    cursor: pointer;
}

.divider {
    width: 100%;
    height: 1px;
    background-color: var(--border);
}

.action-menu .menu-item:hover {
    background-color: var(--border);
}

.action-menu hr {
    margin: 4px 0;
    border: none;
    border-top: 1px solid #ddd;
}

.word-table {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    height:calc(100% - 100px);
}

.word-header {
    display: grid;
    font-weight: bold;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 5px 10px;
}

.word-header .col {
    padding: 5px 10px;
}

.word-header .col.click {
    cursor: pointer;
}

.word-header .col.click:hover {
    color: var(--muted);
}

.sort-icon {
    font-size: 0.75em;
    margin-left: 15px;
    color: var(--fg);
}

.word-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: scroll;
    height: auto;
}

.word-row {
    display: grid;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 5px;
}

.loading-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--muted);
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--muted);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.word-col {
    display: flex;
    padding: 0 10px;
    height: 100%;
    align-items: center;
}

.editable-col {
    cursor: text;
}

.editable-col:hover {
    color: var(--muted);
}

.inline-edit-input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--border);
    padding: 10px;
}

.word-tag-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.word-tag-container:hover {
    background-color: var(--border);
}

.word-term {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--fg);
}

.word-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.word-tag {
    font-size: 0.75rem;
    background: var(--border);
    color: var(--fg);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

.status-badge {
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    color: #fff;
}

.status-buttons {
    display: flex;
    gap: 5px;
}

.status-button, .btn-add-db, .btn-add-ai {
    width: 35px;
    height: 35px;
    border: 1px solid var(--border);
    border-radius: 50%;
    padding: unset;
}

:is(.status-button, .btn-add-db, .btn-add-ai):hover {
    background: var(--border);
}

.status-button.active {
    color: var(--border);
    font-weight: bold;
}

.status-button.ignored.active {
    background: #a4a4a4;
}

.status-button.learning1.active {
    background: #fae489;
}

.status-button.learning2.active {
    background: #ebea89;
}

.status-button.learning3.active {
    background: #dbef89;
}

.status-button.learning4.active {
    background: #ccf489;
}

.status-button.known.active {
    background: #bcfa89;
}

.delete-word-btn {
    width: 35px;
    height: 35px;
    border: 1px solid var(--border);
    border-radius: 50%;
    padding: unset;
}

.delete-word-btn:hover {
    color: #6f1a1a;
    background-color: #fa8989;
}


.voca-modal.hidden {
    display: none;
}

.voca-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1200;
}

.voca-modal-content {
    width: 800px;
    max-width: 90%;
    max-height: 80%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    overflow-y: scroll;
}

.voca-modal-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px;
}

#ttsButton {
    width: 35px;
    height: 35px;
    padding: 5px;
    border: none;
}

.voca-modal-top {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.voca-modal-term {
    font-size: 1.35em;
    font-weight: bold;
    color: var(--fg);
    word-break: break-word;
}

.voca-modal-definition {
    font-size: 1em;
    color: var(--muted);
    white-space: pre-wrap;
}

.voca-modal-main {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 15px;
    padding: 15px;
    overflow: hidden;
}

.voca-modal-left {
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow: hidden;
}

.voca-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.voca-section > span {
    margin-left: 5px;
    color: var(--fg);
    font-size: 1.1em;
    font-weight: bold;
}

.scrollable {
    border: 1px solid var(--border);
    padding: 10px;
    border-radius: 6px;
    background: transparent;
    max-height: 100px;
    overflow-y: auto;
    white-space: pre-wrap;
}

.voca-modal-right {
    margin-left: 20px;
    overflow: auto;
}

.voca-meta-row {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.voca-meta-row > div > span {
    color: var(--fg);
    font-size: 1.1em;
    font-weight: bold;
}

.voca-status-badge {
    display: inline-block;
    margin-left: 10px;
    font-size: 0.75rem;
    background: var(--border);
    color: var(--fg);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

.voca-pos, .voca-related {
    white-space: pre-wrap;
    color: var(--fg);
    margin-top: 5px;
}

.voca-created, .voca-updated {
    color: var(--muted);
}

.create-mode-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.create-mode-tabs > .mode-button {
    border: 1px solid var(--border);
    background: var(--card);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
}

.create-mode-tabs > .mode-button.active {
    background: var(--border);
    font-weight: bold;
}

.modal-title {
    font-weight: bold;
    font-size: 1.35em;
}

.modal-main {
    display: flex;
    flex-direction: column;
    padding: 15px;
}

#singleWordSection, #batchUploadSection {
    flex-direction: column;
    gap: 15px;
}

.modal-label-input {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal-label-input > label {
    margin-left: 5px;
}

.modal-label-input > select {
    width: fit-content;
}

.modal-input-explanation {
    color: var(--muted);
}

#createWordMoreOptions {
    display: none;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    gap: 10px;
}

.modal-button-container {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.generate-inputs {
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

/* --- COMPACT CARD MODE (≤900px) --- */
@media (max-width:900px){
#navHomeHolder {
    display: none;
}
  /* Controls: wrap + breathe */
  .word-controls{
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px 10px;
  }
  .word-controls .search-container{ flex: 1 1 100%; }
  .word-controls .action-menu-container{ flex: 1 1 auto; }

  /* Table into cards */
  .word-header{ display:none; }
  .word-table{ padding: 6px; }
  .word-body{ gap: 8px; }

  .word-row{
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 10px 10px 10px;
    border-radius: 10px;
  }

  /* reduce default padding inside cells */
  .word-row .word-col{ padding:0; }

  /* Show core pieces; hide extras until expanded */
  .word-row .word-col.is-extra{ display:none; }
  .word-row.expanded .word-col.is-extra{ display:flex; }

  /* TERM prominence */
  .word-row .word-col[data-col="term"] .word-term{ font-size: 16px; }

  /* Status block spacing */
  .word-row .word-col[data-col="status"]{ margin-top: 6px; }

  /* Hide select/delete on mobile; you can re-enable if needed */
  .word-row .word-col[data-col="select"],
  .word-row .word-col[data-col="delete"]{ display:none; }

  /* Expand toggle button */
  .row-toggle{
    position:absolute;
    top:8px; right:8px;
    width:28px; height:28px;
    display:inline-flex; align-items:center; justify-content:center;
    border:1px solid var(--border);
    border-radius:999px;
    background:var(--card);
    color:var(--fg);
    font-size:14px;
    line-height:1;
  }
  .row-toggle:after{ content:"▾"; }
  .word-row.expanded .row-toggle:after{ content:"▴"; }
}

/* Make inline editor comfy everywhere */
.inline-edit-input{
  font: inherit;          /* match table text */
  line-height: 1.35;      /* stop text “collapse” */
  height: auto;           /* let content size the input */
  min-height: 38px;       /* good desktop target */
}

/* Mobile tweaks */
@media (max-width:900px){
  /* cells should grow with content */
  .word-row .word-col{ 
    height: auto; 
    align-items: flex-start;  /* don't vertically center inputs */
  }

  /* editable cells stretch the input full width */
  .word-row .editable-col{ 
    align-items: stretch; 
  }

  /* bigger touch target on phones */
  .word-row .inline-edit-input{
    padding: 12px; 
    min-height: 44px;       /* thumbs-up size */
    display: block;         /* avoid any flex oddities */
  }
}

/* Keep select-all header on mobile */
@media (max-width:900px){
  /* show the header again */
  .word-header{
    display: grid;
    grid-template-columns: auto;      /* only the checkbox */
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    z-index: 2;
  }
  /* hide all header cells... */
  .word-header .col{ display:none; }
  /* ...except the checkbox cell */
  .word-header .col.col-checkbox{
    display: flex;
    align-items: center;
    gap: 8px;
  }

  /* keep row checkboxes hidden in card mode (as before) */
  .word-row .word-col[data-col="select"]{ display:none; }

  /* (optional) a tiny "All" label next to the box if you add it in JS */
  .word-header .sel-all-lab{
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
  }
}

/* hide that label on desktop (optional) */
@media (min-width:901px){
  .word-header .sel-all-lab{ display:none; }
}

/* Layout: top area + table fill vertical space and reflow correctly */
.word-section{
  display:flex;
  flex-direction:column;
  gap:12px;
  min-height:0;           /* critical for flex scroll children */
}

.word-table{
  display:flex;
  flex-direction:column;
  gap:10px;
  flex:1 1 auto;          /* replaces any fixed heights */
  min-height:0;           /* allow internal scrolling */
  position:relative;
  z-index:1;
}

.word-body{
  display:flex;
  flex-direction:column;
  gap:10px;
  overflow-y:auto;
  flex:1 1 auto;
  min-height:0;
}


/* --- stacking-only patch (no colors, no JS) --- */
.word-section{ position:relative; }

/* filters/links must sit above the table + sticky header */
.word-links,
.word-controls{
  position:relative;
  z-index:200;            /* above header & table */
}

/* keep table bits below controls */
.word-table,
.word-body{
  position:relative;
  z-index:1 !important;
}

/* sticky header stays under the filters */
.word-header{
  position:sticky;        /* keep whatever you already had */
  top:0;                  /* keep your existing value */
  z-index:10 !important;  /* below .word-controls/.word-links */
}

/* (optional) if any row/cell had a higher z-index, cap it */
.word-row,[class*="word-col"]{ z-index:1; position:relative; }

/* ========== Filters toggle visibility ========== */
@media (max-width: 900px){
  /* hide filters when collapsed */
  .word-controls.collapsed { display: none !important; }
  /* show the Filters button only on mobile */
  .mobile-only { display: inline-flex !important; }
}
@media (min-width: 901px){
  /* hide the Filters button on desktop */
  .mobile-only { display: none !important; }
}

/* ========== Modals on mobile: full screen + single column ========== */
@media (max-width: 900px){
  .voca-modal .voca-modal-content{
    width: auto !important;
    height: auto !important;
    max-width: 94vw !important;
    max-height: 86vh !important;
    border-radius: 10px !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* still stack the panels for readability */
  .voca-modal .voca-modal-main{
    grid-template-columns: 1fr !important;
    gap: 12px;
  }
  .voca-modal-right{ margin-left: 0 !important; }
}

/* Optional: prevent background from scrolling while a modal is open */
body[voca-lock="1"]{ overflow: hidden !important; }

/* ==== Modal: consistent sizing + mobile polish ==== */

/* Give the backdrop a margin so you can tap outside to close */
.voca-modal { padding: 16px; }

/* One layout for all modals (desktop base) */
.voca-modal-content{
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow: hidden;                  /* inner section will scroll */
  width: min(720px, calc(100vw - 32px));
  max-height: min(90svh, 780px);     /* safe on iOS toolbars */
  border-radius: 12px;
}

/* Keep modal header visible while the body scrolls */
.voca-modal-header{
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}

/* The scroll happens here */
.voca-modal-main,
.modal-main{
  overflow: auto;
  min-height: 0;
  padding: 12px 16px;
}

/* Word modal: stack the two columns when needed */
@media (max-width: 900px){
  .voca-modal .voca-modal-main{ 
    display: grid;
    grid-template-columns: 1fr !important;
    gap: 12px;
  }
  .voca-modal-right{ margin-left: 0 !important; }
}

/* Inputs should never force horizontal scroll */
.modal-label-input > input,
.modal-label-input > select,
.modal-label-input > textarea,
#createWordMoreOptions .create-input,
#createWordMoreOptions .create-select,
#createWordExamples.create-textarea{
  width: 100%;
  max-width: none;
  box-sizing: border-box;
}

/* "More options" panel: scroll independently so it never overflows */
#createWordMoreOptions{
  max-height: 50vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* Generate modal inputs: stack on mobile */
@media (max-width: 900px){
  .generate-inputs{
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

/* Force SAME width on mobile (beats inline width="650px") */
@media (max-width: 900px){
  #vocaModal .voca-modal-content,
  #createWordModal .voca-modal-content,
  #generateVocaModal .voca-modal-content{
    width: calc(100vw - 32px) !important;
    max-width: calc(100vw - 32px) !important;
    max-height: 88svh;
  }
}

/* Visible close button */
.modal-close{
  margin-left: auto;
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
}
.modal-close:hover{ background: var(--border); }
