/* Mobile-First Base — Identidade Visual MitraX Sentinel */
:root {
  --bg: #020712;
  --shell: #0b111e;
  --card: #111927;
  --card-inner: #061121;
  --border: rgba(148, 163, 184, 0.16);
  --teal-border: rgba(20, 184, 166, 0.22);
  --text: #f8fafc;
  --muted: #94a3b8;
  --teal: #14b8a6;
  --teal-bright: #2dd4bf;
  --teal-dark: #0f766e;
  --cyan: #0ea5e9;
  --warn-bg: rgba(245, 158, 11, 0.14);
  --warn-text: #fde68a;
  --ok-bg: rgba(20, 184, 166, 0.16);
  --ok-text: #5eead4;
  --err-border: rgba(244, 63, 94, 0.35);
  --err-bg: rgba(244, 63, 94, 0.14);
  --err-text: #fecdd3;
}

*, *::before, *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  font-size: 16px;
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(circle at 50% 0%, #071529 0%, #020712 65%);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

code {
  font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
  font-size: 0.85em;
}

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  background: var(--teal);
  color: #042f2e;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: 8px;
  z-index: 100;
}
.skip-link:focus {
  left: 12px;
}

:where(a, button, input, textarea, select, [tabindex]):focus-visible {
  outline: 3px solid #2dd4bf;
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, 1080px);
  min-height: 100dvh;
  margin-inline: auto;
  padding: 16px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.main-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
}

/* ==================== TOPBAR (Etapa 2: Chat) ==================== */
.topbar {
  background: var(--shell);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px 18px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}

.crest-avatar-bg {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  display: block;
}

.brand-title {
  display: block;
  font-weight: 700;
  font-size: 1.08rem;
  line-height: 1.2;
}

.brand-sub {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
}

.crest-seamless {
  border: none !important;
  outline: none !important;
  filter: drop-shadow(0 8px 20px rgba(20, 184, 166, 0.22));
}

/* ==================== ETAPA 1: Cartão Idêntico ao Login do MitraX Sentinel ==================== */
.intake-stage {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-block: 8px;
}

.login-crest-card {
  width: min(100%, 448px);
  background: radial-gradient(circle at 50% 20%, #071628 0%, #040d1e 45%, #020814 100%);
  border: 1px solid rgba(45, 212, 191, 0.14);
  border-radius: 28px;
  box-shadow: 0 30px 80px -15px rgba(0, 0, 0, 0.9);
  padding: 28px 24px 30px;
  text-align: center;
}

.crest-hero {
  width: 144px;
  height: 144px;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.crest-hero-img {
  width: 144px;
  height: 144px;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.crest-hero-sm {
  width: 88px;
  height: 88px;
  margin-bottom: 8px;
}

.crest-hero-img-sm {
  width: 88px;
  height: 88px;
  object-fit: contain;
}

.crest-title {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.crest-dialog-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  color: #ffffff;
  text-align: center;
}

.crest-subtitle {
  margin: 6px 0 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--teal-bright);
  text-align: center;
}

.crest-error-box {
  margin-top: 16px;
  padding: 11px 14px;
  border-radius: 16px;
  background: var(--err-bg);
  border: 1px solid var(--err-border);
  color: var(--err-text);
  font-size: 0.82rem;
  text-align: left;
}

.crest-connected-box {
  margin-top: 16px;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--ok-bg);
  border: 1px solid rgba(45, 212, 191, 0.35);
  color: var(--ok-text);
  font-size: 0.82rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.btn-inline-link {
  background: none;
  border: none;
  color: #ffffff;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 6px;
}

.crest-form {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  text-align: left;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #cbd5e1;
}

.crest-form input[type="text"],
.crest-form input[type="password"],
.crest-form select {
  width: 100%;
  min-height: 48px;
  background: var(--card-inner);
  color: #ffffff;
  border: 1px solid var(--teal-border);
  border-radius: 16px;
  padding: 12px 16px;
  font: inherit;
  font-size: max(1rem, 1em);
  transition: border-color 0.18s ease;
}

.crest-form input:focus,
.crest-form select:focus {
  border-color: var(--teal-bright);
  outline: none;
}

/* Campos normais (fora do crest card, ex: chat e dialog GLPI) */
input[type="text"],
input[type="password"],
textarea,
select {
  width: 100%;
  min-height: 48px;
  background: var(--card-inner);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
  font: inherit;
  font-size: max(1rem, 1em);
}

textarea {
  min-height: 64px;
}

::placeholder {
  color: rgba(148, 163, 184, 0.48);
}

select option {
  background-color: #061121;
  color: #f8fafc;
}

.field-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.error-msg {
  display: none;
  font-size: 0.8rem;
  color: var(--err-text);
  margin-top: 2px;
}

:is(:user-invalid, .user-invalid-fallback) {
  border-color: #f43f5e !important;
  background: var(--err-bg) !important;
}

select:is(:user-invalid, .user-invalid-fallback) {
  background: var(--card-inner) !important;
}

:is(:user-invalid, .user-invalid-fallback) + .error-msg,
.password-wrap:has(:is(:user-invalid, .user-invalid-fallback)) + .error-msg {
  display: block;
}

/* Bloco condicional Nextcloud quando Departamento === "Diretoria" */
.nc-inline-box {
  border: 1px solid rgba(45, 212, 191, 0.28);
  background: rgba(6, 17, 33, 0.75);
  border-radius: 18px;
  padding: 14px;
  margin: 2px 0 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.nc-inline-box legend {
  padding: 0 8px;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--teal-bright);
}

.nc-inline-verified {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--ok-bg);
  color: var(--ok-text);
  font-size: 0.84rem;
}

.nc-inline-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.password-wrap {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}

.checkbox-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-height: 20px;
  accent-color: var(--teal);
  cursor: pointer;
  flex-shrink: 0;
}

.checkbox-row label {
  font-size: 0.84rem;
  font-weight: 500;
  color: #cbd5e1;
  cursor: pointer;
}

.password-wrap input {
  flex: 1 1 auto;
}

.btn-toggle-pass {
  min-block-size: 48px;
  padding: 0 14px;
  border-radius: 14px;
  background: #0b192e;
  border: 1px solid var(--teal-border);
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-pill-primary {
  width: 100%;
  min-block-size: 50px;
  margin-top: 4px;
  padding: 13px 20px;
  border: none;
  border-radius: 9999px;
  background: linear-gradient(90deg, #14b8a6 0%, #0ea5e9 100%);
  color: #ffffff;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 26px -6px rgba(20, 184, 166, 0.35);
  transition: filter 0.15s ease, transform 0.15s ease;
}

.btn-pill-primary:hover {
  filter: brightness(1.08);
}

.btn-pill-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-pill-secondary {
  width: 100%;
  min-block-size: 46px;
  padding: 11px 18px;
  border-radius: 9999px;
  background: rgba(6, 17, 33, 0.85);
  border: 1px solid rgba(45, 212, 191, 0.28);
  color: #5eead4;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-pill-secondary:hover {
  border-color: var(--teal-bright);
  background: rgba(20, 184, 166, 0.12);
}

.crest-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 12px;
  color: var(--muted);
  font-size: 0.78rem;
}

.crest-divider::before,
.crest-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(148, 163, 184, 0.16);
}

/* ==================== ETAPA 2: Triagem IA + Contexto ==================== */
.triage-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.banner {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.88rem;
}
.banner-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.chat-panel {
  background: var(--shell);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 64dvh;
}

.panel-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.panel-footer-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.panel-footer-actions .btn {
  flex: 1 1 180px;
}

h2 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.25;
}

.panel-subtitle {
  margin: 4px 0 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 48dvh;
  overflow-y: auto;
  padding-right: 4px;
}

.msg {
  padding: 12px 14px;
  border-radius: 12px;
  max-width: 92%;
  border: 1px solid var(--border);
}
.msg-assistant {
  align-self: flex-start;
  background: var(--card);
}
.msg-user {
  align-self: flex-end;
  background: rgba(2, 132, 199, 0.18);
  border-color: rgba(56, 189, 248, 0.3);
}
.msg-system {
  align-self: stretch;
  max-width: 100%;
  background: var(--card-inner);
  font-size: 0.86rem;
}

.msg-role {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--teal);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.msg-body {
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-body a {
  color: #5eead4;
}

.suggested-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(20, 184, 166, 0.12);
  border: 1px solid rgba(20, 184, 166, 0.4);
  border-radius: 12px;
}
.suggested-reason {
  margin: 4px 0 0;
  font-size: 0.86rem;
  color: var(--muted);
}

.loading-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.86rem;
  color: var(--muted);
}
progress {
  accent-color: var(--teal);
  width: 120px;
}

.composer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.composer-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-grow {
  width: 100%;
}

.composer-actions {
  display: flex;
  gap: 8px;
}
.composer-actions .btn {
  flex: 1;
}

.photo-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.84rem;
  color: var(--ok-text);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-block-size: 48px;
  min-inline-size: 48px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: linear-gradient(135deg, var(--teal), var(--cyan));
  color: #ffffff;
}
.btn-secondary {
  background: var(--card);
  color: var(--text);
  border-color: var(--border);
}
.btn-accent {
  background: var(--teal-dark);
  color: #f0fdfa;
  border-color: rgba(45, 212, 191, 0.35);
}
.btn-full {
  width: 100%;
  margin-top: 6px;
}
.btn-link {
  background: none;
  border: none;
  color: #fca5a5;
  cursor: pointer;
  text-decoration: underline;
  font: inherit;
  min-block-size: 40px;
}

.context-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--shell);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
}
.card-desc {
  margin: 6px 0 10px;
  font-size: 0.82rem;
  color: var(--muted);
}

.kv-list {
  margin: 12px 0 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kv-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
  font-size: 0.88rem;
}
.kv-row dt {
  color: var(--muted);
}
.kv-row dd {
  margin: 0;
  font-family: ui-monospace, Consolas, monospace;
  text-align: right;
  word-break: break-word;
}

/* Barras de recursos com avanço de cor e espaçamento amplo */
.resource-metrics {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 14px 0 18px;
  padding: 14px;
  background: var(--card-inner);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.metric-item {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.metric-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 0.84rem;
}

.metric-head label {
  color: var(--muted);
  font-weight: 500;
}

.metric-val {
  font-family: ui-monospace, Consolas, monospace;
  font-weight: 600;
  color: var(--text);
}

.resource-bar {
  appearance: none;
  border: 0 solid;
  overflow: clip;
  width: 100%;
  height: 10px;
  --progress-bar-radius: 1e5px;
  border-radius: var(--progress-bar-radius);
  background: rgba(148, 163, 184, 0.16);
  box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.25);
  --progress-bar-fill: linear-gradient(90deg, #10b981, #14b8a6);
}

.resource-bar[data-level="warn"] {
  --progress-bar-fill: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.resource-bar[data-level="crit"] {
  --progress-bar-fill: linear-gradient(90deg, #ef4444, #f97316);
}

.resource-bar::-webkit-progress-bar {
  background: transparent;
}

.resource-bar::-webkit-progress-value {
  background: var(--progress-bar-fill);
  border-radius: var(--progress-bar-radius);
  transition: inline-size 0.3s ease;
}

.resource-bar::-moz-progress-bar {
  background: var(--progress-bar-fill);
  border-radius: var(--progress-bar-radius);
  transition: inline-size 0.3s ease;
}

.actions-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.action-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.action-name {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
}
.action-badge {
  font-size: 0.72rem;
  color: var(--muted);
}

.draft-title {
  margin: 8px 0 6px;
  font-weight: 600;
}
.draft-meta {
  margin: 0;
  font-size: 0.84rem;
  color: var(--muted);
}

/* Native dialogs following modern-web-guidance */
dialog[open] {
  background: var(--shell);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  width: min(500px, calc(100vw - 24px));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
}
dialog.crest-dialog[open] {
  width: min(440px, calc(100vw - 24px));
  background: radial-gradient(circle at 50% 20%, #071628 0%, #040d1e 45%, #020814 100%);
  border: 1px solid rgba(45, 212, 191, 0.18);
  border-radius: 28px;
  padding: 26px 24px;
}
dialog:modal {
  overscroll-behavior: contain;
}
dialog::backdrop {
  background: rgba(2, 7, 18, 0.82);
  backdrop-filter: blur(8px);
  overflow: hidden;
  overscroll-behavior: contain;
}
.dialog-text {
  color: var(--muted);
  margin: 8px 0 16px;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}
.crest-dialog-actions {
  margin-top: 8px;
  flex-direction: column-reverse;
}

.crest-dialog-actions .btn-pill-primary,
.crest-dialog-actions .btn-pill-secondary {
  margin-top: 0;
  min-block-size: 48px;
  white-space: nowrap;
  flex: 1;
}

.ticket-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
}
.form-row-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (pointer: coarse) {
  .btn,
  .btn-pill-primary,
  .btn-pill-secondary,
  input[type="text"],
  input[type="password"],
  select {
    min-block-size: 52px;
  }
}

/* Tablet / Desktop progressive enhancement */
@media (min-width: 720px) {
  .app-shell {
    padding: 24px 24px 40px;
  }
  .login-crest-card {
    padding: 34px 36px;
  }
  .panel-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
  }
  .panel-footer-actions .btn {
    flex: initial;
  }
  .suggested-bar {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  .composer-row {
    flex-direction: row;
    align-items: flex-end;
  }
  .field-grow {
    flex: 1 1 auto;
  }
  .composer-actions {
    flex-shrink: 0;
  }
  .composer-actions .btn {
    flex: initial;
  }
  .form-row-2 {
    grid-template-columns: 1fr 1fr;
  }
  .crest-dialog-actions {
    flex-direction: row;
  }
}

@media (min-width: 920px) {
  .workspace {
    grid-template-columns: minmax(0, 1.65fr) minmax(300px, 1fr);
  }
  .messages {
    max-height: 52dvh;
  }
}
