*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #232738;
  --border: #2a2e3f;
  --text: #e4e6f0;
  --muted: #7a7f94;
  --primary: #6c5ce7;
  --primary-hover: #7f71e8;
  --green: #00d68f;
  --red: #ff6b6b;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,.3);
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 240px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 24px 16px;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 10;
}
.sidebar-header { margin-bottom: 32px; }
.sidebar-header h1 { font-size: 32px; }
.sidebar-header h2 { font-size: 18px; font-weight: 600; margin-top: 4px; }
.nav-items { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-size: 14px;
  transition: all .2s;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--primary); color: white; }
.nav-icon { font-size: 18px; }
.sidebar-footer { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); padding-top: 16px; border-top: 1px solid var(--border); }
.sidebar-search { padding: 8px 0; }
.sidebar-search .input { margin: 0; font-size: 12px; padding: 8px 10px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; }
.status-dot.ok { background: var(--green); }
.status-dot.error { background: var(--red); }
.status-dot.loading { background: #f0ad4e; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* Content */
.content { margin-left: 240px; flex: 1; padding: 32px; max-width: 1200px; }
.page { display: none; }
.page.active { display: block; }
header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
header h2 { font-size: 24px; font-weight: 600; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 16px; }
.card h3 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.muted { color: var(--muted); font-size: 14px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px,1fr)); gap: 16px; }

/* Buttons */
.btn {
  padding: 8px 20px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface2); color: var(--text); cursor: pointer;
  font-size: 14px; transition: all .2s; white-space: nowrap;
}
.btn:hover { background: var(--border); }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }

/* Inputs */
.input, textarea, select, input[type="file"] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); border-radius: 8px;
  font-size: 14px; margin-bottom: 12px; font-family: inherit;
}
textarea { resize: vertical; }
input[type="file"] { cursor: pointer; }

/* Table */
.file-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.file-table th { text-align: left; padding: 10px 12px; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); }
.file-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.file-table tr:hover td { background: var(--surface2); }
.file-table .file-name { color: var(--primary); cursor: pointer; text-decoration: none; }
.file-table .file-name:hover { text-decoration: underline; }
.file-delete { color: var(--red); cursor: pointer; opacity: .6; font-size: 13px; }
.file-delete:hover { opacity: 1; }
.toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .input { margin-bottom: 0; }
.pagination { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }

/* Upload */
.upload-area {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 32px; text-align: center; margin-bottom: 16px;
  background: var(--surface); transition: all .2s;
}
.upload-area.dragover { border-color: var(--primary); background: rgba(108,92,231,.1); }
.upload-area p { color: var(--muted); margin-top: 8px; }

/* Notes Grid */
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px,1fr)); gap: 12px; }
.note-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; cursor: pointer; transition: all .2s;
}
.note-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.note-card h4 { font-size: 15px; margin-bottom: 8px; color: var(--text); }
.note-card p { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.note-card .note-date { font-size: 11px; color: var(--muted); margin-top: 8px; }
.note-card .note-score { font-size: 11px; color: var(--green); margin-top: 4px; }

/* Modal */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 100;
  justify-content: center; align-items: center; padding: 24px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 700px; max-height: 90vh; display: flex; flex-direction: column;
}
.modal-header { display: flex; align-items: center; gap: 12px; padding: 20px 20px 0; }
.modal-title { margin-bottom: 0; font-size: 18px; font-weight: 600; border: none; background: transparent; }
.modal-title:focus { outline: none; border-bottom: 2px solid var(--primary); border-radius: 0; }
.modal textarea {
  flex: 1; min-height: 300px; border: none; border-radius: 0;
  padding: 20px; margin: 0; background: transparent; font-size: 14px; line-height: 1.6;
}
.modal textarea:focus { outline: none; }
.modal-footer { display: flex; justify-content: space-between; padding: 16px 20px; border-top: 1px solid var(--border); }

/* Gallery */
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 12px; }
.gallery-item {
  position: relative; aspect-ratio: 1; border-radius: var(--radius);
  overflow: hidden; cursor: pointer; border: 1px solid var(--border);
}
.gallery-item img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s; }
.gallery-item:hover img { transform: scale(1.05); }
.gallery-item .gallery-name {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 8px 12px; background: linear-gradient(transparent, rgba(0,0,0,.8));
  font-size: 12px; color: white;
}

/* Lightbox */
.lightbox {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.95); z-index: 200;
  justify-content: center; align-items: center;
}
.lightbox.show { display: flex; }
.lightbox img { max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: 8px; }
.lightbox-close {
  position: absolute; top: 24px; right: 24px;
  background: none; border: none; color: white; font-size: 28px; cursor: pointer;
}

/* Results */
.result-box { margin-top: 12px; padding: 12px; border-radius: 8px; background: var(--surface2); font-size: 13px; white-space: pre-wrap; word-break: break-word; display: none; max-height: 300px; overflow: auto; }
.result-box.show { display: block; }

/* Toast */
.toast { position: fixed; bottom: 24px; right: 24px; padding: 12px 24px; border-radius: 8px; font-size: 14px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); transform: translateY(100px); opacity: 0; transition: all .3s; z-index: 300; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { border-color: var(--red); }
.toast.success { border-color: var(--green); }

/* Chat */
.chat-container { display: flex; flex-direction: column; height: 500px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 8px 0; }
.chat-msg { margin-bottom: 16px; max-width: 80%; }
.chat-msg.bot { align-self: flex-start; }
.chat-msg.user { align-self: flex-end; text-align: right; margin-left: auto; }
.chat-msg strong { font-size: 12px; color: var(--muted); }
.chat-msg p { margin-top: 4px; padding: 12px 16px; border-radius: 12px; background: var(--surface2); font-size: 14px; line-height: 1.5; }
.chat-msg.user p { background: var(--primary); color: white; }
.chat-input { display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }

/* Tags */
.tag-filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 12px; font-size: 11px; cursor: pointer;
  border: 1px solid transparent; transition: all .2s;
}
.tag.active { border-color: var(--text); }
.tag-editor { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 20px 0; }
.tag-editor .tag-add { cursor: pointer; color: var(--primary); font-size: 12px; padding: 4px 8px; }

/* Analytics */
.breakdown-bar { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.breakdown-bar .bar { flex: 1; height: 24px; background: var(--surface2); border-radius: 6px; overflow: hidden; }
.breakdown-bar .bar-fill { height: 100%; border-radius: 6px; transition: width .5s; }
.breakdown-bar .label { min-width: 80px; font-size: 13px; }
.breakdown-bar .value { min-width: 60px; text-align: right; font-size: 13px; color: var(--muted); }

/* Shortcuts */
.shortcut-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.shortcut-row:last-child { border: none; }
kbd { padding: 2px 8px; border-radius: 4px; background: var(--surface2); border: 1px solid var(--border); font-size: 12px; font-family: inherit; }

/* Checkbox */
input[type="checkbox"] { accent-color: var(--primary); width: 16px; height: 16px; cursor: pointer; }

/* Loading skeleton */
.skeleton { background: linear-gradient(90deg, var(--surface2) 25%, var(--surface) 50%, var(--surface2) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 4px; }
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

@media (max-width: 768px) {
  .sidebar { width: 60px; padding: 16px 8px; }
  .sidebar h2, .sidebar-footer span, .nav-item span:last-child, .sidebar-search, #shortcutHint { display: none; }
  .content { margin-left: 60px; padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .card-grid { grid-template-columns: 1fr; }
  .notes-grid { grid-template-columns: 1fr; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); }
  .chat-container { height: 400px; }
}
