/* ── Design tokens ────────────────────────────────── */
:root {
  --sb-w: 240px;
  --sb-bg: #0c0e15;
  --sb-border: rgba(255,255,255,0.07);
  --sb-ink: rgba(255,255,255,0.88);
  --sb-ink-2: rgba(255,255,255,0.52);
  --sb-ink-3: rgba(255,255,255,0.28);
  --sb-rule: rgba(255,255,255,0.07);
  --accent: #4f46e5;
  --accent-bg: rgba(79,70,229,0.14);
  --ok: #22c55e; --ok-bg: rgba(34,197,94,0.12);
  --warn: #f59e0b; --warn-bg: rgba(245,158,11,0.12);
  --crit: #ef4444; --crit-bg: rgba(239,68,68,0.12);
  --info: #3b82f6; --info-bg: rgba(59,130,246,0.12);
  --page-bg: #f5f6fa;
}

/* ── Base ─────────────────────────────────────────── */
html, body { margin: 0; padding: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
#app { height: 100vh; overflow: hidden; }
#blazor-error-ui { display: none; }

/* ── App shell ────────────────────────────────────── */
.app-shell { display: flex; height: 100vh; overflow: hidden; }
.app-body  { flex: 1; overflow-y: auto; background: var(--page-bg); }

/* ── Sidebar ──────────────────────────────────────── */
.sb {
  width: var(--sb-w); flex-shrink: 0;
  background: var(--sb-bg);
  border-right: 1px solid var(--sb-border);
  display: flex; flex-direction: column; overflow: hidden;
}

.sb-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--sb-rule);
}
.sb-brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; flex-shrink: 0;
}
.sb-brand-name { color: var(--sb-ink); font-size: 15px; font-weight: 600; letter-spacing: -.2px; }
.sb-brand-tag  { color: var(--sb-ink-3); font-size: 9px; letter-spacing: 1.6px; font-family: monospace; }

.sb-org {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 14px; border-bottom: 1px solid var(--sb-rule);
  cursor: pointer; transition: background .12s;
}
.sb-org:hover { background: rgba(255,255,255,0.04); }
.sb-org-icon {
  width: 28px; height: 28px; border-radius: 6px;
  background: rgba(255,255,255,0.1); color: var(--sb-ink-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.sb-org-name { font-size: 13px; font-weight: 500; color: var(--sb-ink); line-height: 1.25; }
.sb-org-meta { font-size: 10.5px; color: var(--sb-ink-3); }

.sb-nav {
  flex: 1; overflow-y: auto; padding: 10px 8px;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.08) transparent;
}
.sb-sec {
  font-size: 9.5px; font-weight: 600; letter-spacing: 1.3px;
  color: var(--sb-ink-3); padding: 6px 8px 7px;
  font-family: monospace;
}

.sb-link {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: 6px;
  color: var(--sb-ink-2); font-size: 13.5px;
  text-decoration: none; transition: background .1s, color .1s;
  position: relative; margin-bottom: 1px;
}
.sb-link:hover { background: rgba(255,255,255,0.06); color: var(--sb-ink); }
.sb-link.sb-on {
  background: var(--accent-bg);
  color: rgba(255,255,255,0.96);
}
.sb-link.sb-on::before {
  content: ''; position: absolute; left: 0; top: 5px; bottom: 5px;
  width: 2px; background: var(--accent); border-radius: 0 2px 2px 0;
}
.sb-link .anticon { font-size: 14px; flex-shrink: 0; }
.sb-num { font-size: 10px; font-family: monospace; opacity: .5; width: 16px; flex-shrink: 0; }
.sb-badge {
  margin-left: auto; background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 600; padding: 1px 5px;
  border-radius: 10px; min-width: 18px; text-align: center;
}
.sb-link--sm { font-size: 13px; }

.sb-bottom { border-top: 1px solid var(--sb-rule); padding: 8px; position: relative; }
.sb-user {
  display: flex; align-items: center; gap: 9px;
  padding: 8px; border-radius: 6px; border: none; background: none;
  width: 100%; cursor: pointer; color: var(--sb-ink-2);
  text-align: left; transition: background .1s;
}
.sb-user:hover { background: rgba(255,255,255,0.06); }
.sb-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.sb-user-body { flex: 1; min-width: 0; }
.sb-user-name { font-size: 13px; font-weight: 500; color: var(--sb-ink); line-height: 1.25; }
.sb-user-role { font-size: 11px; color: var(--sb-ink-3); }

.sb-popup {
  position: absolute; bottom: calc(100% + 4px);
  left: 8px; right: 8px;
  background: #1b1e2b; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; padding: 6px; z-index: 200;
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
}
.sb-popup-item {
  display: block; padding: 8px 10px; border-radius: 5px;
  font-size: 13px; color: var(--sb-ink-2); text-decoration: none;
  transition: background .1s, color .1s;
}
.sb-popup-item:hover { background: rgba(255,255,255,0.06); color: var(--sb-ink); }
.sb-popup-item--danger:hover { background: var(--crit-bg); color: var(--crit); }
.sb-popup-rule { border: none; border-top: 1px solid rgba(255,255,255,0.07); margin: 4px 0; }

.sb-compliance {
  text-align: center; font-size: 9px; font-family: monospace;
  letter-spacing: 1.2px; color: rgba(255,255,255,0.12);
  padding: 5px 0 7px; border-top: 1px solid var(--sb-rule);
}

/* ── Pages ────────────────────────────────────────── */
.page-wrap { max-width: 1200px; margin: 0 auto; padding: 28px 24px; box-sizing: border-box; width: 100%; }

.page-head {
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: 16px; margin-bottom: 24px;
}
.page-title { font-size: 22px; font-weight: 700; color: #111827; margin: 0 0 4px; letter-spacing: -.3px; }
.page-sub   { font-size: 14px; color: #6b7280; margin: 0; }

/* ── Breadcrumb ───────────────────────────────────── */
.bc { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #9ca3af; margin-bottom: 14px; }
.bc a { color: #6b7280; text-decoration: none; }
.bc a:hover { color: #111827; }
.bc-sep { color: #d1d5db; }

/* ── Status chips ─────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 500; padding: 2px 8px;
  border-radius: 4px; letter-spacing: .2px;
}
.chip--crit { background: var(--crit-bg); color: var(--crit); }
.chip--warn { background: var(--warn-bg); color: var(--warn); }
.chip--ok   { background: var(--ok-bg);   color: var(--ok);  }
.chip--info { background: var(--info-bg); color: var(--info);}
.chip--neu  { background: #f3f4f6; color: #6b7280; }

/* ── Activity feed ────────────────────────────────── */
.af-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid #f0f0f0; }
.af-item:last-child { border-bottom: none; }
.af-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex-shrink: 0; margin-top: 6px; }
.af-text { font-size: 13px; color: #374151; line-height: 1.5; }
.af-meta { font-size: 11.5px; color: #9ca3af; }

/* ── Issues ───────────────────────────────────────── */
.issue-card {
  display: flex; gap: 12px; padding: 14px 16px;
  border: 1px solid #f0f0f0; border-radius: 8px;
  background: #fff; margin-bottom: 10px;
}
.issue-title { font-size: 14px; font-weight: 600; color: #1f2937; margin-bottom: 3px; }
.issue-desc  { font-size: 13px; color: #6b7280; }

/* ── Org / Settings ───────────────────────────────── */
.settings-grid { display: grid; grid-template-columns: 200px 1fr; gap: 24px; }
.settings-nav  { display: flex; flex-direction: column; gap: 2px; }
.settings-nav-item {
  display: block; padding: 9px 12px; border-radius: 6px;
  font-size: 13.5px; color: #4b5563; text-decoration: none;
  transition: background .1s;
}
.settings-nav-item:hover { background: #f3f4f6; }
.settings-nav-item.sn-on { background: #eff0ff; color: var(--accent); font-weight: 500; }

.role-badge {
  display: inline-flex; align-items: center;
  font-size: 11px; font-weight: 600; padding: 2px 7px;
  border-radius: 4px; text-transform: uppercase; letter-spacing: .5px;
}
.rb-owner  { background: #fef3c7; color: #92400e; }
.rb-admin  { background: #e0f2fe; color: #0369a1; }
.rb-member { background: #f0fdf4; color: #166534; }

/* ── Case link ────────────────────────────────────── */
a.case-link { color: var(--accent); font-weight: 600; font-size: 13px; text-decoration: none; }
a.case-link:hover { text-decoration: underline; }

/* ── Seat bar ─────────────────────────────────────── */
.seat-bar { height: 6px; border-radius: 3px; background: #e5e7eb; overflow: hidden; margin-top: 6px; }
.seat-fill { height: 100%; background: var(--accent); border-radius: 3px; }

/* ── Empty state ──────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 20px;
  color: #9ca3af; text-align: center;
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }

/* ── AntDesign Layout fixes ───────────────────────── */
.ant-layout { display: flex !important; }
.ant-layout.ant-layout-has-sider { flex-direction: row !important; }
.ant-layout:not(.ant-layout-has-sider) { flex-direction: column !important; }

/* ── Login page ───────────────────────────────────── */
.login-page {
  min-height: 100vh; display: flex; align-items: center;
  justify-content: center; background: var(--sb-bg);
}
.login-card {
  background: #fff; border-radius: 12px;
  padding: 40px; width: 380px;
  box-shadow: 0 24px 64px rgba(0,0,0,.4);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-mark {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700; margin-bottom: 12px;
}
.login-title { font-size: 20px; font-weight: 700; color: #111827; margin: 0 0 4px; }
.login-sub   { font-size: 13px; color: #6b7280; margin: 0; }

/* ── Old DM classes (keep for dm-* selectors that remain in ApiService) */
.dm-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 16px 6px;
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.dm-logo-icon { font-size: 22px; }
.dm-logo-sub {
  padding: 0 16px 16px 46px;
  color: rgba(255,255,255,0.4);
  font-size: 12px;
}

/* ── Sidebar body ─────────────────────────────────── */
.dm-sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.dm-section-label {
  color: rgba(255,255,255,0.4);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}
.dm-empty-docs {
  color: rgba(255,255,255,0.3);
  font-size: 13px;
  text-align: center;
  margin-top: 24px;
  line-height: 1.7;
}

/* ── Document list ────────────────────────────────── */
.dm-doc-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
  border-radius: 6px;
  color: rgba(255,255,255,0.7);
  font-size: 13px;
  transition: background 0.15s;
}
.dm-doc-item:hover { background: rgba(255,255,255,0.07); }
.dm-doc-icon { flex-shrink: 0; font-size: 14px; }
.dm-doc-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dm-doc-size {
  color: rgba(255,255,255,0.3);
  font-size: 11px;
  flex-shrink: 0;
}

/* ── Sidebar footer ───────────────────────────────── */
.dm-sidebar-footer { padding: 12px 16px; }
.dm-api-link {
  color: rgba(255,255,255,0.4);
  font-size: 12px;
  text-decoration: none;
  transition: color 0.15s;
}
.dm-api-link:hover { color: rgba(255,255,255,0.7); }

/* ── Messages area ────────────────────────────────── */
.dm-messages-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 28px 32px;
}

/* ── Welcome screen ───────────────────────────────── */
.dm-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 55vh;
  text-align: center;
  padding: 40px 20px;
}
.dm-welcome-icon {
  font-size: 56px;
  color: #1677ff;
  margin-bottom: 20px;
  line-height: 1;
}
.dm-suggestions { margin-top: 20px; }

/* ── Chat messages ────────────────────────────────── */
.dm-msg {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 20px;
  max-width: 800px;
}
.dm-msg-user { flex-direction: row-reverse; margin-left: auto; }
.dm-msg-ai { margin-right: auto; }

.dm-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  font-weight: 600;
}
.dm-avatar-ai { background: #1677ff; color: #fff; font-size: 18px; }
.dm-avatar-u  { background: #52c41a; color: #fff; font-size: 14px; }

.dm-bubble {
  padding: 10px 15px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 680px;
}
.dm-bubble-ai {
  background: #fff;
  color: #1f1f1f;
  border: 1px solid #f0f0f0;
  border-top-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.dm-bubble-user {
  background: #1677ff;
  color: #fff;
  border-top-right-radius: 4px;
}

/* ── Input area ───────────────────────────────────── */
.dm-input-section {
  padding: 16px 32px 20px;
  background: #fff;
  border-top: 1px solid #f0f0f0;
  flex-shrink: 0;
}
.dm-input-row {
  display: flex;
  align-items: flex-end;
}
.dm-textarea {
  flex: 1 !important;
  resize: none !important;
  min-height: 42px !important;
  max-height: 140px !important;
  overflow-y: auto !important;
  border-radius: 10px !important;
  font-size: 14px !important;
  line-height: 1.65 !important;
  padding: 9px 13px !important;
  box-sizing: border-box !important;
  transition: border-color 0.2s !important;
}
.dm-input-hint {
  color: rgba(0,0,0,0.3);
  font-size: 12px;
  margin-top: 8px;
  text-align: center;
}

/* ── AntDesign Layout flex fixes ──────────────────── */
.ant-layout {
  display: flex !important;
}
.ant-layout.ant-layout-has-sider {
  flex-direction: row !important;
}
.ant-layout:not(.ant-layout-has-sider) {
  flex-direction: column !important;
}
