/* Vocab - personal English dictionary for the WebRead extension.
   Layout language mirrors the Notepad PWA: fixed sidebar + main pane,
   collapsible groups, color-coded cards, floating dialogs. */

:root {
  --bg: #f0f2f5;
  --pane: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #1d4ed8;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --star: #f59e0b;
  --sidebar-w: 264px;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(17, 24, 39, 0.12);
}

* { box-sizing: border-box; }

/* The hidden attribute must win even over display:flex/inline-block classes. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button { font: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 650; }
ul { list-style: none; margin: 0; padding: 0; }

#app { display: flex; height: 100%; }

/* ---------------------------------------------------------------- sidebar */

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: #f8fafc;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 12px;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 9px; padding: 2px 4px; }
.brand img { width: 26px; height: 26px; }
.brand h1 { font-size: 18px; letter-spacing: -0.3px; }

.search-wrap { position: relative; }
#search {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font-size: 13px;
}
#search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.tabs { display: flex; flex-direction: column; gap: 2px; }
.tab {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border: 0;
  background: none;
  border-radius: 9px;
  text-align: left;
  color: var(--ink);
  font-size: 13.5px;
}
.tab:hover { background: #eef1f6; }
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.count {
  min-width: 20px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}
.tab.active .count { color: var(--accent); }

.group-list { display: flex; flex-direction: column; gap: 1px; }
.group-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  background: none;
  border-radius: 8px;
  font-size: 13px;
  color: var(--muted);
  text-align: left;
}
.group-item:hover { background: #eef1f6; color: var(--ink); }
.group-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.group-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-count { font-size: 11px; }

.side-actions { display: flex; flex-direction: column; gap: 7px; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 13px;
}
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1e40af; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; text-align: center; }
.btn.icon-only { padding: 5px 9px; }

.cloud-box {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.cloud-user { display: flex; align-items: center; gap: 8px; padding: 2px 0 4px; }
.cloud-user img, #cloud-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--line);
}
.cloud-email { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 170px; }
.cloud-status { font-size: 11px; color: var(--muted); }
.cloud-status.ok { color: #15803d; }
.cloud-status.error { color: var(--danger); }
.cloud-status.syncing { color: var(--accent); }
.cloud-setup { font-size: 11px; color: var(--muted); }

.side-footer { display: flex; align-items: center; gap: 8px; padding-top: 6px; border-top: 1px solid var(--line); }
.offline-badge { font-size: 11px; color: var(--danger); }

/* ------------------------------------------------------------------- main */

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--pane);
}
#btn-menu { display: none; }
.toolbar-right { margin-left: auto; display: flex; gap: 7px; align-items: center; }
.batch-bar { display: flex; align-items: center; gap: 7px; }
.batch-count { font-size: 12.5px; color: var(--accent); font-weight: 600; }
.select {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 12.5px;
}

#content { flex: 1; display: flex; min-height: 0; }

.entry-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 24px;
}
.group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 14px 2px 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.group-header:first-child { margin-top: 2px; }
.group-header .arrow { display: inline-block; transition: transform 0.12s; }
.group-header.collapsed .arrow { transform: rotate(-90deg); }

.entry-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin: 0 0 8px;
  background: var(--pane);
  border: 1px solid var(--line);
  border-left: 4px solid var(--note-color, transparent);
  border-radius: 10px;
  cursor: pointer;
}
.entry-card:hover { border-color: #c7d2fe; border-left-color: var(--note-color, #c7d2fe); }
.entry-card.active { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.entry-card input[type="checkbox"] { accent-color: var(--accent); }
.entry-main { flex: 1; min-width: 0; }
.entry-word { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-trans { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-def { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-side { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.entry-group-chip {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.star { color: var(--star); font-size: 14px; }

.empty-state { padding: 60px 20px; text-align: center; }
.empty-state p { margin: 4px 0; font-size: 15px; }
.muted { color: var(--muted); font-size: 12.5px; }
.error { color: var(--danger); font-size: 12.5px; }

/* ----------------------------------------------------------------- editor */

.editor {
  width: 380px;
  min-width: 320px;
  border-left: 1px solid var(--line);
  background: var(--pane);
  overflow-y: auto;
  padding: 14px 16px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.editor-head { display: flex; align-items: center; gap: 8px; }
.editor-head-actions { margin-left: auto; display: flex; gap: 6px; }
.editor-meta { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.field { display: block; }
.field > span { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; color: #374151; }
.field input, .field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font: inherit;
  font-size: 13.5px;
  background: #fff;
  color: var(--ink);
}
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field-row { display: flex; gap: 12px; align-items: flex-start; }
.field.grow { flex: 1; }

.color-palette { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px 0; }
.color-swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line);
  padding: 0;
}
.color-swatch.selected { box-shadow: 0 0 0 2px var(--accent); }
.color-swatch.none { background: repeating-linear-gradient(45deg, #f3f4f6, #f3f4f6 4px, #fff 4px, #fff 8px); }

.source-line {
  font-size: 12px;
  color: var(--muted);
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  word-break: break-all;
}
.source-line a { color: var(--accent); }

.editor-actions { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.save-status { font-size: 12px; color: #15803d; }

/* -------------------------------------------------------------- statusbar */

#statusbar {
  display: flex;
  gap: 14px;
  padding: 6px 14px;
  border-top: 1px solid var(--line);
  background: var(--pane);
  font-size: 11.5px;
  color: var(--muted);
}

/* ---------------------------------------------------------------- dialogs */

.dialog {
  border: 0;
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px;
  width: 360px;
  max-width: calc(100vw - 32px);
}
.dialog.wide { width: 560px; }
.dialog::backdrop { background: rgba(17, 24, 39, 0.35); }
.dialog h3 { margin-bottom: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.dialog-actions.column { flex-direction: column; align-items: stretch; }
.dialog input[type="text"], .dialog input[type="password"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font: inherit;
  font-size: 13.5px;
}
.check { display: flex; align-items: center; gap: 7px; margin: 10px 0; font-size: 13px; }
.check input { accent-color: var(--accent); }

.cloud-list { max-height: 320px; overflow-y: auto; margin-top: 8px; }
.cloud-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 6px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
}
.cloud-list .cl-title { font-weight: 600; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cloud-list .cl-meta { color: var(--muted); font-size: 11px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cloud-list input, .cloud-list .btn { accent-color: var(--accent); }
.cloud-list .empty { color: var(--muted); justify-content: center; border: 0; }

.dropzone {
  border: 2px dashed var(--line);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: #111827;
  color: #f9fafb;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: 80vw;
}

/* ------------------------------------------------------------ update card */

/* Sits above the toast (z-index 60) so the two never overlap ambiguously. */
.update-card {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 70;
  width: 340px;
  max-width: calc(100vw - 32px);
  background: var(--pane);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: update-slide-in 0.18s ease-out;
}
.update-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: var(--accent);
  color: #fff;
}
.update-head h3 { font-size: 13.5px; }
.update-close {
  margin-left: auto;
  border: 0;
  background: none;
  color: #fff;
  font-size: 13px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 6px;
}
.update-close:hover { background: rgba(255, 255, 255, 0.2); }
.update-body { display: flex; flex-direction: column; gap: 9px; padding: 11px 12px 12px; }
.update-text { margin: 0; font-size: 12.8px; }
.update-build { margin: 0; font-size: 11px; color: var(--muted); }
.update-build code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.update-actions { display: flex; justify-content: flex-end; gap: 8px; }

@keyframes update-slide-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .update-card { animation: none; }
}

/* -------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  #sidebar {
    position: fixed;
    z-index: 40;
    top: 0; bottom: 0; left: 0;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow);
  }
  #sidebar.open { transform: translateX(0); }
  #btn-menu { display: inline-block; }

  .editor {
    position: fixed;
    z-index: 30;
    top: 0; right: 0; bottom: 0;
    width: min(430px, 100vw);
    box-shadow: var(--shadow);
  }
}

@media (max-width: 640px) {
  .toolbar-right .btn small, #btn-import, #btn-export { padding: 5px 8px; }
  .entry-trans { white-space: normal; }

  /* A narrow banner along the bottom edge, not a full-screen takeover. */
  .update-card { left: 12px; right: 12px; bottom: 12px; width: auto; }
}
