:root {
  --red: #DA3742;
  --red-dark: #B72C36;
  --blue: #284294;
  --blue-dark: #203579;
  --ink: #333;
  --muted: #6d7379;
  --gray: #808285;
  --line: #e5e7ea;
  --surface: #fff;
  --canvas: #f4f6f8;
  --success: #198754;
  --warning: #d88400;
  --shadow: 0 10px 30px rgba(35, 40, 45, .08);
  --focus-ring: 0 0 0 3px var(--blue);
  color: var(--ink);
  background: var(--canvas);
  font-family: "Albert Sans", "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
:where(button, input, textarea, select, a):focus-visible { outline: 0; box-shadow: var(--focus-ring); }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 255px minmax(0, 1fr);
  grid-template-rows: 76px minmax(0, 1fr);
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 18px; }
.brand img { object-fit: contain; }
.brand-divider { width: 1px; height: 38px; background: var(--line); }
.brand strong { display: block; font-size: 17px; }
.brand small { display: block; color: var(--muted); margin-top: 3px; }
.topbar-status { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.status-dot { width: 9px; height: 9px; background: var(--success); border-radius: 50%; box-shadow: 0 0 0 4px rgba(25, 135, 84, .12); }
.menu-button { display: none; border: 0; background: transparent; font-size: 24px; }

.sidebar {
  height: calc(100vh - 76px);
  position: sticky;
  top: 76px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 24px 14px;
  overflow: auto;
  color: #fff;
  background: var(--blue);
}

.sidebar nav { display: flex; flex-direction: column; gap: 7px; }
.nav-item {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 13px;
  border: 0;
  border-radius: 7px;
  color: #fff;
  background: transparent;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
}
.nav-item[hidden] { display: none; }

.nav-item span { width: 22px; color: rgba(255, 255, 255, .8); text-align: center; }
.nav-item:hover { background: rgba(255, 255, 255, .12); }
.nav-item.active { color: #fff; background: var(--red); }
.nav-item.active span { color: #fff; }
.nav-item:focus-visible { outline: 2px solid #fff; outline-offset: 2px; box-shadow: none; }
.brain-link { margin-top: 7px; border: 1px solid rgba(255, 255, 255, .12); }
.nav-label { margin: 22px 13px 8px; color: rgba(255, 255, 255, .8); font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }

.privacy-card { padding: 14px; border: 1px solid rgba(255, 255, 255, .3); border-radius: 8px; background: rgba(255, 255, 255, .08); }
.privacy-card strong { display: block; margin-bottom: 7px; color: #fff; font-size: 12px; }
.privacy-card span { display: block; color: rgba(255, 255, 255, .88); font-size: 11px; line-height: 1.45; }
.sidebar-foot { display: grid; gap: 10px; }
.demo-identity { padding: 12px; border: 1px solid rgba(255, 255, 255, .3); border-radius: 8px; color: #fff; font-size: 12px; }
.demo-identity[hidden] { display: none; }
.demo-identity label { display: block; margin-bottom: 7px; font-weight: 700; }
.demo-identity select { width: 100%; padding: 8px; border: 1px solid #737b82; border-radius: 6px; background: #fff; color: #222; }
.demo-identity small { display: block; margin-top: 7px; color: rgba(255, 255, 255, .88); }

.workspace { min-width: 0; padding: 36px 42px 70px; }
.view { display: none; max-width: 1450px; margin: auto; }
.view.active { display: block; }
.access-screen { display: none; min-height: 62vh; align-items: center; justify-content: center; }
.access-card { width: min(100%, 560px); padding: clamp(28px, 5vw, 48px); border: 1px solid var(--line); border-radius: 7px; background: var(--surface); box-shadow: var(--shadow); }
.access-card h1 { margin: 12px 0; font-size: clamp(26px, 4vw, 34px); line-height: 1.2; }
.access-card p { margin: 0; color: var(--muted); line-height: 1.6; }
.app-shell.access-denied { grid-template-columns: minmax(0, 1fr); }
.app-shell.access-denied .sidebar, .app-shell.access-denied .view, .app-shell.access-denied .menu-button { display: none; }
.app-shell.access-denied .access-screen { display: flex; }
.app-shell.access-denied .status-dot { background: var(--red); box-shadow: 0 0 0 4px rgba(218, 55, 66, .12); }

.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.eyebrow { color: var(--red); font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.page-heading h1 { margin: 6px 0 7px; font-size: 34px; line-height: 1.1; }
.page-heading p { max-width: 720px; margin: 0; color: var(--muted); }

.primary, .secondary { padding: 11px 17px; border: 0; border-radius: 5px; font-weight: 700; transition: .15s; }
.primary { color: #fff; background: var(--red); }
.primary:hover { background: var(--red-dark); }
.secondary { color: #fff; background: var(--blue); }
.secondary:hover { background: var(--blue-dark); }
.text-button { border: 0; color: var(--blue); background: transparent; font-weight: 700; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.metric-card { padding: 19px; border: 1px solid var(--line); border-top: 3px solid var(--red); border-radius: 7px; background: #fff; box-shadow: var(--shadow); }
.metric-card.blue { border-top-color: var(--blue); }
.metric-card.gray { border-top-color: var(--gray); }
.metric-card.warning { border-top-color: var(--warning); }
.metric-card strong { display: block; margin: 8px 0 3px; font-size: 30px; }
.metric-card span { color: var(--muted); font-size: 12px; font-weight: 600; }

.panel { min-width: 0; padding: 22px; border: 1px solid var(--line); border-radius: 7px; background: #fff; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 18px; font-size: 18px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.panel-heading h2 { margin: 3px 0 0; }
.dashboard-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.wide { grid-column: span 2; }

.list { display: flex; flex-direction: column; }
.list-empty { padding: 28px; border: 1px dashed var(--line); border-radius: 6px; color: var(--muted); background: #fafbfc; text-align: center; }
.task-row, .idea-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 18px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.task-row:last-child, .idea-row:last-child { border-bottom: 0; }
.task-row strong, .idea-row strong { display: block; }
.task-row small, .idea-row small { display: block; margin-top: 5px; color: var(--muted); }

.badge { display: inline-flex; padding: 5px 8px; border-radius: 999px; color: #596069; background: #f0f2f4; font-size: 11px; font-weight: 700; }
.badge.critical { color: var(--red-dark); background: #fde8ec; }
.signal-list { display: grid; gap: 10px; }
.signal { display: flex; justify-content: space-between; padding: 13px; border-left: 3px solid var(--blue); border-radius: 3px; background: #f8f9fa; }
.signal strong { font-size: 20px; }
.signal span { font-size: 13px; }

.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.form-card { display: flex; flex-direction: column; gap: 14px; }
.form-card h2 { margin-bottom: 4px; }
.form-card label { display: flex; flex-direction: column; gap: 7px; color: #555b60; font-size: 12px; font-weight: 700; }
.form-card input, .form-card textarea, .form-card select, .chat-composer textarea {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid #ccd1d6;
  border-radius: 5px;
  color: var(--ink);
  background: #fff;
}

.form-card textarea { min-height: 90px; resize: vertical; }
.form-card input:focus, .form-card textarea:focus, .form-card select:focus, .chat-composer textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.file-field { cursor: pointer; }
.file-field input { position: absolute; opacity: 0; pointer-events: none; }
.file-field span { display: block; padding: 13px; border: 1px dashed #b9bec4; border-radius: 5px; color: var(--blue); background: #f8fbfe; text-align: center; }


.table-panel { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { padding: 11px; border-bottom: 2px solid var(--line); color: var(--muted); text-align: left; font-size: 10px; letter-spacing: .07em; text-transform: uppercase; }
.data-table td { padding: 13px 11px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table select { padding: 6px; border: 1px solid var(--line); border-radius: 4px; }
#usersTable { overflow-x: auto; }
#usersTable input[type="email"] { width: min(220px, 100%); min-width: 170px; padding: 6px; border: 1px solid var(--line); border-radius: 4px; }

.asset-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.asset-card { padding: 15px; border: 1px solid var(--line); border-left: 4px solid var(--blue); border-radius: 5px; }
.asset-card strong { display: block; }
.asset-card small { display: block; margin-top: 7px; color: var(--muted); }

.brain-view { max-width: 1550px; }
.local-badge { padding: 8px 12px; border: 1px solid #b9ddef; border-radius: 999px; color: var(--blue); background: #e7f4fb; font-size: 12px; font-weight: 700; }
.brain-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; }
.chat-panel { min-height: 650px; display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.chat-messages { max-height: 600px; flex: 1; display: flex; flex-direction: column; gap: 18px; padding: 26px; overflow: auto; }
.message { max-width: 85%; display: flex; gap: 12px; line-height: 1.55; }
.message.user { align-self: flex-end; padding: 12px 15px; border-radius: 12px 12px 2px 12px; background: #f1f3f5; }
.message.assistant { align-self: flex-start; }
.message p { margin: 4px 0; }
.brain-avatar { width: 34px; height: 34px; flex: 0 0 34px; display: flex; align-items: center; justify-content: center; border-radius: 4px; color: #fff; background: var(--red); font-weight: 800; }
.source-footnote { margin-top: 10px !important; padding-top: 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.chat-composer { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 16px; border-top: 1px solid var(--line); background: #fafbfc; }
.chat-composer textarea { min-height: 50px; max-height: 130px; resize: vertical; }
.source-list { display: grid; gap: 10px; }
.source-item { padding: 12px; border: 1px solid var(--line); border-radius: 5px; }
.source-item strong { display: block; }
.source-item span { color: var(--muted); font-size: 11px; }

.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.security-status { display: grid; gap: 8px; margin-bottom: 24px; }
.security-line { display: flex; justify-content: space-between; padding: 10px; border-radius: 4px; background: #f8f9fa; }
.security-line strong.good { color: var(--success); }
.security-line strong.warn { color: var(--warning); }
code { padding: 2px 5px; border-radius: 3px; background: #f0f2f4; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: 420px; padding: 14px 18px; border-radius: 6px; color: #fff; background: #26292c; box-shadow: 0 15px 40px rgba(0, 0, 0, .25); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--red-dark); }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid, .two-columns, .brain-layout, .admin-grid { grid-template-columns: 1fr; }
  .wide { grid-column: span 1; }
  .sources-panel { order: -1; }
  .asset-grid { grid-template-columns: repeat(2, 1fr); }


}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .topbar { height: 68px; padding: 0 14px; }
  .menu-button { display: block; }
  .brand { gap: 10px; }
  .brand img { width: 84px; height: auto; }
  .brand-divider, .brand small, .topbar-status { display: none; }
  .app-shell.access-denied .topbar-status { display: flex; font-size: 0; }
  .app-shell.access-denied .status-dot { width: 10px; height: 10px; }
  .sidebar { position: fixed; z-index: 30; top: 68px; left: 0; width: 270px; height: calc(100vh - 68px); transform: translateX(-100%); transition: .2s; }
  .sidebar.open { transform: none; }
  .workspace { padding: 25px 16px 60px; }
  .page-heading { display: block; }
  .page-heading .primary { margin-top: 16px; }
  .page-heading h1 { font-size: 29px; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { padding: 15px; }
  .metric-card strong { font-size: 25px; }
  .form-row, .asset-grid{ grid-template-columns: 1fr; }

  .task-row, .idea-row { grid-template-columns: 1fr; }
  .chat-panel { min-height: 560px; }
  .message { max-width: 96%; }
  .chat-composer { grid-template-columns: 1fr; }
  .privacy-card { display: none; }
}
