/* 115 AI Assistant — ChatGPT-style UI. CSS variables, light/dark, no gradients. */
:root {
  --background: #f6f6f6;
  --surface: #ffffff;
  --surface-secondary: #f0f0f0;
  --text-primary: #0d0d0d;
  --text-secondary: #6b6b6b;
  --border: #e3e3e3;
  --accent: #0d7a5f;
  --accent-soft: rgba(13, 122, 95, 0.12);
  --danger: #b3261e;
  --danger-soft: rgba(179, 38, 30, 0.10);
  --success: #0d7a5f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --sidebar-w: 232px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --background: #212121;
    --surface: #2f2f2f;
    --surface-secondary: #3a3a3a;
    --text-primary: #ececec;
    --text-secondary: #a3a3a3;
    --border: #444444;
    --accent: #5fbf9f;
    --accent-soft: rgba(95, 191, 159, 0.16);
    --danger: #f2b8b5;
    --danger-soft: rgba(242, 184, 181, 0.12);
    --success: #5fbf9f;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--background);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; }

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

/* ---------- sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  gap: 14px;
}
.brand { display: flex; align-items: center; gap: 8px; padding: 4px 8px; font-weight: 600; }
.brand-mark svg { width: 20px; height: 20px; color: var(--accent); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; color: var(--text-primary);
}
.nav-item:hover { background: var(--surface-secondary); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 4px; }
.storage-mini { font-size: 12px; color: var(--text-secondary); padding: 0 6px; }

/* ---------- main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; background: var(--surface);
  border-bottom: 1px solid var(--border); min-height: 52px;
}
.crumbs { flex: 1; display: flex; align-items: center; gap: 2px; flex-wrap: wrap; min-width: 0; }
.crumb {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px 6px; border-radius: 6px; color: var(--text-secondary);
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.crumb.link { cursor: pointer; color: var(--text-primary); }
.crumb.link:hover { background: var(--surface-secondary); }
.crumb-sep { color: var(--text-secondary); display: inline-flex; }
.topbar-actions { display: flex; gap: 8px; }

.content { flex: 1; overflow-y: auto; padding: 20px 22px 60px; focus: outline none; }
.content:focus { outline: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; color: var(--text-primary);
}
.btn:hover { background: var(--surface-secondary); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-secondary); }
.btn.ghost:hover { background: var(--surface-secondary); color: var(--text-primary); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.icon-only { padding: 6px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------- cards ---------- */
.card-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.file-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px; position: relative;
}
.file-card:hover { border-color: var(--accent); }
.file-card .fc-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.file-card .fc-icon { color: var(--accent); display: inline-flex; flex: 0 0 auto; }
.file-card .fc-name {
  font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer;
}
.file-card .fc-sub { color: var(--text-secondary); font-size: 12.5px; }
.file-card .fc-path {
  color: var(--text-secondary); font-size: 12px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.file-card .fc-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.panel h2 { margin: 0 0 12px; font-size: 16px; }
.panel h3 { margin: 0 0 8px; font-size: 14px; color: var(--text-secondary); }

/* ---------- dashboard ---------- */
.storage-bar-wrap { margin: 8px 0 4px; }
.storage-bar { height: 8px; border-radius: 4px; background: var(--surface-secondary); overflow: hidden; }
.storage-bar > div { height: 100%; background: var(--accent); }
.stat-row { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 14px; }
.stat {
  background: var(--surface-secondary); border-radius: 8px; padding: 10px 14px; min-width: 120px;
}
.stat .num { font-size: 20px; font-weight: 700; }
.stat .lbl { font-size: 12px; color: var(--text-secondary); }
.quick-actions { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.quick-action {
  display: flex; align-items: center; gap: 10px; padding: 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; font-weight: 600;
}
.quick-action:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- search ---------- */
.search-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.search-input-wrap {
  flex: 1; min-width: 240px; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0 12px;
}
.search-input-wrap svg { color: var(--text-secondary); flex: 0 0 auto; }
.search-input-wrap input { flex: 1; border: none; background: transparent; padding: 10px 0; color: var(--text-primary); outline: none; font: inherit; }
select, input[type="text"], input[type="number"], textarea {
  background: var(--surface); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font: inherit;
}
select:focus, input:focus, textarea:focus, .btn:focus, a:focus, [tabindex]:focus {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.search-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-label { color: var(--text-secondary); font-size: 12.5px; }

/* ---------- drawer ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.32); z-index: 40;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 92vw);
  background: var(--surface); border-left: 1px solid var(--border);
  z-index: 41; overflow-y: auto; padding: 18px 20px 40px; box-shadow: var(--shadow);
}
.drawer h2 { margin: 0 0 4px; font-size: 17px; word-break: break-all; }
.drawer .meta-row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.drawer .meta-row .k { color: var(--text-secondary); flex: 0 0 auto; }
.drawer .meta-row .v { text-align: right; word-break: break-all; }
.drawer section { margin-top: 18px; }
.drawer section h3 { margin: 0 0 8px; font-size: 13px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.drawer .btn-col { display: flex; flex-direction: column; gap: 8px; }
.ask-box textarea { width: 100%; min-height: 84px; resize: vertical; }
.text-preview {
  background: var(--surface-secondary); border-radius: 8px; padding: 12px;
  font-family: ui-monospace, Consolas, monospace; font-size: 12.5px;
  white-space: pre-wrap; word-break: break-word; max-height: 340px; overflow-y: auto;
}
.drawer-close { position: absolute; top: 12px; right: 12px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
table.data th { color: var(--text-secondary); font-weight: 600; }
table.data tr:hover td { background: var(--surface-secondary); }
.progress { height: 6px; border-radius: 3px; background: var(--surface-secondary); overflow: hidden; min-width: 80px; }
.progress > div { height: 100%; background: var(--accent); }

/* ---------- misc ---------- */
.empty { color: var(--text-secondary); padding: 30px 10px; text-align: center; }
.skeleton { height: 74px; border-radius: var(--radius); background: var(--surface-secondary); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
.toast-wrap { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 10px 14px; box-shadow: var(--shadow); max-width: 380px;
}
.toast.error { border-left-color: var(--danger); }
.toast .t-title { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.toast .t-msg { color: var(--text-secondary); font-size: 12.5px; word-break: break-all; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal-card { background: var(--surface); border-radius: var(--radius); padding: 20px 22px; width: min(420px, 92vw); box-shadow: var(--shadow); }
.modal-card h3 { margin: 0 0 8px; }
.modal-card p { color: var(--text-secondary); margin: 0 0 14px; }
.modal-card input { width: 100%; margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.kb-ask { display: flex; gap: 8px; margin-top: 10px; }
.kb-ask input { flex: 1; }
.snippet-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.snippet { background: var(--surface-secondary); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.snippet .s-path { font-weight: 600; margin-bottom: 3px; word-break: break-all; }
.snippet .s-text { color: var(--text-secondary); }
.hidden { display: none !important; }

@media (max-width: 768px) {
  .sidebar { position: fixed; z-index: 45; left: calc(-1 * var(--sidebar-w)); transition: left 0.2s ease; height: 100vh; }
  .sidebar.open { left: 0; box-shadow: var(--shadow); }
  .content { padding: 14px 12px 60px; }
  .card-grid { grid-template-columns: 1fr; }
  .sidebar-toggle { display: inline-flex !important; }
}
.sidebar-toggle { display: none; }
