@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

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

:root {
  --blue:    #2563EB;
  --blue-bg: #EFF6FF;
  --text:    #111827;
  --muted:   #6B7280;
  --border:  #E5E7EB;
  --surface: #F9FAFB;
  --red:     #dc2626;

  --badge-info-text:  #1d4ed8; --badge-info-bg:  #dbeafe;
  --badge-trans-text: #15803d; --badge-trans-bg: #dcfce7;
  --badge-nav-text:   #c2410c; --badge-nav-bg:   #ffedd5;
  --badge-com-text:   #be185d; --badge-com-bg:   #fce7f3;

  --radius-sm: 4px;
  --radius-lg: 8px;
  --shadow-modal: 0 20px 40px rgba(0,0,0,.12), 0 4px 12px rgba(0,0,0,.08);
}

html { font-size: 14px; }
body {
  font-family: 'Inter', sans-serif;
  color: var(--text);
  background: #fff;
  min-height: 100vh;
}

/* ── Auth screen ────────────────────────────── */
#auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  z-index: 200;
}

.auth-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 24px rgba(0,0,0,.06);
}

.auth-logo {
  display: block;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 20px;
}

.auth-title {
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 24px;
}

.auth-error {
  display: block;
  margin-bottom: 12px;
  text-align: center;
}

.btn-full {
  width: 100%;
  justify-content: center;
  margin-top: 4px;
}

.auth-switch {
  text-align: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--muted);
}

.auth-link {
  border: none;
  background: none;
  color: var(--blue);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  margin-left: 4px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── Header ─────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  height: 52px;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 10;
  gap: 0;
}

.header-logo {
  font-size: 15px;
  font-weight: 600;
  color: var(--blue);
  white-space: nowrap;
  flex-shrink: 0;
  margin-right: 24px;
}

.tabs {
  display: flex;
  align-items: stretch;
  height: 100%;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab-item {
  display: flex;
  align-items: stretch;
  height: 100%;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  height: 100%;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--blue);
  font-weight: 600;
  border-bottom-color: var(--blue);
}

.tab-count {
  font-size: 11px;
  font-weight: 500;
  background: var(--border);
  color: var(--muted);
  border-radius: 20px;
  padding: 1px 6px;
  line-height: 16px;
}
.tab.active .tab-count {
  background: var(--blue-bg);
  color: var(--blue);
}

.tab-del {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  visibility: hidden;
  padding: 0;
  margin-left: -6px;
  transition: color .12s;
  flex-shrink: 0;
}
.tab-item:hover .tab-del { visibility: visible; }
.tab-del:hover { color: var(--red); }

.tab-add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  margin: auto 0 auto 8px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color .12s, color .12s, background .12s;
}
.tab-add:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-bg);
}
.tab-add svg { width: 13px; height: 13px; }

/* ── Header user section ────────────────────── */
.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 16px;
  flex-shrink: 0;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 99px;
  background: var(--blue-bg);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  font-family: inherit;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, color .12s;
}
.btn-logout:hover { background: var(--surface); color: var(--text); }

/* ── Main ───────────────────────────────────── */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 32px 48px;
}

/* ── No-categories empty state ──────────────── */
.no-cats {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 52px - 76px);
}
.no-cats-inner {
  text-align: center;
  max-width: 300px;
}
.no-cats-icon {
  width: 56px;
  height: 56px;
  margin-bottom: 16px;
}
.no-cats-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
}
.no-cats-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 20px;
}

/* ── Toolbar ────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 10px;
  width: 15px;
  height: 15px;
  color: var(--muted);
  pointer-events: none;
}
.search-input {
  height: 36px;
  padding: 0 12px 0 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  width: 220px;
  outline: none;
  transition: border-color .15s;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus { border-color: var(--blue); }

.select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: #fff;
  cursor: pointer;
  outline: none;
  transition: border-color .15s;
}
.select:focus { border-color: var(--blue); }

/* ── Buttons ────────────────────────────────── */
.btn-primary {
  height: 36px;
  padding: 0 16px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.btn-primary:hover { background: #1d4ed8; }

.btn-danger {
  height: 36px;
  padding: 0 16px;
  background: #fff;
  color: var(--red);
  border: 1px solid #fca5a5;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn-danger:hover { background: #fee2e2; border-color: var(--red); }

.btn-secondary {
  height: 36px;
  padding: 0 16px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-secondary:hover { background: var(--surface); border-color: #d1d5db; }

/* ── Table ──────────────────────────────────── */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.table {
  width: 100%;
  border-collapse: collapse;
}
.table thead tr {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}
.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--blue-bg); }

.cell-keyword { font-weight: 600; }
.cell-difficulty { min-width: 140px; }

.diff-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.diff-bar-bg {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.diff-bar-fill {
  height: 100%;
  border-radius: 99px;
}
.diff-pct {
  font-size: 12px;
  color: var(--muted);
  min-width: 30px;
  text-align: right;
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-info  { background: var(--badge-info-bg);  color: var(--badge-info-text); }
.badge-trans { background: var(--badge-trans-bg); color: var(--badge-trans-text); }
.badge-nav   { background: var(--badge-nav-bg);   color: var(--badge-nav-text); }
.badge-com   { background: var(--badge-com-bg);   color: var(--badge-com-text); }

.cell-actions { display: flex; gap: 4px; }
.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--muted);
  transition: background .12s, color .12s;
}
.action-btn:hover { background: var(--border); color: var(--text); }
.action-btn.delete:hover { background: #fee2e2; color: var(--red); }
.action-btn svg { width: 15px; height: 15px; }

.empty {
  display: none;
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
}
.empty.show { display: block; }

/* ── Modals ─────────────────────────────────── */
.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(2px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.backdrop.open { display: flex; }

.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow-modal);
}
.modal-sm { max-width: 360px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title {
  font-size: 15px;
  font-weight: 600;
}
.modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
}
.modal-close:hover { background: var(--border); color: var(--text); }

.field { margin-bottom: 16px; }
.label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  margin-bottom: 6px;
}
.label-optional {
  font-weight: 400;
  color: #9ca3af;
  font-size: 11.5px;
}
.input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.input:focus { border-color: var(--blue); }
.input.error { border-color: var(--red); }

.field-error {
  display: block;
  font-size: 11.5px;
  color: var(--red);
  margin-top: 4px;
  min-height: 16px;
}

.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 99px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  background: #fff;
  cursor: pointer;
  transition: border-color .12s, background .12s, color .12s;
}
.pill:hover { border-color: var(--blue); color: var(--blue); }
.pill.selected { border-color: var(--blue); background: var(--blue); color: #fff; }

.import-msg {
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 4px;
}
.import-msg-success { color: #16a34a; }
.import-msg-error   { color: var(--red); }
.import-msg-muted   { color: var(--muted); }

.import-errors {
  margin-top: 12px;
  font-size: 12.5px;
}
.import-errors summary {
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.import-errors ul {
  margin-top: 8px;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.9;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── kw-view layout ─────────────────────────── */
#kw-view {
  display: flex;
  flex-direction: column;
}

.kw-content {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  min-height: 0;
}

.kw-content .table-wrap {
  flex: 1;
  min-width: 0;
}

/* ── Projects sidebar ───────────────────────── */
.projects-sidebar {
  width: 200px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #fff;
  overflow: hidden;
  position: sticky;
  top: 68px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

.sidebar-add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
  flex-shrink: 0;
}
.sidebar-add-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-bg);
}
.sidebar-add-btn svg { width: 11px; height: 11px; }

.projects-list {
  padding: 6px 0;
}

.projects-empty {
  padding: 16px 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.project-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  cursor: pointer;
  transition: background .12s;
  gap: 6px;
}
.project-item:hover { background: var(--surface); }
.project-item.active { background: var(--blue-bg); }

.project-name {
  font-size: 13px;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}
.project-item.active .project-name {
  color: var(--blue);
  font-weight: 500;
}

.project-del {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  visibility: hidden;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  transition: color .12s, background .12s;
}
.project-item:hover .project-del { visibility: visible; }
.project-del:hover { color: var(--red); background: #fee2e2; }

/* ── Publish toggle ─────────────────────────── */
.th-publish { text-align: center; }
.cell-publish { text-align: center; }

.toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  cursor: pointer;
  vertical-align: middle;
}
.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 20px;
  transition: background .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle-slider { background: var(--blue); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }
