*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #315C52;
  --primary-dark: #1F3D36;
  --primary-light: #4A7A6E;
  --on-primary: #FFFFFF;
  --surface: #F6F8F5;
  --surface-card: #FFFFFF;
  --on-surface: #18201D;
  --on-surface-muted: #5A6B64;
  --border: #D6DDD8;
  --danger: #9B2C2C;
  --success: #2C9B5E;
  --warning: #C98A1F;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.12);
  --sidebar-width: 240px;
  --topbar-height: 56px;
}
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif; background: var(--surface); color: var(--on-surface); }
#app { display: flex; height: 100%; }

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  background: var(--primary-dark);
  color: var(--on-primary);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header { padding: 20px 24px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.sidebar-header .version { font-size: 11px; opacity: 0.6; }
#sidebar nav { flex: 1; padding: 12px 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.12); color: #fff; border-left-color: var(--on-primary); }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-status { padding: 16px 24px; border-top: 1px solid rgba(255,255,255,0.1); display: flex; align-items: center; gap: 8px; font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.connected { background: var(--success); }
.status-dot.disconnected { background: var(--danger); }
.status-dot.connecting { background: var(--warning); animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* Main area */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
#topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 24px;
  background: var(--surface-card);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-shrink: 0;
}
.menu-btn { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--on-surface); padding: 4px; }
#pageTitle { font-size: 18px; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.connection-badge { font-size: 13px; padding: 4px 12px; border-radius: 20px; background: var(--surface); color: var(--on-surface-muted); border: 1px solid var(--border); }

/* Page content */
#pageContent { flex: 1; overflow-y: auto; padding: 24px; }
.page { display: none; }
.page.active { display: block; }

/* Cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface-card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.stat-value { font-size: 32px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 14px; color: var(--on-surface-muted); margin-top: 4px; }
.card { background: var(--surface-card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 20px; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: 16px; font-weight: 600; }
.card-link { font-size: 13px; color: var(--primary); text-decoration: none; font-weight: 500; }
.card-link:hover { text-decoration: underline; }
.card-body { padding: 16px 20px; }
.placeholder { color: var(--on-surface-muted); font-size: 14px; }

/* Memory items */
.memory-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.memory-item:last-child { border-bottom: none; }
.memory-item:hover { background: var(--surface); margin: 0 -20px; padding: 12px 20px; border-radius: 4px; }
.memory-item .memory-summary { font-size: 15px; font-weight: 500; margin-bottom: 4px; }
.memory-item .memory-meta { font-size: 12px; color: var(--on-surface-muted); display: flex; gap: 12px; flex-wrap: wrap; }
.memory-item .memory-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.memory-item .memory-tag { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--surface); color: var(--on-surface-muted); border: 1px solid var(--border); }

/* Ask page */
.ask-container { max-width: 700px; }
.ask-input-row { display: flex; gap: 12px; }
.ask-input-row input { flex: 1; height: 48px; padding: 0 16px; border: 2px solid var(--border); border-radius: var(--radius-sm); font-size: 16px; outline: none; transition: border-color 0.15s; }
.ask-input-row input:focus { border-color: var(--primary); }
.btn-primary { height: 48px; padding: 0 24px; background: var(--primary); color: var(--on-primary); border: none; border-radius: var(--radius-sm); font-size: 15px; font-weight: 600; cursor: pointer; transition: background 0.15s; white-space: nowrap; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { height: 40px; padding: 0 20px; background: var(--surface); color: var(--on-surface); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; cursor: pointer; transition: background 0.15s; }
.btn-secondary:hover { background: var(--border); }
.ask-result { margin-top: 20px; }
.ask-result.hidden, .ask-loading.hidden { display: none; }
.answer-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.answer-status { font-size: 12px; font-weight: 600; text-transform: uppercase; padding: 3px 10px; border-radius: 10px; }
.answer-status.supported { background: #E3F2E8; color: var(--success); }
.answer-status.partial { background: #FFF3E0; color: var(--warning); }
.answer-status.unknown { background: #F3E5E5; color: var(--danger); }
.answer-text { font-size: 18px; line-height: 1.6; margin-bottom: 16px; }
.evidence-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.evidence-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; }
.evidence-card .evidence-time { font-size: 12px; color: var(--on-surface-muted); }
.evidence-card .evidence-type { font-size: 12px; font-weight: 600; color: var(--primary); }
.ask-loading p { color: var(--on-surface-muted); font-style: italic; }
.reel-badge { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; cursor: pointer; }
.reel-badge.hidden { display: none; }

/* Assets */
.page-toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.toggle-label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--on-surface-muted); cursor: pointer; }
.asset-list { display: grid; gap: 12px; }
.asset-card { background: var(--surface-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.asset-card.inactive { opacity: 0.6; }
.asset-info h4 { font-size: 16px; font-weight: 600; }
.asset-info p { font-size: 13px; color: var(--on-surface-muted); margin-top: 2px; }
.asset-actions { display: flex; gap: 8px; }
.asset-actions button { padding: 6px 14px; font-size: 13px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); cursor: pointer; transition: background 0.1s; }
.asset-actions button:hover { background: var(--border); }
.asset-actions .btn-danger { color: var(--danger); border-color: var(--danger); }
.asset-actions .btn-danger:hover { background: #F3E5E5; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.modal-content { position: relative; background: var(--surface-card); border-radius: var(--radius); width: 90%; max-width: 500px; max-height: 90vh; overflow-y: auto; padding: 24px; box-shadow: var(--shadow-lg); }
.modal-wide { max-width: 700px; }
.modal-close { position: absolute; top: 16px; right: 16px; background: none; border: none; font-size: 24px; cursor: pointer; color: var(--on-surface-muted); line-height: 1; }
.modal-close:hover { color: var(--on-surface); }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; color: var(--on-surface); }
.form-group input[type="text"], .form-group input[type="password"], .form-group select { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; outline: none; }
.form-group input:focus, .form-group select:focus { border-color: var(--primary); }
.form-group input[type="range"] { width: calc(100% - 50px); vertical-align: middle; }
.form-actions { display: flex; gap: 12px; margin-top: 20px; justify-content: flex-end; }

/* Timeline */
.timeline-filters { display: flex; gap: 12px; margin-bottom: 20px; align-items: center; }
.timeline-filters input[type="date"] { height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; }
.timeline-list { max-width: 700px; }
.timeline-entry { padding: 16px 0; border-left: 2px solid var(--border); padding-left: 20px; margin-left: 8px; position: relative; }
.timeline-entry::before { content: ''; position: absolute; left: -5px; top: 20px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.timeline-entry .entry-time { font-size: 12px; color: var(--on-surface-muted); font-weight: 600; }
.timeline-entry .entry-summary { font-size: 15px; margin-top: 4px; cursor: pointer; }
.timeline-entry .entry-summary:hover { color: var(--primary); }
.timeline-entry .entry-tags { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.timeline-entry .entry-tag { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--surface); color: var(--on-surface-muted); border: 1px solid var(--border); }

/* Memory Detail */
#memoryDetail h3 { font-size: 18px; margin-bottom: 8px; }
#memoryDetail .detail-section { margin-bottom: 16px; }
#memoryDetail .detail-section h4 { font-size: 14px; font-weight: 600; color: var(--on-surface-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
#memoryDetail .evidence-list { display: flex; flex-direction: column; gap: 8px; }
#memoryDetail .evidence-item { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--surface); border-radius: var(--radius-sm); }
#memoryDetail .evidence-item img { width: 60px; height: 60px; object-fit: cover; border-radius: 4px; }

/* Exports */
.export-list { max-width: 600px; }
.export-item { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--surface-card); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px; }
.export-status { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 10px; }
.export-status.completed { background: #E3F2E8; color: var(--success); }
.export-status.pending { background: #FFF3E0; color: var(--warning); }
.export-status.failed { background: #F3E5E5; color: var(--danger); }

/* Settings */
.settings-status { font-size: 14px; margin-left: 12px; }
.settings-status.ok { color: var(--success); }
.settings-status.error { color: var(--danger); }

/* Mobile */
@media (max-width: 768px) {
  #sidebar { position: fixed; left: -280px; top: 0; bottom: 0; z-index: 100; transition: left 0.25s; width: 260px; }
  #sidebar.open { left: 0; }
  .menu-btn { display: block; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  #pageContent { padding: 16px; }
}
