/* ============================================================
   base.css —— 全站设计变量与基础布局（唯一来源）
   任何积木块的颜色 / 间距 / 圆角都必须引用这里的变量，
   不要在组件 css 里写死色值，这样才能全局换肤不牵连组件。
   ============================================================ */

:root {
  /* —— 色板：深色导航 + 浅色内容区（参考图配色结构） —— */
  --c-ink: #1c1f2a;          /* 导航栏深色底 */
  --c-ink-soft: #262b39;     /* 导航栏 hover / 分割 */
  --c-ink-line: rgba(255, 255, 255, 0.08);

  --c-bg: #f3f5f9;           /* 页面底色 */
  --c-bg-dot: #e6e9f1;       /* 页面点阵纹理 */
  --c-card: #ffffff;         /* 卡片白 */
  --c-card-soft: #f8f9fc;    /* 卡片内浅底 */

  --c-text: #1f2430;         /* 主文字 */
  --c-text-2: #5b6273;       /* 次要文字 */
  --c-text-3: #8b92a4;       /* 辅助文字 / 日期 */
  --c-line: #e8ebf2;         /* 分割线 / 边框 */
  --c-line-strong: #cfd6e4;  /* hover 时的边框 */

  /* —— 各种「面」的底色：组件里不许再写死 #fff / #f8f9fc —— */
  --c-card-hover: #ffffff;   /* 列表行 hover 底 */
  --c-surface-soft: #fbfcfe; /* 输入框 / 预览区底 */
  --c-surface-focus: #ffffff;
  --c-thumb-bg: #dfe4ee;     /* 图片未加载时的占位底 */
  --c-plain-tag-bg: #f2f4f9; /* 次要标签底 */
  --c-code-bg: #eef1f7;      /* 行内代码底 */
  --c-code-block: #1e2330;   /* 代码块底（两种模式都偏深） */
  --c-code-block-text: #e6eaf3;
  --c-dot: #c7ccd8;          /* 元信息小圆点 */

  --c-danger: #c0392b;
  --c-danger-bg: #fdf3f2;
  --c-danger-line: #f0c6c0;

  /* 页面背景（由 js/theme.js 覆盖成自定义图片） */
  --page-bg-image: radial-gradient(var(--c-bg-dot) 1px, transparent 1px);
  --page-bg-size: 20px 20px;

  --c-accent: #14b1ef;       /* 主题蓝（按钮、链接、强调） */
  --c-accent-strong: #0d94cb;
  --c-accent-soft: rgba(20, 177, 239, 0.1);

  --c-warn: #f5c945;         /* 参考图侧栏黄色按钮，第二版用 */

  /* —— 课程标签配色：卡片按 data 里的 color 键取值 —— */
  --tag-blue: #1c8ef0;
  --tag-blue-bg: #e8f3fe;
  --tag-green: #17a673;
  --tag-green-bg: #e6f7f0;
  --tag-purple: #7a5af5;
  --tag-purple-bg: #f0edfe;
  --tag-orange: #e58131;
  --tag-orange-bg: #fef2e6;
  --tag-pink: #e0528c;
  --tag-pink-bg: #fdedf3;

  /* —— 尺寸 —— */
  --layout-w: 1200px;        /* 内容最大宽度 */
  --side-w: 300px;           /* 右侧栏宽度 */
  --gap: 22px;               /* 栅格间距 */
  --navbar-h: 72px;          /* 导航栏高度（按参考图比例放大） */

  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 14px;
  --radius-pill: 999px;

  --shadow-1: 0 1px 2px rgba(28, 31, 42, 0.04);
  --shadow-2: 0 10px 28px rgba(28, 31, 42, 0.09);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* ============================================================
   深色模式：只覆盖变量，组件 css 一行都不用改
   由 js/theme.js 写到 <html data-theme="dark"> 上
   ============================================================ */
html[data-theme='dark'] {
  --c-ink: #0d1118;
  --c-ink-soft: #171d27;
  --c-ink-line: rgba(255, 255, 255, 0.07);

  --c-bg: #11151d;
  --c-bg-dot: #1b2230;
  --c-card: #1a212b;
  --c-card-soft: #212a37;

  --c-text: #e9eef7;
  --c-text-2: #a9b4c7;
  --c-text-3: #78849a;
  --c-line: #2a3341;
  --c-line-strong: #3b475a;

  --c-card-hover: #232d3c;
  --c-surface-soft: #151b24;
  --c-surface-focus: #1d2531;
  --c-thumb-bg: #232c39;
  --c-plain-tag-bg: #263140;
  --c-code-bg: #263140;
  --c-dot: #4a5568;

  --c-accent: #2bb8f0;
  --c-accent-strong: #57cbf6;
  --c-accent-soft: rgba(43, 184, 240, 0.16);

  --tag-blue: #6cbcf9;
  --tag-blue-bg: rgba(28, 142, 240, 0.18);
  --tag-green: #4ecf9e;
  --tag-green-bg: rgba(23, 166, 115, 0.18);
  --tag-purple: #a58bff;
  --tag-purple-bg: rgba(122, 90, 245, 0.2);
  --tag-orange: #f0a05c;
  --tag-orange-bg: rgba(229, 129, 49, 0.18);
  --tag-pink: #f07dab;
  --tag-pink-bg: rgba(224, 82, 140, 0.2);

  --c-danger: #ef7a6a;
  --c-danger-bg: rgba(192, 57, 43, 0.16);
  --c-danger-line: rgba(240, 198, 192, 0.3);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 12px 30px rgba(0, 0, 0, 0.5);
}

/* —— reset —— */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  /* 弹性纵向布局：内容不足一屏时（如短笔记的详情页），
     main 撑开剩余高度，页脚始终压在视口底部，不会悬在页面中间 */
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--c-text);
  background-color: var(--c-bg);
  /* 默认是浅灰点阵底纹；页面设置里换成自定义背景图时，
     js/theme.js 只改 --page-bg-image / --page-bg-size 两个变量 */
  background-image: var(--page-bg-image);
  background-size: var(--page-bg-size);
  background-position: center;
  background-attachment: fixed;
  background-repeat: repeat;
  transition: background-color 0.25s var(--ease), color 0.25s var(--ease);
  -webkit-font-smoothing: antialiased;
}

body > main {
  flex: 1 0 auto;
}

h1, h2, h3, h4, p, figure {
  margin: 0;
}

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

img {
  max-width: 100%;
  display: block;
}

ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

button,
input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
}

/* ============================================================
   静态部署模式（部署到自己的服务器 / 备案域名时由 js/cloud.js 打上
   html[data-site-mode="static"]）：
     - 访客（默认）：只读展示，隐藏所有写入口，内容来自站点后端
     - 管理员（html[data-admin="1"]，登录后由 js/admin.js 打上）：
       写入口全部恢复，数据读写走 /api/*
   ============================================================ */

html[data-site-mode='static']:not([data-admin='1']) .note-card__edit,
html[data-site-mode='static']:not([data-admin='1']) .sidebar__actions,
html[data-site-mode='static']:not([data-admin='1']) .sidebar__hint,
html[data-site-mode='static']:not([data-admin='1']) .notedetail__dockbtn--edit,
html[data-site-mode='static']:not([data-admin='1']) .notedetail__dockbtn--compose,
/* 访客也收起导航栏里的「轮播图 / 全部笔记」管理菜单 */
html[data-site-mode='static']:not([data-admin='1']) [data-menu-item='slides'],
html[data-site-mode='static']:not([data-admin='1']) [data-menu-item='notes'] {
  display: none !important;
}

/* 快捷发布整块（侧栏）在没有按钮后就没意义了 */
html[data-site-mode='static']:not([data-admin='1']) .sidebar__panel:has(.sidebar__actions) {
  display: none;
}

/* —— 管理员登录弹窗 —— */
.admlogin {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.admlogin[hidden] {
  display: none;
}

.admlogin__mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.admlogin__dialog {
  position: relative;
  width: min(320px, 86vw);
  background: var(--c-card, #fff);
  border: 1px solid var(--c-line);
  border-radius: 14px;
  padding: 24px 22px 20px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.22);
}

.admlogin__title {
  margin: 0 0 14px;
  font-size: 16px;
  color: var(--c-text);
}

.admlogin__input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--c-line);
  border-radius: 8px;
  font-size: 14px;
  background: var(--c-bg, #f7f7f9);
  color: var(--c-text);
  outline: none;
}

.admlogin__input:focus {
  border-color: var(--c-accent);
}

.admlogin__err {
  margin: 8px 0 0;
  font-size: 12px;
  color: #d64545;
}

.admlogin__acts {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.admlogin__btn {
  flex: 1;
  padding: 9px 0;
  border: 0;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  background: var(--c-accent);
  color: #fff;
}

.admlogin__btn[disabled] {
  opacity: 0.6;
  cursor: default;
}

.admlogin__btn--ghost {
  background: transparent;
  border: 1px solid var(--c-line);
  color: var(--c-text);
}

/* —— 页面骨架：主内容流 + 右侧栏 —— */
.page {
  padding: 22px 0 48px;
}

.layout {
  width: 100%;
  max-width: var(--layout-w);
  margin: 0 auto;
  padding: 0 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side-w);
  gap: var(--gap);
  align-items: start;
}

.layout__main {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
}

.layout__side {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  position: sticky;
  top: calc(var(--navbar-h) + 20px);
}

/* —— 未接入积木的占位槽：让骨架一眼看清结构 —— */
.block-slot {
  position: relative;
}

.block-slot--side {
  height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #d3d9e6;
  border-radius: var(--radius-m);
  background: rgba(255, 255, 255, 0.45);
}

.block-slot__label {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--c-text-3);
  text-transform: uppercase;
}

/* ============================================================
   设计系统：按钮与轻提示
   多个积木块共用同一套按钮/提示样式，所以放在 base.css 里，
   组件 css 只做布局，不重复定义外观。
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background-color 0.18s var(--ease), border-color 0.18s var(--ease),
    transform 0.12s var(--ease), box-shadow 0.18s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
  flex: none;
}

.btn--block {
  display: flex;
  width: 100%;
}

/* 参考图侧栏那种黄色主行动按钮 */
.btn--warn {
  background: #f8d05a;
  border-color: #f2c53f;
  color: #4a3a06;
  box-shadow: 0 2px 8px rgba(240, 195, 63, 0.28);
}

.btn--warn:hover {
  background: #f6c93f;
}

.btn--primary {
  background: var(--c-accent);
  color: #fff;
  box-shadow: 0 2px 10px rgba(20, 177, 239, 0.28);
}

.btn--primary:hover {
  background: var(--c-accent-strong);
}

.btn--ghost {
  background: var(--c-card);
  border-color: var(--c-line);
  color: var(--c-text-2);
}

.btn--ghost:hover {
  border-color: var(--c-line-strong);
  color: var(--c-text);
  background: var(--c-surface-soft);
}

/* 轻提示 */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.toast {
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  background: rgba(26, 31, 42, 0.92);
  color: #fff;
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: 0 10px 28px rgba(20, 24, 34, 0.24);
  animation: toast-in 0.24s var(--ease);
}

.toast--err {
  background: rgba(180, 46, 46, 0.94);
}

.toast--ok {
  background: rgba(18, 122, 88, 0.94);
}

.toast.is-out {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* —— 响应式：窄屏折叠为单列 —— */
@media (max-width: 980px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .layout__side {
    position: static;
  }

  .block-slot--side {
    height: 180px;
  }
}

@media (max-width: 600px) {
  .page {
    padding: 14px 0 32px;
  }

  .layout {
    padding: 0 12px;
  }
}
