/* ═══ Telegram Mini App — Vocabulary Manager ═══ */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #999999);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --border: rgba(0, 0, 0, 0.06);
  --danger: #ff3b30;
  --success: #34c759;
  --radius: 14px;
  --radius-sm: 10px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ═══ Modal scroll-lock ═══ */
body.modal-open {
  overflow: hidden;
  position: fixed;
  left: 0;
  right: 0;
}

/* ═══ Tabs — Segmented Control ═══ */

.tabs {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--secondary-bg);
  padding: 6px 10px 8px;
  gap: 4px;
}

.tab {
  flex: 1;
  border: none;
  background: none;
  color: var(--hint);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 4px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.tab.active {
  background: var(--btn);
  color: var(--btn-text);
  font-weight: 600;
}

.tab:active:not(.active) {
  background: rgba(0, 0, 0, 0.04);
}

/* ═══ Tab content ═══ */

.tab-content {
  display: none;
  padding: 0 12px 12px;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ═══ Search ═══ */

.search-wrapper {
  position: relative;
  margin-bottom: 10px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--hint);
  pointer-events: none;
}

.search-wrapper input {
  width: 100%;
  padding: 11px 12px 11px 42px;
  border: none;
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  outline: none;
  -webkit-appearance: none;
}

.search-wrapper input::placeholder {
  color: var(--hint);
}

/* ═══ Sort strip — chips ═══ */

.sort-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 2px 0;
}

.sort-strip::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.chip.active {
  background: var(--btn);
  color: var(--btn-text);
  border-color: var(--btn);
}

.chip:active { transform: scale(0.95); }

.sort-dir-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--hint);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  margin-left: auto;
  flex-shrink: 0;
}

.sort-dir-btn:active { transform: scale(0.95); }

.sort-dir-btn .arrow {
  display: inline-block;
  transition: transform 0.2s ease;
}

.sort-dir-btn[data-dir="asc"] .arrow {
  transform: rotate(180deg);
}

/* ═══ Filter panel ═══ */

.filter-section {
  margin-bottom: 10px;
}

.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--link);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 2px 0;
  -webkit-tap-highlight-color: transparent;
}

.filter-chevron {
  display: inline-block;
  transition: transform 0.2s ease;
  font-size: 12px;
}

.filter-toggle.open .filter-chevron {
  transform: rotate(90deg);
}

.filter-panel {
  display: none;
  padding-top: 8px;
}

.filter-panel.open {
  display: block;
  animation: slideDown 0.15s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.date-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.date-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.date-field input[type="date"] {
  width: 100%;
  padding: 9px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
}

.date-field input[type="date"]:focus {
  border-color: var(--btn);
}

/* ═══ Word cards ═══ */

.word-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.word-card:active {
  transform: scale(0.98);
}

.word-main {
  font-weight: 600;
  font-size: 16px;
  line-height: 1.3;
}

.word-plural {
  color: var(--hint);
  font-weight: 400;
  font-size: 14px;
}

.word-translation {
  margin-top: 3px;
  color: var(--hint);
  font-size: 14px;
}

.word-example {
  font-size: 13px;
  color: var(--hint);
  font-style: italic;
  margin-top: 5px;
  line-height: 1.4;
}

.word-date {
  font-size: 12px;
  color: var(--hint);
  margin-top: 6px;
  opacity: 0.6;
}

.empty-state {
  text-align: center;
  color: var(--hint);
  padding: 48px 20px;
  font-size: 15px;
}

/* ═══ Pagination ═══ */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 14px 0 24px;
}

.pagination.pagination-top {
  padding: 4px 0 10px;
}

.pagination button {
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--btn);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.pagination button:active:not(:disabled) {
  transform: scale(0.96);
}

.pagination button:disabled {
  opacity: 0.3;
  cursor: default;
}

#page-info {
  font-size: 13px;
  color: var(--hint);
  min-width: 48px;
  text-align: center;
}

/* ═══ Section cards ═══ */

.section-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.section-hint {
  font-size: 13px;
  color: var(--hint);
  line-height: 1.4;
  margin-bottom: 12px;
}

/* ═══ Forms ═══ */

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="date"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
  font-family: inherit;
  -webkit-appearance: none;
}

.form-group textarea {
  resize: none;
  overflow: hidden;
  min-height: 44px;
  line-height: 1.45;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--btn);
  box-shadow: 0 0 0 3px rgba(36, 129, 204, 0.08);
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

.modal-actions {
  padding-bottom: 8px;
}

/* ═══ Buttons ═══ */

.btn-primary {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--btn);
  color: var(--btn-text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:active { opacity: 0.8; }

.btn-danger {
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--danger);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-danger:active { opacity: 0.8; }

.btn-export {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px;
  border: 1.5px solid var(--btn);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--btn);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-export:active {
  background: var(--btn);
  color: var(--btn-text);
}

.btn-export svg {
  flex-shrink: 0;
}

/* ═══ Import ═══ */

.import-section p {
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 10px;
  line-height: 1.4;
}

.import-format {
  background: var(--secondary-bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 11px;
  color: var(--hint);
  margin-bottom: 14px;
  overflow-x: auto;
  white-space: pre;
  line-height: 1.6;
}

.import-divider {
  text-align: center;
  color: var(--hint);
  font-size: 13px;
  margin: 14px 0;
  opacity: 0.7;
}

.file-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.file-upload-area:active,
.file-upload-area.dragover {
  border-color: var(--btn);
  background: rgba(36, 129, 204, 0.04);
}

.upload-icon { font-size: 28px; margin-bottom: 6px; }
.upload-text { font-size: 14px; color: var(--hint); }
.upload-filename { font-size: 13px; color: var(--btn); margin-top: 4px; font-weight: 500; }

.import-textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 13px;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  outline: none;
  resize: vertical;
  line-height: 1.5;
}

.import-textarea:focus {
  border-color: var(--btn);
  box-shadow: 0 0 0 3px rgba(36, 129, 204, 0.08);
}

.import-textarea::placeholder {
  color: var(--hint);
  opacity: 0.6;
}

/* Import results */

.import-results {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--secondary-bg);
  font-size: 14px;
  line-height: 1.5;
  display: none;
}

.import-results.visible { display: block; }

.import-results.has-errors {
  border-left: 3px solid var(--danger);
}

.import-results.all-ok {
  border-left: 3px solid var(--success);
}

.result-summary {
  font-weight: 600;
  margin-bottom: 6px;
}

.result-errors {
  margin-top: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.error-item {
  font-size: 13px;
  color: var(--danger);
  margin-bottom: 4px;
  padding-left: 8px;
  border-left: 2px solid var(--danger);
}

/* ═══ Modal ═══ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 8px 16px 20px;
  animation: slideUp 0.25s ease-out;
  -webkit-overflow-scrolling: touch;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: rgba(0, 0, 0, 0.12);
  border-radius: 2px;
  margin: 4px auto 12px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
}

.modal-close {
  background: var(--secondary-bg);
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--hint);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

/* ═══ Toast ═══ */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: var(--bg);
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  max-width: calc(100% - 32px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ═══ Settings ═══ */

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.setting-info {
  flex: 1;
  padding-right: 12px;
}

.setting-label {
  font-size: 15px;
  font-weight: 400;
}

.setting-hint {
  font-size: 12px;
  color: var(--hint);
  margin-top: 2px;
  line-height: 1.3;
}

/* ═══ Toggle (iOS style) ═══ */

.toggle {
  position: relative;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 31px;
  cursor: pointer;
  transition: background 0.25s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 27px;
  height: 27px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.25s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.toggle input:checked + .toggle-slider {
  background: var(--success);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}
