:root {
  color-scheme: dark;
  --bg: #0d0d0b;
  --bg-soft: #151411;
  --panel: rgba(30, 29, 24, .82);
  --panel-solid: #1d1b17;
  --line: rgba(235, 220, 183, .14);
  --line-strong: rgba(235, 220, 183, .24);
  --text: #f3ead8;
  --muted: #a99f8b;
  --soft: #d8c9aa;
  --gold: #c6a35b;
  --green: #9bb7b0;
  --rust: #b98368;
  --danger: #d78373;
  --shadow: 0 24px 80px rgba(0, 0, 0, .42);
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Source Serif 4", Georgia, serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f4ed;
  --bg-soft: #eee7d9;
  --panel: rgba(255, 252, 245, .86);
  --panel-solid: #fffaf0;
  --line: rgba(65, 51, 27, .16);
  --line-strong: rgba(65, 51, 27, .28);
  --text: #17130d;
  --muted: #756a58;
  --soft: #3f3526;
  --gold: #9c7429;
  --green: #4f7771;
  --rust: #a55f42;
  --danger: #a64235;
  --shadow: 0 22px 70px rgba(70, 53, 24, .16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(198, 163, 91, .05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(198, 163, 91, .04) 1px, transparent 1px),
    radial-gradient(circle at 82% 10%, rgba(155, 183, 176, .16), transparent 28rem),
    linear-gradient(135deg, var(--bg) 0%, var(--bg-soft) 52%, var(--bg) 100%);
  background-size: 72px 72px, 72px 72px, auto, auto;
  color: var(--text);
  font-family: var(--sans);
  letter-spacing: 0;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

svg {
  width: 20px;
  height: 20px;
}

.app-shell {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(22px);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line-strong);
  background: linear-gradient(145deg, color-mix(in srgb, var(--panel-solid) 74%, var(--gold)), var(--bg));
  color: var(--gold);
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 700;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 17px;
}

.brand small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.page-nav {
  display: grid;
  gap: 8px;
}

.page-nav a {
  padding: 13px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--soft);
  transition: background .18s ease, border-color .18s ease, color .18s ease;
}

.page-nav a:hover,
.page-nav a.active {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, .045);
  color: var(--text);
}

.page-nav span,
.page-nav small {
  display: block;
}

.page-nav span {
  font-size: 14px;
  font-weight: 700;
}

.page-nav small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.sidebar-footer a,
.export-strip a,
.drawer-exports a {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--soft);
  background: rgba(255, 255, 255, .035);
  font-size: 12px;
  font-weight: 700;
}

.sidebar-footer a {
  padding: 11px 12px;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto auto auto;
  gap: 12px;
  align-items: center;
}

.topbar .menu-toggle {
  display: none;
}

.search {
  min-width: 0;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .04);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  color: var(--muted);
}

.search input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
}

.search svg,
.icon-button svg,
.button svg,
.link-arrow svg {
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.time-card {
  height: 48px;
  min-width: 132px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .035);
}

.time-card span,
.time-card strong {
  display: block;
}

.time-card span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.time-card strong {
  margin-top: 3px;
  font-size: 15px;
}

.button,
.icon-button {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, .06);
  cursor: pointer;
}

:root[data-theme="light"] .button,
:root[data-theme="light"] .icon-button,
:root[data-theme="light"] .search,
:root[data-theme="light"] .time-card,
:root[data-theme="light"] .sidebar-footer a,
:root[data-theme="light"] .export-strip a,
:root[data-theme="light"] .drawer-exports a {
  background: rgba(255, 255, 255, .52);
}

.button {
  height: 48px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-size: 13px;
  font-weight: 800;
}

.button.primary {
  border-color: rgba(198, 163, 91, .5);
  background: linear-gradient(135deg, #d1ae67, #9b7837);
  color: #16120a;
}

.theme-toggle .sun {
  display: none;
}

:root[data-theme="light"] .theme-toggle .sun {
  display: block;
}

:root[data-theme="light"] .theme-toggle .moon {
  display: none;
}

.button.full {
  width: 100%;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: inline-grid;
  place-items: center;
}

.overview {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  padding: 58px 0 34px;
}

.section-label {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .16em;
}

.overview h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(44px, 7vw, 86px);
  line-height: .9;
}

.overview p:not(.section-label) {
  width: min(100%, 580px);
  max-width: 100%;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.export-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.export-strip a {
  padding: 11px 13px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 22px;
  align-items: start;
}

.bookmark-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.link-group,
.side-panel,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.link-group {
  overflow: hidden;
}

.link-group.drag-over,
.link-row.drag-over,
.page-nav a.drag-over {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

.link-group.dragging,
.link-row.dragging,
.page-nav a.dragging {
  opacity: .45;
}

.link-group header {
  display: grid;
  grid-template-columns: 5px 1fr auto;
  gap: 16px;
  align-items: start;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.link-group header > span {
  border-radius: 99px;
  background: var(--group-color);
}

.link-group h2,
.panel-block h2,
.admin-drawer h2 {
  margin: 0;
  font-size: 17px;
}

.link-group p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.link-list {
  display: grid;
}

.link-row {
  display: grid;
  grid-template-columns: 42px 1fr 24px;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-top: 1px solid rgba(235, 220, 183, .08);
  transition: background .18s ease, transform .18s ease;
}

.link-row:first-child {
  border-top: 0;
}

.link-row:hover {
  background: rgba(255, 255, 255, .045);
  transform: translateX(2px);
}

.link-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--group-color);
  background: rgba(255, 255, 255, .035);
  overflow: hidden;
  position: relative;
}

.link-icon img {
  width: 22px;
  height: 22px;
  border-radius: 5px;
}

.link-icon img:not([hidden]) + .link-icon-fallback {
  display: none;
}

.link-icon-fallback {
  display: grid;
  place-items: center;
}

.link-copy {
  min-width: 0;
}

.link-copy strong,
.link-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-copy strong {
  font-size: 14px;
}

.link-copy small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.tag-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 7px;
}

.tag-row em {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--soft);
  background: rgba(255, 255, 255, .035);
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
}

.link-arrow {
  color: var(--muted);
}

.drag-handle {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, .035);
  cursor: grab;
}

.drag-handle svg {
  stroke: currentColor;
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
}

.side-panel {
  display: grid;
  gap: 20px;
  padding: 18px;
}

.panel-block {
  display: grid;
  gap: 12px;
}

.note {
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  border-radius: 8px;
  background: rgba(255, 255, 255, .035);
}

.note.green {
  border-left-color: var(--green);
}

.note strong {
  display: block;
  font-size: 13px;
}

.note p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.page-counts {
  display: grid;
  gap: 8px;
}

.page-counts a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .03);
  font-size: 13px;
}

.page-counts strong {
  color: var(--gold);
}

.empty-state {
  grid-column: 1 / -1;
  padding: 34px;
}

.empty-state h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 34px;
}

.empty-state p {
  max-width: 520px;
  color: var(--muted);
  line-height: 1.6;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, .48);
}

.admin-drawer {
  position: fixed;
  z-index: 40;
  top: 0;
  right: 0;
  width: min(440px, calc(100vw - 24px));
  height: 100vh;
  padding: 22px;
  border-left: 1px solid var(--line-strong);
  background: color-mix(in srgb, var(--bg) 95%, black 5%);
  box-shadow: -30px 0 80px rgba(0, 0, 0, .45);
  transform: translateX(104%);
  transition: transform .22s ease;
  overflow-y: auto;
}

.admin-drawer.open {
  transform: translateX(0);
}

.admin-drawer header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.admin-drawer form {
  display: grid;
  gap: 14px;
}

.admin-drawer label {
  display: grid;
  gap: 7px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 800;
}

.admin-drawer input,
.admin-drawer select,
.admin-drawer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .05);
  color: var(--text);
  outline: 0;
}

.admin-drawer input,
.admin-drawer select {
  height: 44px;
  padding: 0 12px;
}

.admin-drawer textarea {
  resize: vertical;
  padding: 11px 12px;
}

.admin-drawer option {
  color: #171511;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 90px;
  gap: 12px;
}

.form-status {
  min-height: 18px;
  margin: 0;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.drawer-exports {
  margin-top: 26px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.drawer-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.drawer-tabs button {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--soft);
  background: rgba(255, 255, 255, .035);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.drawer-tabs button.active {
  border-color: rgba(198, 163, 91, .52);
  color: var(--text);
  background: rgba(198, 163, 91, .14);
}

.drawer-panel {
  display: none;
}

.drawer-panel.active {
  display: block;
}

.deploy-warning {
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid rgba(198, 163, 91, .36);
  border-radius: 8px;
  background: rgba(198, 163, 91, .08);
}

.deploy-warning strong {
  display: block;
  color: var(--text);
  font-size: 13px;
}

.deploy-warning p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.deploy-warning code {
  color: var(--soft);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
}

.drawer-exports h3 {
  margin: 0 0 3px;
  font-size: 14px;
}

.drawer-exports a {
  padding: 12px;
}

.form-status.error {
  color: var(--danger);
}

.helper-copy {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 50;
    width: min(320px, calc(100vw - 24px));
    transform: translateX(-105%);
    transition: transform .22s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .topbar .menu-toggle {
    display: inline-grid;
  }

  .content-grid,
  .bookmark-stack {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .workspace {
    padding: 16px;
  }

  .topbar {
    grid-template-columns: 44px 44px minmax(0, 1fr);
  }

  .topbar .menu-toggle {
    order: 1;
  }

  .topbar .theme-toggle {
    order: 2;
  }

  .time-card {
    order: 3;
  }

  .topbar > .button {
    order: 4;
    grid-column: 1 / -1;
    width: 100%;
  }

  .search {
    order: 5;
    grid-column: 1 / -1;
  }

  .overview {
    display: block;
    padding: 34px 0 24px;
  }

  .overview h1 {
    font-size: 52px;
  }

  .overview p:not(.section-label) {
    width: min(100%, 330px);
    font-size: 16px;
  }

  .export-strip {
    display: grid;
    grid-template-columns: 1fr;
    justify-content: stretch;
    margin-top: 18px;
  }

  .export-strip a {
    text-align: center;
  }

  .link-row {
    grid-template-columns: 38px 1fr;
  }

  .link-arrow {
    display: none;
  }
}

/* ============================================================
   LINK ROW WRAP + EDIT / DELETE ACTIONS
   ============================================================ */

.link-row-wrap {
  position: relative;
}
.link-row-wrap:hover .link-actions,
.link-row-wrap:focus-within .link-actions {
  opacity: 1;
  pointer-events: all;
}
.link-actions {
  position: absolute;
  right: .5rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: .25rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s;
  z-index: 2;
}
.link-action-btn {
  width: 1.8rem;
  height: 1.8rem;
  border-radius: .4rem;
  background: var(--surface2, rgba(255,255,255,.07));
  border: 1px solid var(--border, rgba(255,255,255,.1));
  color: var(--muted, #888);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s;
}
.link-action-btn:hover { background: var(--surface, #1a1a18); color: var(--text, #e8e8e4); }
.link-action-btn.danger-icon:hover { color: #e87171; }
.link-action-btn svg { width: .85rem; height: .85rem; }

.danger-icon { color: var(--muted, #888); }
.danger-icon:hover { color: #e87171 !important; }

.danger-outline {
  background: transparent;
  border: 1px solid rgba(232,113,113,.4);
  color: #e87171;
  font-size: .78rem;
  padding: .35rem .8rem;
  border-radius: .4rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.danger-outline:hover { background: rgba(232,113,113,.1); border-color: #e87171; }

/* ============================================================
   PAGE ADD BUTTON IN SIDEBAR
   ============================================================ */

.page-add-btn {
  display: flex;
  align-items: center;
  gap: .4rem;
  width: 100%;
  padding: .45rem .75rem;
  background: none;
  border: 1px dashed var(--border, rgba(255,255,255,.12));
  border-radius: .5rem;
  color: var(--muted, #888);
  font-size: .8rem;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  margin-top: .25rem;
}
.page-add-btn:hover { color: var(--accent, #c6a35b); border-color: var(--accent, #c6a35b); }
.page-add-btn svg { width: .9rem; height: .9rem; }

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */

.toast-container {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  pointer-events: none;
}
.toast {
  background: var(--surface, #1a1a18);
  border: 1px solid var(--border, rgba(255,255,255,.12));
  color: var(--text, #e8e8e4);
  padding: .6rem 1.2rem;
  border-radius: 2rem;
  font-size: .84rem;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  white-space: nowrap;
}
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-success { border-color: rgba(100,200,130,.4); color: #7ecf9a; }
.toast-error   { border-color: rgba(232,113,113,.4); color: #e87171; }
.toast-info    { border-color: var(--border); }

/* ============================================================
   COMMAND PALETTE
   ============================================================ */

.cmd-overlay {
  position: fixed;
  inset: 0;
  z-index: 800;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
}
.cmd-box {
  width: min(620px, calc(100vw - 2rem));
  background: var(--surface, #1a1a18);
  border: 1px solid var(--border, rgba(255,255,255,.14));
  border-radius: .85rem;
  box-shadow: 0 16px 60px rgba(0,0,0,.6);
  overflow: hidden;
}
.cmd-search-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border, rgba(255,255,255,.08));
}
.cmd-search-row svg { width: 1rem; height: 1rem; color: var(--muted, #888); flex-shrink: 0; stroke: currentColor; fill: none; }
.cmd-search-row input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text, #e8e8e4);
  font-size: .95rem;
  font-family: inherit;
  outline: none;
}
.cmd-search-row input::placeholder { color: var(--muted, #888); }
.cmd-search-row kbd {
  background: var(--surface2, rgba(255,255,255,.06));
  border: 1px solid var(--border);
  border-radius: .3rem;
  padding: .1rem .4rem;
  font-size: .7rem;
  color: var(--muted, #888);
}
.cmd-results {
  max-height: 380px;
  overflow-y: auto;
  padding: .4rem;
}
.cmd-results::-webkit-scrollbar { width: 4px; }
.cmd-results::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.cmd-item {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  width: 100%;
  text-align: left;
  padding: .6rem .75rem;
  border-radius: .5rem;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text, #e8e8e4);
  font-family: inherit;
  font-size: .86rem;
  text-decoration: none;
  transition: background .1s;
}
.cmd-item:hover,
.cmd-item:focus {
  background: var(--surface2, rgba(255,255,255,.07));
  outline: none;
}
.cmd-action { color: var(--accent, #c6a35b); font-weight: 500; }
.cmd-title  { font-weight: 500; }
.cmd-url    { font-size: .75rem; color: var(--muted, #888); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmd-empty  { text-align: center; color: var(--muted, #888); padding: 1.5rem; font-size: .85rem; }

/* ============================================================
   MODALS (Edit link, Add page)
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 700;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal {
  background: var(--surface, #1a1a18);
  border: 1px solid var(--border, rgba(255,255,255,.12));
  border-radius: .85rem;
  padding: 1.5rem;
  width: min(460px, 100%);
  box-shadow: 0 12px 50px rgba(0,0,0,.5);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal header h2 { font-size: 1rem; margin: 0; }
.modal form { display: flex; flex-direction: column; gap: .75rem; }

/* ============================================================
   AI CHAT WIDGET
   ============================================================ */

.ai-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 600;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  background: var(--accent, #c6a35b);
  color: #000;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
  transition: transform .15s, box-shadow .15s;
}
.ai-fab:hover { transform: scale(1.07); box-shadow: 0 6px 28px rgba(0,0,0,.5); }
.ai-fab svg { width: 1.35rem; height: 1.35rem; }
.ai-fab-open  { display: block; }
.ai-fab-close { display: none; }
.ai-fab.open .ai-fab-open  { display: none; }
.ai-fab.open .ai-fab-close { display: block; }
.ai-fab-dot {
  position: absolute;
  top: .3rem;
  right: .3rem;
  width: .6rem;
  height: .6rem;
  border-radius: 50%;
  background: #e87171;
  border: 2px solid var(--bg, #0d0d0b);
}

.ai-panel {
  position: fixed;
  bottom: 5.5rem;
  right: 1.5rem;
  z-index: 599;
  width: min(420px, calc(100vw - 2rem));
  height: min(560px, calc(100vh - 8rem));
  background: var(--surface, #1a1a18);
  border: 1px solid var(--border, rgba(255,255,255,.1));
  border-radius: 1rem;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
  transform: translateY(10px) scale(.97);
  opacity: 0;
  pointer-events: none;
  transition: transform .18s ease, opacity .18s ease;
}
.ai-panel.open { transform: translateY(0) scale(1); opacity: 1; pointer-events: all; }

.ai-panel-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--border, rgba(255,255,255,.08));
  flex-shrink: 0;
}
.ai-panel-header strong { flex: 1; font-size: .88rem; }
.ai-provider-badge {
  font-size: .68rem;
  padding: .12rem .45rem;
  border-radius: 99px;
  background: rgba(198,163,91,.15);
  color: var(--accent, #c6a35b);
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 600;
}
.ai-context-toggle {
  font-size: .7rem;
  display: flex;
  align-items: center;
  gap: .25rem;
  color: var(--muted, #888);
  cursor: pointer;
}
.ai-context-toggle input { accent-color: var(--accent, #c6a35b); }

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: .8rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  scroll-behavior: smooth;
}
.ai-messages::-webkit-scrollbar { width: 4px; }
.ai-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.ai-msg {
  max-width: 88%;
  padding: .5rem .75rem;
  border-radius: .7rem;
  font-size: .84rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-msg.user      { align-self: flex-end; background: var(--accent, #c6a35b); color: #000; border-bottom-right-radius: .2rem; }
.ai-msg.assistant { align-self: flex-start; background: var(--surface2, rgba(255,255,255,.06)); color: var(--text, #e8e8e4); border-bottom-left-radius: .2rem; }
.ai-msg.system-note  { align-self: center; background: transparent; color: var(--muted, #888); font-size: .75rem; padding: .15rem .4rem; font-style: italic; }
.ai-msg.bookmark-added { align-self: center; background: rgba(100,200,130,.1); color: #7ecf9a; font-size: .75rem; border-radius: .45rem; padding: .3rem .65rem; }
.ai-typing { align-self: flex-start; color: var(--muted, #888); font-size: .78rem; font-style: italic; padding: .25rem 0; }

.ai-input-row {
  display: flex;
  gap: .5rem;
  padding: .7rem 1rem;
  border-top: 1px solid var(--border, rgba(255,255,255,.08));
  flex-shrink: 0;
}
.ai-input-row textarea {
  flex: 1;
  background: var(--surface2, rgba(255,255,255,.05));
  border: 1px solid var(--border, rgba(255,255,255,.1));
  border-radius: .5rem;
  color: var(--text, #e8e8e4);
  padding: .45rem .65rem;
  font-size: .84rem;
  resize: none;
  height: 2.4rem;
  max-height: 7rem;
  line-height: 1.4;
  font-family: inherit;
  transition: border-color .15s;
}
.ai-input-row textarea:focus { outline: none; border-color: var(--accent, #c6a35b); }
.ai-send-btn {
  width: 2.4rem;
  height: 2.4rem;
  flex-shrink: 0;
  border-radius: .5rem;
  background: var(--accent, #c6a35b);
  color: #000;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .15s;
}
.ai-send-btn:disabled { opacity: .4; cursor: default; }
.ai-send-btn svg { width: .95rem; height: .95rem; }

/* AI key row in settings */
.ai-key-row { position: relative; }
.ai-key-row input { padding-right: 2.5rem; }
.ai-key-toggle {
  position: absolute; right: .6rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--muted, #888); cursor: pointer; padding: .2rem; display: flex;
}
.ai-key-toggle svg { width: .95rem; height: .95rem; }
