/* dufu.ai — Notion-like minimal UI */

/* ===== Variables ===== */
:root {
  --sidebar-w: 270px;
  --content-w: 230px;
  --content-x: calc((var(--sidebar-w) - var(--content-w)) / 2);
  --bg: #ffffff;
  --sidebar-bg: rgb(249, 248, 247);
  --hover: rgb(241, 240, 239);
  --active: rgb(235, 234, 233);
  --divider: rgb(239, 239, 237);
  --border: rgb(215, 215, 215);
  --text: #191919;
  --muted: #555555;
  --primary: #2383e2;
  --sidebar: 270px;
  --topbar: 64px;
  --font-en: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-zh: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-ja: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", "Noto Sans JP", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-ko: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

/* ===== Reset ===== */
* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body { margin: 0; font-family: var(--font-en); color: var(--text); background: var(--bg); }
a { color: inherit; }

/* Language-specific font stacks */
html[lang^="zh"] body { font-family: var(--font-zh); }
html[lang^="ja"] body { font-family: var(--font-ja); }
html[lang^="ko"] body { font-family: var(--font-ko); }

/* ===== App Shell ===== */
.app-shell { height: 100%; display: flex; }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar);
  background: #f7f7f5;
  border-right: 1px solid #e9e9e7;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  height: 100vh;
  overflow: hidden;
}

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  width: var(--content-w);
  margin: 0 auto;
  padding: 0;
}

.logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  margin-bottom: 12px;
  border: none;
  overflow: hidden;
}

.brand-icon {
  width: 48px;
  height: 48px;
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.brand-name {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: .2px;
  line-height: 1.1;
  margin: 0;
}

.brand-link {
  font-size: 18px;
  font-weight: 700;
  color: #000000;
  text-decoration: none;
}
.brand-link:hover { text-decoration: none; }

.brand-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* Sidebar Actions */
.sidebar-actions {
  display: flex;
  align-items: center;
  width: var(--content-w);
  margin: 2px auto 8px;
  padding: 0;
  gap: 10px;
  justify-content: center;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  height: 34px;
  padding: 0 8px;
  border: 1px solid #d9d9d9;
  background: #ffffff;
  box-shadow: none;
  border-radius: 8px;
  color: #222;
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.action-btn:hover { background: #f2f2f2; }
.action-btn:active { transform: none; }
.action-btn.editing-active {
  background: #2383e2;
  color: #fff;
  border-color: #2383e2;
}
.action-btn.editing-active:hover { background: #1b6ec2; }
.action-btn.editing-active .action-ico { filter: brightness(0) invert(1); }

.action-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #333;
}

.action-ico {
  width: 18px;
  height: 18px;
  display: block;
}

.lang-btn { justify-content: center; }

/* Language Menu */
.lang-wrap { position: relative; flex: 1; }
.lang-wrap .action-btn { width: 100%; }

.lang-menu {
  position: absolute;
  top: 44px;
  left: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .10);
  min-width: 220px;
  padding: 6px;
  display: none;
  z-index: 50;
}
.lang-menu.open { display: block; }

.lang-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}
.lang-item:hover { background: var(--hover); }

.flag {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f6f6f6;
  font-size: 14px;
}

/* ===== Tool List ===== */
.tool-list-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  margin-top: 0;
  padding-top: 0;
  padding-right: 0;
  padding-bottom: 10px;
}

/* Divider line (appears when tool list is scrolled) */
.tool-list-wrap::before {
  content: "";
  position: absolute;
  left: 0;
  right: auto;
  width: var(--sidebar-w);
  top: 0;
  height: 1px;
  background: #DDDDDD;
  opacity: 0;
  transition: opacity 500ms linear;
  pointer-events: none;
}
.tool-list-wrap.has-divider::before { opacity: 1; }
.sidebar.has-list-divider .tool-list-wrap::before { opacity: 1; }

.tool-list {
  height: 100%;
  overflow-y: auto;
  background: transparent;
  padding: 4px 0;
  border-radius: 0;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}
.tool-list:hover { scrollbar-color: #D7D7D7 transparent; }
.tool-list::-webkit-scrollbar { width: 6px; }
.tool-list::-webkit-scrollbar-track { background: transparent; }
.tool-list::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 999px;
  transition: background-color 300ms;
}
.tool-list:hover::-webkit-scrollbar-thumb { background: #D7D7D7; }
.tool-list::-webkit-scrollbar-thumb:hover { background: #7F7F7F; }
.tool-list::-webkit-scrollbar-thumb:active { background: #7F7F7F; }

/* Tool list styles when sidebar has divider class */
.sidebar.has-list-divider .tool-list {
  padding: 6px 0 0 0;
}

.tool-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: var(--content-w);
  margin: 0 auto 2px;
  padding: 12px 5px;
  box-sizing: border-box;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}
.tool-item:hover { background: #f1f1ef; }
.tool-item.active { background: #e8e8e6; }

.tool-leading {
  width: 24px;
  height: 24px;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #111;
  flex: 0 0 auto;
  background: transparent;
  margin-top: -1px;
}
.tool-leading img { width: 24px; height: 24px; display: block; }

.tool-ico {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: var(--muted);
}
.tool-ico svg { width: 24px; height: 24px; }
.tool-item.active .tool-ico { color: var(--text); }

.sidebar.editing .tool-leading .tool-ico { display: none; }
.sidebar.editing .tool-leading .drag-ico { display: block; }
.tool-leading .drag-ico { display: none; }

.tool-meta { min-width: 0; flex: 1; }

.tool-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
  margin: 0;
}

.tool-desc {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  font-weight: 400;
  line-height: 16px;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Drag-and-drop reorder */
.sidebar.editing .tool-item { cursor: grab; }
.sidebar.editing .tool-item:active { cursor: grabbing; }

/* Smooth transition for items shifting out of the way */
.tool-item.drag-transition {
  transition: transform .2s cubic-bezier(.2,.8,.4,1);
}

/* The placeholder gap left behind */
.tool-item.drag-source {
  opacity: 0;
  pointer-events: none;
}

/* The floating clone that follows the pointer */
.drag-ghost {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  opacity: .92;
  box-shadow: 0 8px 24px rgba(0,0,0,.15), 0 2px 6px rgba(0,0,0,.08);
  border-radius: 8px;
  background: #fff;
  transition: box-shadow .15s ease;
  will-change: transform;
}

/* Sidebar Footer */
.sidebar-footer {
  flex: 0 0 auto;
  width: var(--content-w);
  margin: 0 auto;
  padding: 0;
  font-size: 9px;
  color: rgba(0, 0, 0, 0.25);
  text-align: center;
  letter-spacing: .2px;
  line-height: 1;
}

/* ===== Main Content ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #fff; }

.topbar {
  height: var(--topbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px 14px;
  background: #fff;
  border-bottom: 1px solid var(--divider);
}

.topbar-left { display: flex; align-items: center; gap: 10px; }
.page-title { font-weight: 600; font-size: 18px; white-space: nowrap; }
.page-desc { font-size: 12px; color: var(--muted); font-weight: 400; white-space: nowrap; }
/* User area (Google login) */
.user-area {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.user-profile {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: default;
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}
.user-name {
  font-size: 13px;
  color: var(--muted);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-signout {
  background: none;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font-en);
}
.user-signout:hover { background: #f2f2f2; color: var(--text); }

.content { flex: 1; min-height: 0; padding: 0; background: #fff; }
.tool-frame { width: 100%; height: 100%; border: 0; background: #fff; }

/* ===== Sidebar Collapse / Expand ===== */
.sidebar {
  transition: width .25s ease;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}

/* Inner wrapper keeps layout at sidebar width regardless of outer width */
.sidebar-inner {
  width: var(--sidebar);
  min-width: var(--sidebar);
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 0 12px;
  transition: opacity .2s ease;
}

/* Fade out expanded content when collapsed */
.app-shell.sidebar-collapsed .sidebar-inner {
  opacity: 0;
  pointer-events: none;
}

.sidebar-toggle {
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  margin-left: auto;
  margin-right: -6px;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--hover); color: var(--text); }

/* Collapsed narrow rail (56px) */
.app-shell.sidebar-collapsed .sidebar { width: 56px; }

/* Rail overlay — always in DOM, visible only when collapsed */
.sidebar-rail {
  position: absolute;
  inset: 0;
  width: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.app-shell.sidebar-collapsed .sidebar-rail {
  opacity: 1;
  pointer-events: auto;
}

/* Rail expand button — same size as sidebar-toggle (28px) */
.rail-expand {
  width: 28px;
  height: 28px;
  display: flex;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}
.rail-expand:hover { background: var(--hover); color: var(--text); }

/* Rail icon list */
.rail-icons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0;
  width: 100%;
  scrollbar-width: none;
}
.rail-icons::-webkit-scrollbar { display: none; }

.rail-icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  flex-shrink: 0;
}
.rail-icon-btn:hover { background: var(--hover); color: var(--text); }
.rail-icon-btn.active { background: var(--active); color: var(--text); }
.rail-icon-btn svg { width: 20px; height: 20px; }

/* ===== Mobile ===== */
@media (max-width: 860px) {
  /* Default to collapsed sidebar on narrow screens */
  .app-shell .sidebar { width: 56px; }
  .app-shell .sidebar .sidebar-inner { opacity: 0; pointer-events: none; }
  .app-shell .sidebar .sidebar-rail { opacity: 1; pointer-events: auto; }

  /* When expanded on mobile, overlay the sidebar */
  .app-shell.sidebar-expanded-mobile .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: var(--sidebar);
    z-index: 100;
    box-shadow: 4px 0 24px rgba(0, 0, 0, .08);
  }
  .app-shell.sidebar-expanded-mobile .sidebar .sidebar-inner { opacity: 1; pointer-events: auto; }
  .app-shell.sidebar-expanded-mobile .sidebar .sidebar-rail { opacity: 0; pointer-events: none; }

  /* Backdrop overlay when sidebar is open */
  .app-shell.sidebar-expanded-mobile::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .15);
    z-index: 99;
  }

  .topbar { position: sticky; top: 0; z-index: 10; }

  /* iframe fills available width */
  .main { min-width: 0; flex: 1; }
  .tool-frame { width: 100%; height: 100%; }
}
