:root {
  --bg: #eef2f5;
  --panel: #fff;
  --ink: #17212b;
  --muted: #5e6b78;
  --line: #d8e0e8;
  --primary: #1769aa;
  --primary-2: #0f4f82;
  --green: #1f8a5b;
  --amber: #a46405;
  --red: #b62929;
  --teal: #117a8b;
  --shadow: 0 8px 24px rgba(22, 35, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  min-height: 76px;
  padding: 14px 22px;
  background: #17212b;
  color: #fff;
  border-bottom: 4px solid #2d9cdb;
}

.topbar h1,
.topbar p,
h2,
p {
  margin: 0;
}

.topbar h1 {
  font-size: 24px;
}

.role-label {
  margin-top: 4px;
  color: #c5d0db;
  font-size: 14px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.layout {
  padding: 18px;
}

.admin-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.admin-page .topbar {
  flex-wrap: nowrap;
  gap: 12px;
  min-height: 64px;
  padding-top: 8px;
  padding-bottom: 8px;
}

.admin-page .topbar > div:first-child {
  flex: 0 0 auto;
  min-width: 250px;
}

.admin-page .layout {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(420px, 1fr) minmax(260px, 340px);
  gap: 18px;
  height: calc(100vh - 76px);
  align-items: stretch;
}

.admin-page .admin-grid {
  height: 100%;
}

.admin-sidebar {
  display: grid;
  gap: 18px;
}

.admin-left-panel {
  gap: 14px;
}

.admin-left-panel .list-header {
  flex: 0 0 auto;
  margin-bottom: 0;
}

.admin-left-panel .user-list {
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.admin-tools {
  display: grid;
  flex: 0 0 auto;
  gap: 10px;
}

.tool-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.tool-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 800;
}

.tool-panel summary small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: right;
}

.tool-panel form {
  max-height: min(44vh, 390px);
  overflow-y: auto;
  padding: 0 12px 12px;
  scrollbar-gutter: stable;
}

.top-storage {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  flex: 0 1 360px;
  width: min(360px, 28vw);
  margin: 0;
  gap: 4px 8px;
  padding: 6px 8px;
  color: var(--ink);
  background: #f8fafc;
  box-shadow: none;
}

.top-storage strong {
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
}

.top-storage .progress {
  grid-column: 1 / 3;
  height: 6px;
}

.top-storage .muted {
  font-size: 12px;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-storage .button {
  grid-column: 3;
  grid-row: 1 / 3;
  min-height: 26px;
  padding: 3px 8px;
  font-size: 12px;
  white-space: nowrap;
}

.admin-page .top-actions .button {
  min-height: 34px;
  padding: 6px 10px;
}

.normal-grid {
  display: grid;
  grid-template-columns: minmax(220px, 290px) minmax(560px, 1fr) minmax(220px, 290px);
  gap: 18px;
  height: calc(100vh - 76px);
  align-items: stretch;
}

.normal-grid.viewer-open {
  grid-template-columns: minmax(220px, 290px) minmax(560px, 1fr) minmax(220px, 290px);
}

.panel,
.task-card,
.viewer {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.panel-header,
.viewer-header,
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.list-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.list-panel.admin-left-panel {
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 12px;
  scrollbar-gutter: stable;
}

.list-panel.admin-left-panel .user-list {
  flex: 0 0 auto;
  overflow: visible;
  padding-right: 0;
}

.task-list {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.task-list > .task-card {
  flex: 0 0 auto;
}

.login-wrap {
  min-height: calc(100vh - 76px);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(420px, 100%);
}

form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #b9c5d0;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px;
}

textarea {
  min-height: 100px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 700;
  text-decoration: none;
}

.button.compact {
  min-height: 30px;
  padding: 4px 9px;
  font-size: 13px;
}

.primary {
  background: var(--primary);
  color: #fff;
}

.primary:hover {
  background: var(--primary-2);
}

.secondary {
  background: #fff;
  border-color: #b9c5d0;
  color: #24313d;
}

.success {
  background: var(--green);
  color: #fff;
}

.warning {
  background: var(--amber);
  color: #fff;
}

.danger {
  background: var(--red);
  color: #fff;
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.task-card {
  border-left: 5px solid var(--primary);
  padding: 14px;
}

.task-card.compact {
  cursor: pointer;
  padding: 10px;
}

.task-card.compact:focus-visible {
  outline: 3px solid rgba(23, 105, 170, 0.35);
  outline-offset: 2px;
}

.task-card.compact h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

.task-card.compact .meta {
  margin-bottom: 6px;
}

.task-card.compact .message {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.task-card.compact.selected {
  background: #edf7ff;
  border-color: #9dccf0;
}

.board-task .meta {
  gap: 6px;
  font-size: 12px;
}

.board-task .badge {
  min-height: 22px;
  padding: 2px 8px;
  font-size: 11px;
}

.board-task .compact-actions {
  gap: 6px;
}

.board-task .compact-actions .button {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 13px;
}

.task-card.expanded h2 {
  font-size: 26px;
}

.task-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.compact-actions {
  margin-top: 10px;
}

.priority-Baixa {
  border-left-color: var(--teal);
}

.priority-Alta {
  border-left-color: var(--amber);
}

.priority-Urgente {
  border-left-color: var(--red);
}

.task-card.status-call-admin {
  border-left-color: var(--red);
  background: #fff5f5;
  animation: callAdminPulse 1s ease-in-out infinite;
}

.task-card.status-call-admin .badge {
  background: #fee2e2;
  color: #991b1b;
}

@keyframes callAdminPulse {
  0%,
  100% {
    box-shadow: var(--shadow), 0 0 0 0 rgba(196, 38, 38, 0);
  }

  50% {
    box-shadow: var(--shadow), 0 0 0 5px rgba(196, 38, 38, 0.24);
  }
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 10px;
  background: #e8eef4;
  color: #24313d;
  font-size: 12px;
  font-weight: 700;
}

.message,
.response {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.message {
  font-size: 16px;
}

.response {
  margin-top: 10px;
  color: var(--muted);
}

.message-thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
  max-height: 320px;
  min-height: 96px;
  overflow-y: auto;
  scrollbar-gutter: stable;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafc;
  padding: 12px;
}

.workspace-task {
  box-shadow: none;
}

.workspace-empty {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 240px;
  border: 1px dashed #c9d5df;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.workspace-empty strong {
  color: var(--ink);
  font-size: 22px;
}

.workspace-files {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.file-open-row {
  width: 100%;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.file-preview {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.file-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.file-preview iframe,
.file-preview img {
  width: 100%;
  min-height: 48vh;
  border: 0;
  border-radius: 6px;
  background: #f3f5f7;
}

.file-preview img {
  min-height: auto;
  height: auto;
}

.message-jump {
  position: sticky;
  bottom: 0;
  z-index: 2;
  align-self: flex-end;
  width: 38px;
  min-height: 34px;
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.18);
  font-size: 18px;
  line-height: 1;
}

.message-thread > strong {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.chat-line {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: min(76%, 560px);
  border: 1px solid var(--line);
  border-radius: 16px 16px 16px 4px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  padding: 10px 12px;
}

.chat-line.mine {
  align-self: flex-end;
  border-color: #c5e8bd;
  border-radius: 16px 16px 4px 16px;
  background: #e9f8e4;
}

.chat-line p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-line .muted {
  font-size: 12px;
}

.chat-line.mine .muted {
  text-align: right;
}

.message-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 2px;
}

.compact {
  min-height: 30px;
  padding: 4px 10px;
  font-size: 13px;
}

.task-reply {
  margin-top: 12px;
  min-height: 76px;
}

.actions,
.file-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.file-row {
  align-items: center;
  justify-content: space-between;
  background: #f5f8fb;
  border: 1px solid #dfe7ef;
  border-radius: 8px;
  padding: 10px;
}

.file-name {
  font-weight: 650;
  overflow-wrap: anywhere;
}

.viewer {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.viewer-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  margin: 0;
}

.viewer-body {
  flex: 1;
  overflow: auto;
  padding: 14px;
  background: #f7f9fb;
}

.viewer-body iframe,
.viewer-body img {
  width: 100%;
  min-height: 70vh;
  border: 0;
  background: #fff;
}

.viewer-body img {
  height: auto;
  min-height: auto;
}

.viewer-body pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.csv-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

.csv-table td,
.csv-table th {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: left;
}

.storage-box {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.user-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.user-item {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}

.user-item.selectable {
  cursor: pointer;
}

.user-item.selected {
  border-color: var(--primary);
  box-shadow: inset 4px 0 0 var(--primary);
}

.user-item-header,
.user-list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.user-item-main {
  display: grid;
  gap: 4px;
}

.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.user-edit-form {
  display: grid;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.user-edit-actions {
  display: flex;
  gap: 8px;
}

.selection-note {
  margin: -8px 0 10px;
  font-size: 13px;
}

.success-note {
  color: var(--green);
  font-weight: 650;
}

.progress {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe7ef;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--primary);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  border-radius: 8px;
  background: #17212b;
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.error {
  color: var(--red);
  font-weight: 650;
}

.muted {
  color: var(--muted);
}

@media (max-width: 980px) {
  .admin-grid,
  .normal-grid {
    grid-template-columns: 1fr;
    height: auto;
  }

  .top-storage {
    order: 3;
    width: 100%;
  }

  .viewer {
    min-height: 70vh;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }
}

@media print {
  body.print-file-only {
    background: #fff;
  }

  body.print-file-only .topbar,
  body.print-file-only .login-wrap,
  body.print-file-only .list-panel,
  body.print-file-only .viewer-header,
  body.print-file-only .toast {
    display: none !important;
  }

  body.print-file-only .layout,
  body.print-file-only .normal-grid,
  body.print-file-only .viewer,
  body.print-file-only .viewer-body {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    border: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
  }

  body.print-file-only .workspace-task,
  body.print-file-only .file-preview-header {
    display: none !important;
  }

  body.print-file-only .file-preview {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: #fff !important;
  }

  body.print-file-only .viewer-body iframe {
    display: block;
    width: 100% !important;
    height: 100vh !important;
    min-height: 100vh !important;
    border: 0 !important;
  }

  body.print-file-only .viewer-body img {
    display: block;
    width: auto !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 auto !important;
  }

  body.print-file-only .viewer-body pre,
  body.print-file-only .viewer-body table {
    width: 100% !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
}
