/* totalwebX — modern dark UI */
:root {
  /* Brand — Manual de Identidade Totalweb */
  --orange: #F46D21;
  --orange-hover: #ff7d35;
  --orange-soft: rgba(244, 109, 33, 0.16);
  --orange-glow: rgba(244, 109, 33, 0.30);
  --red: #CC2328;
  --red-soft: rgba(204, 35, 40, 0.16);
  --lilac: #D4C9E9;
  --lilac-soft: #DAD7EA;

  /* Surfaces (dark, near-black brand) */
  --bg: #1a1418;
  --bg-elevated: #211a1f;
  --card: #2a2228;
  --card-hover: #32292f;
  --sidebar: #140f13;
  --sidebar-elevated: #1c161b;
  --line: rgba(212, 201, 233, 0.10);
  --line-strong: rgba(212, 201, 233, 0.18);

  /* Text */
  --ink: #F4F0F7;
  --ink-secondary: #D4C9E9;
  --muted: #A89BB3;
  --sidebar-text: #F4F0F7;

  /* Status */
  --ok: #2fbf71;
  --ok-soft: rgba(47, 191, 113, 0.15);
  --warn: #f0a202;
  --warn-soft: rgba(240, 162, 2, 0.16);
  --err: #CC2328;

  /* Shape & motion */
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 18px;
  --radius-pill: 999px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.40);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.28);
  --shadow-glow: 0 0 0 1px rgba(244, 109, 33, 0.28), 0 8px 28px rgba(244, 109, 33, 0.14);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --focus: 0 0 0 3px rgba(244, 109, 33, 0.38);

  /* Typography — Baloo (brand/headings), Lato (UI) */
  --font-brand: "Baloo 2", Baloo, "Segoe UI", system-ui, sans-serif;
  --font-ui: Lato, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-family: var(--font-ui);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, .chat-header h1, .modal h2, .brand .logo, .auth-card .logo {
  font-family: var(--font-brand);
}
a { color: var(--orange); text-decoration: none; transition: color .15s var(--ease); }
a:hover { color: var(--orange-hover); text-decoration: underline; }
.muted { color: var(--muted); font-weight: 300; font-size: .9em; }
[hidden] { display: none !important; }

/* —— Brand mark + wordmark —— */
.logo {
  font-family: var(--font-brand);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 1.85rem;
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  line-height: 1;
  user-select: none;
}
.logo-mark {
  width: 1.55em;
  height: auto;
  flex: 0 0 auto;
  display: block;
}
.logo .logo-text { display: inline-flex; align-items: baseline; }
.logo .tw { color: #fff; }
.logo .x { color: var(--orange); margin-left: .02em; }
.logo.small { font-size: 1.15rem; gap: 8px; }
.logo.small .logo-mark { width: 1.45em; }
.brand .logo,
.auth-card .logo,
.empty-state .logo {
  background: transparent;
  padding: 0;
  border-radius: 0;
}
.empty-state .logo { font-size: 2.1rem; gap: 12px; flex-direction: column; }
.empty-state .logo-mark { width: 3.2rem; }

/* —— Auth —— */
body.auth {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 28px 20px;
  background:
    radial-gradient(900px 520px at 12% -8%, rgba(244, 109, 33, 0.28), transparent 58%),
    radial-gradient(720px 480px at 100% 0%, rgba(204, 35, 40, 0.18), transparent 55%),
    radial-gradient(600px 400px at 50% 110%, rgba(244, 109, 33, 0.10), transparent 50%),
    var(--bg);
}
.auth-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent 40%), var(--card);
  border-radius: 22px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(12px);
}
.brand { text-align: center; margin-bottom: 26px; }
.tagline {
  color: var(--muted);
  margin: 12px 0 0;
  font-size: .95rem;
  letter-spacing: 0.01em;
  font-weight: 300;
}
.form { display: grid; gap: 14px; }
.form label {
  display: grid;
  gap: 7px;
  font-size: .875rem;
  font-weight: 600;
  color: var(--ink-secondary);
}
.form input,
.form textarea,
.form select,
.model-select,
.vault-toolbar input[type=search],
.vault-toolbar select,
select.approve-role,
select.change-role,
select.role-sys-level-edit {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--bg-elevated);
  color: var(--ink);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease);
}
.form input::placeholder,
.form textarea::placeholder,
.composer textarea::placeholder,
.vault-toolbar input::placeholder {
  color: #6b7388;
}
.form input:focus,
.form textarea:focus,
.form select:focus,
.model-select:focus,
.vault-toolbar input:focus,
.vault-toolbar select:focus,
.composer textarea:focus,
select.approve-role:focus,
select.change-role:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: var(--focus);
  background: #181c26;
}
.btn {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 16px;
  min-height: 40px;
  font: inherit;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: .9rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  background: #3a3238;
  color: var(--ink);
  transition: background .15s var(--ease), filter .15s var(--ease), transform .1s var(--ease), border-color .15s var(--ease), box-shadow .15s var(--ease), color .15s var(--ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  box-shadow: none;
}
.btn .btn-ico,
.btn .nav-ico {
  flex: 0 0 auto;
  display: block;
}
.btn:hover { background: #463c44; color: #fff; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}
.btn.primary {
  background: linear-gradient(180deg, #ff7d35 0%, var(--orange) 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(244, 109, 33, 0.32);
}
.btn.primary:hover {
  filter: brightness(1.07);
  background: linear-gradient(180deg, #ff8a45 0%, var(--orange-hover) 100%);
  color: #fff;
}
.btn.primary:active {
  filter: brightness(.98);
}
.btn.secondary {
  background: rgba(212, 201, 233, 0.08);
  border: 1px solid var(--line-strong);
  color: var(--ink-secondary);
}
.btn.secondary:hover {
  background: rgba(212, 201, 233, 0.14);
  border-color: rgba(212, 201, 233, 0.28);
  color: #fff;
}
.btn.ghost {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--ink-secondary);
}
.btn.ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.24);
  color: #fff;
}
.btn.danger {
  background: linear-gradient(180deg, #e03a40, var(--red));
  color: #fff;
  box-shadow: 0 4px 12px rgba(204, 35, 40, 0.28);
}
.btn.danger:hover { filter: brightness(1.07); color: #fff; }
.btn.full { width: 100%; }
.btn.sm {
  min-height: 32px;
  padding: 0 12px;
  font-size: .82rem;
  border-radius: 8px;
}
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; filter: none !important; }

/* Table action buttons — compact */
.table-wrap .btn,
.row.gap .btn {
  min-height: 34px;
  padding: 0 12px;
  font-size: .82rem;
}
.table-wrap select.approve-role,
.table-wrap select.change-role,
select.approve-role,
select.change-role {
  min-height: 34px;
}
.error, .success {
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  border: 1px solid transparent;
}
.error {
  background: var(--red-soft);
  color: #ffb0b3;
  border-color: rgba(204, 35, 40, 0.35);
}
.success {
  background: var(--ok-soft);
  color: #9be7bc;
  border-color: rgba(47, 191, 113, 0.35);
}
.auth-forgot {
  margin: -4px 0 0;
  text-align: right;
  font-size: .88rem;
}
.auth-forgot a { color: var(--lilac-soft); font-weight: 600; }
.auth-forgot a:hover { color: var(--orange); }
.auth-foot {
  text-align: center;
  margin-top: 20px;
  color: var(--muted);
  font-size: .92rem;
}

/* —— App shell —— */
body.app-shell {
  display: grid;
  grid-template-columns: 272px 1fr;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}
.sidebar {
  background: linear-gradient(180deg, #10131a 0%, var(--sidebar) 40%);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  gap: 12px;
  min-height: 0;
  border-right: 1px solid var(--line);
}
.sidebar-top { display: grid; gap: 14px; }
.sidebar-bottom {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* Side nav buttons (Cofre / Meu uso / Admin / etc.) */
.side-nav,
.admin-nav {
  display: grid;
  gap: 4px;
}
.side-nav-btn,
.admin-nav a,
a.side-nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--lilac-soft);
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease), box-shadow .15s var(--ease);
  box-sizing: border-box;
}
.side-nav-btn .nav-ico,
.admin-nav a .nav-ico {
  flex: 0 0 auto;
  opacity: .9;
  color: var(--lilac);
}
.side-nav-btn span:not(.badge),
.admin-nav a span:not(.badge) {
  flex: 1;
  text-align: left;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-nav-btn:hover,
.admin-nav a:hover {
  background: rgba(212, 201, 233, 0.08);
  color: #fff;
  text-decoration: none;
}
.side-nav-btn:hover .nav-ico,
.admin-nav a:hover .nav-ico { color: #fff; opacity: 1; }
.side-nav-btn.active,
.admin-nav a.active,
.side-nav-btn.active:hover,
.admin-nav a.active:hover {
  background: var(--orange-soft);
  color: #fff;
  border-color: rgba(244, 109, 33, 0.28);
  box-shadow: inset 3px 0 0 var(--orange);
}
.side-nav-btn.active .nav-ico,
.admin-nav a.active .nav-ico { color: var(--orange); opacity: 1; }
.side-nav-btn:focus-visible,
.admin-nav a:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.badge {
  background: var(--orange);
  color: #fff;
  border-radius: var(--radius-pill);
  font-size: .72rem;
  padding: 2px 8px;
  font-weight: 700;
  min-width: 1.4em;
  text-align: center;
  flex: 0 0 auto !important;
}

/* User card with avatar initials */
.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(212, 201, 233, 0.06);
  border: 1px solid var(--line);
}
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: .85rem;
  color: #fff;
  background: linear-gradient(145deg, var(--orange), var(--red));
  box-shadow: 0 4px 12px rgba(244, 109, 33, 0.25);
  flex: 0 0 auto;
  letter-spacing: 0.02em;
}
.user-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.user-meta strong {
  color: #fff;
  font-weight: 700;
  font-size: .9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-meta span {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-chip {
  display: grid;
  font-size: .85rem;
  gap: 2px;
  padding: 4px 2px;
}
.user-chip strong { color: #fff; font-weight: 600; }
.user-chip span { color: var(--muted); }

/* Legacy linkish → look like nav if still used */
.linkish {
  color: var(--lilac-soft);
  font-size: .9rem;
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color .15s, background .15s;
}
.linkish:hover {
  color: #fff;
  text-decoration: none;
  background: rgba(212, 201, 233, 0.08);
}

/* Sidebar logout — ghost, danger on hover */
.sidebar .btn.ghost.btn-logout,
.sidebar .btn-logout {
  background: transparent;
  border: 1px solid rgba(212, 201, 233, 0.18);
  color: var(--lilac-soft) !important;
  min-height: 40px;
}
.sidebar .btn.ghost.btn-logout:hover,
.sidebar .btn-logout:hover {
  background: var(--red-soft);
  border-color: rgba(204, 35, 40, 0.45);
  color: #ffb0b3 !important;
}
.sidebar .btn.ghost.btn-logout:hover .nav-ico,
.sidebar .btn-logout:hover .nav-ico { color: #ffb0b3; }

/* —— Main panels —— */
.chat-main,
.admin-main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(800px 400px at 80% -10%, rgba(244, 109, 33, 0.07), transparent 55%),
    radial-gradient(600px 300px at 0% 100%, rgba(204, 35, 40, 0.04), transparent 50%),
    var(--bg-elevated);
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 17, 21, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.chat-header h1 {
  font-size: 1.05rem;
  margin: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.model-select {
  max-width: 240px;
  width: auto;
  padding: 8px 12px;
  font-size: .875rem;
  background: var(--card);
}

/* —— Chat —— */
.messages {
  overflow: auto;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.12) transparent;
}
.empty-state {
  margin: auto;
  text-align: center;
  color: var(--muted);
  max-width: 420px;
  padding: 32px 20px;
}
.empty-state .logo {
  margin-bottom: 16px;
  font-size: 2.2rem;
}
.empty-state p {
  font-size: 1.05rem;
  color: var(--ink-secondary);
  line-height: 1.5;
  margin: 0;
}
.msg {
  max-width: min(760px, 100%);
  padding: 14px 16px;
  border-radius: 16px;
  line-height: 1.6;
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  animation: msg-in .22s var(--ease);
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(160deg, rgba(244, 109, 33, 0.22), rgba(244, 109, 33, 0.1));
  border-color: rgba(244, 109, 33, 0.35);
  box-shadow: 0 4px 16px rgba(244, 109, 33, 0.08);
}
.msg.assistant { background: var(--card); }
.msg .role {
  font-size: .7rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.msg.user .role { color: #ffb07a; }
.msg .content pre {
  background: #0a0c10;
  color: #e8e4dc;
  padding: 12px 14px;
  border-radius: 10px;
  overflow: auto;
  border: 1px solid var(--line);
}
.msg .content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88em;
}
.msg .content :not(pre) > code {
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 6px;
  border-radius: 5px;
}
.msg .content p { margin: 0 0 .75em; }
.msg .content p:last-child { margin-bottom: 0; }
.msg .content ul, .msg .content ol { margin: 0 0 .75em; padding-left: 1.25em; }
.msg .content a { word-break: break-word; }
.msg.error-msg {
  border-color: rgba(204, 35, 40, 0.45);
  background: var(--red-soft);
  color: #ffb0b3;
}

.composer {
  display: flex;
  gap: 10px;
  padding: 14px 18px 18px;
  border-top: 1px solid var(--line);
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(12px);
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 160px;
  min-height: 48px;
  padding: 12px 15px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  font: inherit;
  background: var(--card);
  color: var(--ink);
  line-height: 1.45;
  transition: border-color .15s, box-shadow .15s;
}
.composer .btn.primary {
  min-height: 48px;
  padding-inline: 18px;
  border-radius: 12px;
  gap: 8px;
}

/* —— Admin —— */
.admin-content {
  padding: 22px 22px 32px;
  overflow: auto;
  scrollbar-width: thin;
}
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, transform .15s var(--ease);
}
.card:hover { border-color: var(--line-strong); }
.card .label {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.card .value {
  font-size: 1.55rem;
  font-weight: 700;
  margin-top: 8px;
  letter-spacing: -0.02em;
  color: #fff;
}
.table-wrap {
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
th, td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
tr:last-child td { border-bottom: 0; }
th {
  background: rgba(255, 255, 255, 0.03);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}
tbody tr { transition: background .12s; }
tbody tr:hover { background: rgba(255, 255, 255, 0.025); }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; flex-wrap: wrap; }
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: .75rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink-secondary);
  letter-spacing: 0.02em;
}
.pill.pendente { background: var(--warn-soft); color: #ffd27a; }
.pill.ativo { background: var(--ok-soft); color: #9be7bc; }
.pill.rejeitado,
.pill.inativo { background: var(--red-soft); color: #ffb0b3; }
.check {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-weight: 500 !important;
  color: var(--ink-secondary);
}
.checks {
  display: grid;
  gap: 4px;
  max-height: 160px;
  overflow: auto;
  border: 1px solid var(--line);
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
}
fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0;
}
fieldset legend {
  padding: 0 6px;
  color: var(--ink-secondary);
  font-weight: 600;
  font-size: .85rem;
}
dialog {
  border: 0;
  border-radius: var(--radius-lg);
  padding: 0;
  box-shadow: var(--shadow);
  max-width: min(560px, 94vw);
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line-strong);
}
dialog::backdrop {
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(4px);
}
.modal {
  padding: 22px;
  display: grid;
  gap: 12px;
}
.modal h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.icon-btn {
  border: 0;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font-size: 1.15rem;
  cursor: pointer;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.mobile-only { display: none; }


/* Compact selects in tables */
.table-wrap select,
select.approve-role,
select.change-role,
select.role-sys-level-edit {
  width: auto;
  min-width: 120px;
  padding: 7px 10px;
  font-size: .85rem;
}

/* —— Cofre —— */
.vault-lock { display: grid; place-items: center; min-height: 60vh; }
.vault-lock-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line-strong);
}
.vault-lock-card h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}
.vault-toolbar { margin-bottom: 16px; flex-wrap: wrap; }
.vault-toolbar input[type=search] { flex: 1; min-width: 180px; width: auto; }
.vault-toolbar select { width: auto; min-width: 150px; }
.vault-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.vault-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 6px;
  min-width: 0;
  transition: border-color .15s var(--ease), transform .15s var(--ease), box-shadow .15s;
}
.vault-card:hover {
  border-color: rgba(244, 109, 33, 0.45);
  transform: translateY(-1px);
  box-shadow: var(--shadow-glow);
}
.vault-card .vt {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #fff;
}
.vault-card .vm {
  color: var(--muted);
  font-size: .85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.secret-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.secret-mask {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .08em;
  color: var(--ink-secondary);
}
.chip-type {
  display: inline-block;
  font-size: .7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--orange-soft);
  color: #ffb07a;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* —— Responsive —— */
@media (max-width: 860px) {
  body.app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 300px);
    z-index: 20;
    transform: translateX(-105%);
    transition: transform .22s var(--ease);
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; }
  .model-select { max-width: 150px; font-size: .82rem; }
  .messages { padding: 18px 14px; }
  .admin-content { padding: 16px; }
  .composer { padding: 12px 12px 14px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}


/* —— Message time (WhatsApp-style) —— */
.msg {
  position: relative;
  padding-bottom: 22px;
}
.msg .msg-time {
  position: absolute;
  right: 12px;
  bottom: 6px;
  font-size: .68rem;
  line-height: 1;
  color: var(--muted);
  opacity: .75;
  user-select: none;
  pointer-events: none;
}
.msg.user .msg-time { color: #ffc9a8; opacity: .85; }

/* —— Agent activity status (Grok-like) —— */
.agent-status {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  padding: 4px 2px 8px;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 500;
  letter-spacing: .01em;
  animation: msg-in .18s var(--ease);
}
.agent-status[hidden] { display: none !important; }
.agent-status-icon {
  display: inline-flex;
  color: #F46D21;
  animation: agent-sparkle 1.4s ease-in-out infinite;
}
.agent-status-icon svg { display: block; }
@keyframes agent-sparkle {
  0%, 100% { transform: rotate(0deg) scale(1); opacity: .85; filter: drop-shadow(0 0 0 rgba(244,109,33,0)); }
  40% { transform: rotate(18deg) scale(1.18); opacity: 1; filter: drop-shadow(0 0 6px rgba(244,109,33,.55)); }
  70% { transform: rotate(-8deg) scale(.96); opacity: .9; }
}
.agent-status-label {
  color: var(--muted);
}

/* Vault edit: linkage is above credentials, with an independently scrollable modal. */
#item-modal { max-height: 92dvh; overflow: auto; }
#item-modal .vault-access-controls { margin: 0 0 12px; padding: 12px; border: 1px solid var(--line-strong); border-radius: 10px; }
#item-modal .vault-access-controls legend { color: var(--ink-secondary); font-weight: 700; }
#item-modal .vault-access-controls label { display: block; margin: 6px 0; }
#item-modal .vault-access-controls select { width: 100%; }

.msg .content details { font-size: .78rem; color: var(--muted); margin-top: 12px; }
.msg .content details summary { cursor: pointer; }
.vault-unlock-card { margin-top: 12px; padding: 12px; border: 1px solid rgba(244,109,33,.4); border-radius: 10px; }
.vault-unlock-card p { margin: 0 0 9px; color: var(--muted); }
#chat-vault-unlock-modal { max-width: min(460px,94vw); }

/* Audit column filters: full history options, server-side queries. */
.audit-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 10px; }
.audit-toolbar label { display: grid; gap: 5px; color: var(--ink-secondary); font-size: .85rem; }
.audit-toolbar input, .audit-toolbar select, .audit-column-filter { border: 1px solid var(--line-strong); border-radius: 7px; padding: 8px; background: var(--bg-elevated); color: var(--ink); font: inherit; }
.audit-column-filter { display: block; margin-top: 8px; width: 100%; min-width: 125px; max-width: 250px; font-size: .8rem; font-weight: 400; }
.audit-column-filter:focus, .audit-toolbar input:focus, .audit-toolbar select:focus { outline: 2px solid #F46D21; outline-offset: 1px; }
.audit-column-label { display: block; white-space: nowrap; }
.audit-table th { vertical-align: top; }
.audit-table td { max-width: 400px; overflow-wrap: anywhere; white-space: normal; }
.audit-filter-help { font-size: .83rem; }
.audit-pagination { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 14px 0 25px; }
/* Create and edit share this responsive, accessible role form. */
#role-modal { padding: 0; width: 780px; max-width: calc(100vw - 28px); max-height: 94dvh; overflow: hidden; }
#role-modal .modal { width: 100%; max-width: 100%; max-height: 90dvh; overflow-y: auto; overflow-x: hidden; padding: 24px; gap: 18px; }
#role-form > *, #role-form fieldset, #role-form label, #role-form div { min-width: 0; }
#role-form .role-section { border: 1px solid var(--line-strong); border-radius: 12px; padding: 16px; margin: 0; display: grid; gap: 14px; max-width: 100%; }
#role-form .role-section legend { color: #F46D21; font-weight: 700; padding: 0 8px; }
#role-form .role-field-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
#role-form .role-permissions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
#role-form label.permission-row { display: grid; grid-template-columns: 20px minmax(0,1fr); align-items: start; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; }
#role-form input[type=checkbox] { width: 18px; height: 18px; min-width: 18px; padding: 0; margin: 3px 0 0; accent-color: #F46D21; cursor: pointer; }
#role-form .permission-copy strong { display: block; font-size: .88rem; line-height: 1.4; font-weight: 600; }
#role-form .permission-copy small { display: block; color: var(--muted); font-size: .78rem; line-height: 1.5; margin-top: 4px; font-weight: 400; }
#role-form .permission-copy, #role-form .model-permission span, #role-form label { overflow-wrap: anywhere; }
#role-form input:not([type=checkbox]), #role-form select, #role-form textarea { width: 100%; min-width: 0; max-width: 100%; }
#role-form #model-checks { max-height: none; overflow: visible; grid-template-columns: repeat(2,minmax(0,1fr)); padding: 0; border: 0; gap: 9px; }
#role-form .role-systems-add, #role-form .role-system-card { display: grid; gap: 12px; padding: 14px; background: var(--bg-elevated); border: 1px solid var(--line); border-radius: 10px; }
#role-form .role-system-cards { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
#role-form .role-access-details { color: var(--muted); font-size: .85rem; }
#role-form .role-access-details summary { cursor: pointer; margin-bottom: 12px; }
#role-form .role-modal-actions { position: sticky; bottom: -24px; background: var(--card); margin: 0 -8px -24px; padding: 14px 8px 20px; border-top: 1px solid var(--line); z-index: 2; }
@media (max-width: 620px) {
  #role-modal .modal { padding: 16px; }
  #role-form .role-field-grid, #role-form .role-permissions, #role-form #model-checks, #role-form .role-system-cards { grid-template-columns: minmax(0,1fr); }
  #role-form .role-modal-actions { bottom: -16px; margin-bottom: -16px; }
}

.presence-pill { display: inline-flex; align-items: center; gap: 7px; border-radius: 999px; padding: 5px 10px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.presence-pill.online { background: rgba(47,191,113,.14); color: #9be7bc; }
.presence-pill.offline { background: rgba(160,160,160,.12); color: #b6b1bb; }
.presence-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.presence-last-seen { display: block; margin-top: 6px; font-size: .75rem; white-space: nowrap; }
/* Shared sector tasks: cards instead of wide tables. */
body.tasks-shell { display: block; height: auto; min-height: 100dvh; overflow: auto; overflow-x: hidden; }
.tasks-topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; padding: 16px 24px; border-bottom: 1px solid var(--line); background: var(--sidebar); }
.tasks-topbar nav { display: flex; flex-wrap: wrap; gap: 8px; }
.tasks-main { width: min(1160px,100%); padding: 24px; margin: auto; min-width: 0; }
.tasks-main > h1 { font-size: 1.6rem; }
.tasks-tabs { display: flex; flex-wrap: wrap; gap: 12px; margin: 24px 0; }
.task-card-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,290px),1fr)); gap: 16px; margin: 18px 0; }
.task-card { min-width: 0; background: var(--card); border: 1px solid var(--line-strong); border-radius: 14px; padding: 18px; overflow-wrap: anywhere; }
.task-card p { white-space: pre-wrap; }
.task-card h3 { font-size: 1rem; margin: 0; }
.task-card-heading, .task-card-meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.task-overdue { border-color: var(--orange); box-shadow: inset 3px 0 var(--orange); }
.task-card-meta { margin: 12px 0; font-size: .85rem; }
.task-completion-form { display: grid; gap: 12px; }
.task-completion-check { display: grid; grid-template-columns: 22px minmax(0,1fr); gap: 10px; cursor: pointer; align-items: start; }
.task-completion-check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: #F46D21; }
.task-note-label { display: grid; gap: 8px; font-size: .85rem; }
.task-note { width: 100%; min-width: 0; max-width: 100%; background: var(--bg-elevated); border: 1px solid var(--line-strong); border-radius: 8px; color: var(--ink); padding: 10px; font: inherit; resize: vertical; }
.task-completed-by { font-size: .88rem; }
.task-progress-card { display: grid; gap: 10px; padding: 16px; margin: 16px 0; background: var(--bg-elevated); border: 1px solid var(--line); border-radius: 12px; }
.task-progress-card progress { width: 100%; max-width: 100%; accent-color: #F46D21; height: 10px; }
.task-progress-card progress::-webkit-progress-value { background: #F46D21; }
.task-progress-card progress::-moz-progress-bar { background: #F46D21; }
.task-sector-section { margin: 28px 0; }
.task-filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.task-filters label, .tasks-definition-actions label { display: grid; gap: 7px; min-width: 0; font-size: .85rem; }
.task-filters input, .task-filters select, .tasks-definition-actions select { max-width: 100%; min-width: 0; padding: 10px; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--ink); background: var(--bg-elevated); font: inherit; }
.tasks-definition-actions { display: flex; flex-wrap: wrap; gap: 16px; align-items: end; }
#task-edit-modal, #task-history-modal { padding: 0; width: 760px; max-width: calc(100vw - 28px); max-height: 92dvh; overflow: hidden; }
#task-edit-modal .modal, #task-history-modal .modal { max-height: 90dvh; overflow-y: auto; overflow-x: hidden; padding: 24px; }
#task-edit-form > *, #task-edit-form label, #task-edit-form div { min-width: 0; max-width: 100%; }
#task-edit-form input, #task-edit-form textarea, #task-edit-form select { min-width: 0; max-width: 100%; }
#task-edit-form label.task-check { display: grid; grid-template-columns: 18px minmax(0,1fr); gap: 9px; align-items: start; cursor: pointer; }
#task-edit-form input[type=checkbox] { width: 18px; height: 18px; padding: 0; margin: 2px 0 0; accent-color: #F46D21; }
#task-edit-form .task-check small { display: block; font-size: .78rem; font-weight: 400; margin-top: 5px; }
.task-weekdays { border: 1px solid var(--line-strong); border-radius: 10px; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; padding: 16px; margin: 0; }
.task-weekdays legend { color: #F46D21; }
.task-form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
.task-history-entry { border-bottom: 1px solid var(--line); padding: 12px 0; overflow-wrap: anywhere; }
.chat-task-summary { display: grid; gap: 6px; margin: 8px 16px; padding: 12px; border: 1px solid var(--line-strong); border-radius: 10px; font-size: .82rem; color: var(--ink); text-decoration: none; }
.chat-task-summary.has-overdue { border-color: #F46D21; }
@media (max-width:620px) {
 .tasks-main { padding: 16px; }
 .tasks-topbar { padding: 16px; }
 .tasks-topbar nav { width: 100%; }
 .task-form-grid { grid-template-columns: minmax(0,1fr); }
 .task-weekdays { grid-template-columns: repeat(2,minmax(0,1fr)); }
 .task-filters label { flex: 1 1 140px; }
 #task-edit-modal .modal { padding: 16px; }
}
/* Role access summaries remain visible without a wide table. */
.role-overview-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,320px),1fr)); gap: 18px; }
.role-overview-card { min-width: 0; display: grid; align-content: start; gap: 14px; padding: 20px; background: var(--card); border: 1px solid var(--line-strong); border-radius: 14px; overflow-wrap: anywhere; }
.role-overview-card h2 { margin: 0; font-size: 1.1rem; }
.role-overview-card p { margin: 0; }
.role-overview-card details { font-size: .85rem; }
.role-overview-card details p { margin: 10px 0; }
.role-overview-card summary { cursor: pointer; color: var(--ink-secondary); }
.role-system-chips { display: flex; flex-wrap: wrap; gap: 7px; min-width: 0; }
.role-system-chip { display: inline-block; padding: 5px 10px; border-radius: 999px; border: 1px solid rgba(244,109,33,.4); background: var(--orange-soft); color: var(--ink); max-width: 100%; font-size: .8rem; overflow-wrap: anywhere; }
.role-permissions-summary { font-size: .82rem; }
#role-form .role-systems-heading { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0; font-size: .95rem; }
#role-form .role-system-level { color: var(--orange); font-size: .82rem; }
/* Situation precedes the title; acknowledgement means displayed, not read. */
.task-title-state { display: flex; align-items: flex-start; gap: 9px; min-width: 0; }
.task-title-state strong { flex: 1; min-width: 0; overflow-wrap: anywhere; line-height: 1.5; }
.task-state { flex: 0 0 auto; font-size: .74rem; white-space: nowrap; }
.task-state-completed { background: rgba(47,191,113,.16); color: #9be7bc; border: 1px solid rgba(47,191,113,.35); }
.task-state-pending { background: rgba(168,155,179,.12); color: #d4c9e9; border: 1px solid rgba(244,109,33,.3); }
.task-state-overdue { background: rgba(204,35,40,.18); color: #ff9b9b; border: 1px solid rgba(204,35,40,.5); }
.task-overdue { border-color: #CC2328; box-shadow: inset 3px 0 #CC2328; }
.task-note-details summary { cursor: pointer; color: var(--ink-secondary); font-size: .85rem; }
.task-note-details[open] .task-note-label { margin-top: 12px; }
.task-completion-help { font-size: .82rem; line-height: 1.5; margin: 0; }
.task-view-info { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 10px; font-size: .82rem; line-height: 1.6; }
.task-view-info summary { cursor: pointer; color: var(--ink-secondary); }
.task-view-info p { overflow-wrap: anywhere; }
.chat-task-items { display: grid; gap: 9px; max-height: 180px; overflow-y: auto; overflow-x: hidden; }
.chat-task-item { display: flex; align-items: flex-start; gap: 7px; min-width: 0; }
.chat-task-name { min-width: 0; overflow-wrap: anywhere; }
.chat-task-item .task-state { font-size: .63rem; padding: 3px 6px; }
/* Task links share the standard nav icon/hover/active styles, without truncation. */
.side-nav-btn.task-nav-link > span:not(.badge), .admin-nav a.task-nav-link > span:not(.badge) { overflow: visible; text-overflow: clip; white-space: normal; overflow-wrap: anywhere; line-height: 1.35; }

/* Chat image attachments — same compact composer on desktop and mobile. */
.composer { flex-wrap: wrap; }
.composer textarea { min-width: 0; flex: 1 1 120px; }
.composer .chat-attach { height: 48px; flex: 0 0 42px; border: 1px solid var(--line); border-radius: 12px; }
.composer .chat-attach:hover { color: #F46D21; border-color: #F46D21; }
.composer.image-dragover { outline: 2px dashed #F46D21; outline-offset: -6px; }
.chat-image-previews { display: flex; flex-wrap: wrap; gap: 10px; flex-basis: 100%; }
.chat-image-previews[hidden], .chat-image-notice[hidden] { display: none; }
.chat-image-preview { width: 82px; height: 82px; position: relative; border: 1px solid var(--line); border-radius: 12px; }
.chat-image-preview img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.image-remove { position: absolute; right: -5px; top: -5px; border: 1px solid var(--line); border-radius: 50%; background: var(--card); color: var(--ink); width: 25px; height: 25px; font-size: 19px; cursor: pointer; }
.chat-image-notice { flex-basis: 100%; margin: 0; font-size: .82rem; color: #F46D21; }
.chat-image-gallery { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chat-image-open { display: block; padding: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: transparent; cursor: zoom-in; max-width: 100%; }
.chat-image-open img { display: block; max-width: min(230px, 100%); max-height: 200px; object-fit: contain; }
.chat-image-lightbox { max-width: min(96vw, 1100px); overflow-x: hidden; padding: 16px; }
.chat-image-lightbox img { display: block; max-width: 100%; max-height: 78vh; margin: 12px auto 0; object-fit: contain; }
@media (max-width: 480px) { .composer .btn.primary { padding-inline: 12px; } .composer .btn.primary span { display: none; } .chat-image-open img { max-width: 180px; } }
