:root {
  --color-primary: #1a3d6d;
  --color-primary-dark: #122a4d;
  --color-accent: #2f8fd6;
  --color-bg: #f2f4f7;
  --color-surface: #ffffff;
  --color-border: #e2e6ec;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-danger: #d64545;
  --sidebar-width: 220px;
  --topbar-height: 60px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, Segoe UI, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

a { text-decoration: none; color: inherit; }

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-height);
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-left .brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  background: var(--color-accent);
  color: #fff;
  font-weight: 700;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  font-size: 14px;
}
.brand-name { font-weight: 600; font-size: 16px; }
.topbar-version {
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  margin-left: 10px;
  padding: 2px 8px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 10px;
  cursor: default;
}
.topbar-center { flex: 1; display: flex; justify-content: center; }
.topbar-search {
  width: 100%;
  max-width: 420px;
  padding: 9px 14px;
  border-radius: 20px;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
}
.topbar-search::placeholder { color: rgba(255,255,255,0.7); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
}
.icon-btn:hover { background: rgba(255,255,255,0.12); }
.user-menu { display: flex; align-items: center; gap: 8px; margin-left: 8px; }
.user-avatar {
  width: 32px; height: 32px;
  background: var(--color-accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 14px;
}
.user-name { font-size: 14px; font-weight: 500; }
.logout-btn {
  background: transparent; border: none; color: #fff;
  font-size: 16px; cursor: pointer; opacity: 0.85;
}
.logout-btn:hover { opacity: 1; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: calc(100vh - var(--topbar-height)); }

.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 16px 10px;
  flex-shrink: 0;
}
.sidebar-group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  margin: 18px 10px 8px;
  font-weight: 600;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--color-text);
  margin-bottom: 2px;
}
.sidebar-item:hover { background: var(--color-bg); }
.sidebar-item.active { background: #e8f1fb; color: var(--color-primary); font-weight: 600; }
.sidebar-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  margin-top: 20px;
  padding: 10px;
  text-align: center;
  font-size: 11px;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  cursor: default;
}

.app-content { flex: 1; padding: 24px 28px; }

/* ---------- Page header ---------- */
.page-header { margin-bottom: 20px; }
.page-header h1 { margin: 0 0 4px; font-size: 22px; }
.page-subtitle { margin: 0; color: var(--color-text-muted); font-size: 14px; }

/* ---------- Widgets ---------- */
.widget-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}
.widget-wide { grid-column: span 2; }
.widget {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--color-border);
}
.widget-header h2 { margin: 0; font-size: 15px; }
.widget-link { font-size: 13px; color: var(--color-accent); font-weight: 500; }
.widget-body { padding: 18px; }
.widget-empty { color: var(--color-text-muted); font-size: 14px; margin: 0; }

/* ---------- Login ---------- */
.login-body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  font-family: 'Inter', sans-serif;
}
.login-box {
  background: #fff;
  padding: 36px 34px;
  border-radius: 14px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.brand-mark.large { width: 52px; height: 52px; font-size: 18px; margin: 0 auto 12px; }
.login-brand h1 { font-size: 18px; margin: 0 0 4px; color: var(--color-primary); }
.login-brand p { font-size: 13px; color: var(--color-text-muted); margin: 0; }
.login-form { display: flex; flex-direction: column; gap: 6px; }
.login-form label { font-size: 13px; font-weight: 500; margin-top: 10px; }
.login-form input {
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.login-form input:focus { outline: 2px solid var(--color-accent); border-color: transparent; }
.btn-primary {
  margin-top: 18px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: 11px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { background: var(--color-primary-dark); }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 10px; }
.alert-error { background: #fdecec; color: var(--color-danger); }

/* ---------- Errors ---------- */
.error-page { text-align: center; padding: 60px 20px; }
.error-page h1 { font-size: 48px; margin: 0; color: var(--color-primary); }

/* ---------- Formulário em seções (cadastro de usuário, etc.) ---------- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}
.form-section-title {
  grid-column: 1 / -1;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-primary);
  margin: 22px 0 6px;
  padding-top: 18px;
  border-top: 1px solid var(--color-border);
}
.form-section-title.first { border-top: none; padding-top: 0; margin-top: 0; }
.form-grid label {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 500;
  display: block;
}
.form-grid input, .form-grid select {
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
}
.form-grid .full-width { grid-column: 1 / -1; }
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- Chat ---------- */
.chat-shell {
  display: flex;
  height: calc(100vh - var(--topbar-height) - 48px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}
.chat-sidebar { width: 300px; border-right: 1px solid var(--color-border); overflow-y: auto; flex-shrink: 0; display: flex; flex-direction: column; }
.chat-sidebar-section-title { font-size: 11px; text-transform: uppercase; color: var(--color-text-muted); font-weight: 600; padding: 14px 14px 6px; }
.chat-list-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; text-decoration: none; color: inherit; border-bottom: 1px solid var(--color-border); }
.chat-list-item:hover { background: var(--color-bg); }
.chat-list-item.active { background: #e8f1fb; }
.chat-list-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--color-accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.chat-list-info { flex: 1; min-width: 0; }
.chat-list-name { font-size: 14px; font-weight: 600; }
.chat-list-preview { font-size: 12px; color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-unread-badge { background: var(--color-danger); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; flex-shrink: 0; }

.chat-thread { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-thread-header { padding: 14px 18px; border-bottom: 1px solid var(--color-border); font-weight: 600; }
.chat-messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; }
.chat-message { margin-bottom: 12px; max-width: 65%; }
.chat-message.mine { align-self: flex-end; text-align: right; }
.chat-bubble { display: inline-block; padding: 9px 13px; border-radius: 14px; background: var(--color-bg); font-size: 14px; text-align: left; white-space: pre-wrap; word-break: break-word; }
.chat-message.mine .chat-bubble { background: var(--color-primary); color: #fff; }
.chat-message-meta { font-size: 11px; color: var(--color-text-muted); margin-top: 3px; }
.chat-input-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--color-border); }
.chat-input-row input { flex: 1; padding: 10px 14px; border: 1px solid var(--color-border); border-radius: 20px; font-family: inherit; font-size: 14px; }
.chat-input-row button { background: var(--color-primary); color: #fff; border: none; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 16px; }
.chat-empty-state { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--color-text-muted); font-size: 14px; }
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #e2e6ec;
  transition: 0.2s;
  border-radius: 22px;
}
.toggle-slider:before {
  position: absolute;
  content: "";
  height: 16px; width: 16px;
  left: 3px; bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-slider { background-color: var(--color-primary); }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(16px); }

.permission-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
}
.permission-row:last-child { border-bottom: none; }
.permission-row-label { font-size: 14px; }
.helpdesk-tab {
  padding: 8px 14px;
  font-size: 14px;
  color: var(--color-text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.helpdesk-tab:hover { color: var(--color-text); }
.helpdesk-tab.active {
  color: var(--color-primary);
  font-weight: 600;
  border-bottom: 2px solid var(--color-primary);
}

/* ---------- Tables (admin) ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { text-align: left; padding: 12px 18px; border-bottom: 1px solid var(--color-border); }
.data-table th { font-size: 12px; text-transform: uppercase; color: var(--color-text-muted); letter-spacing: 0.03em; }
.data-table tr:last-child td { border-bottom: none; }
.table-link { color: var(--color-accent); font-size: 13px; margin-left: 10px; }
.table-btn { background: none; border: none; cursor: pointer; font-family: inherit; padding: 0; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  background: #eef2f7;
  color: var(--color-primary);
}
.badge-success { background: #e8f7ee; color: #1c7a3d; }
.badge-muted { background: #f0f1f3; color: var(--color-text-muted); }

.data-table select, .data-table input { font-family: inherit; }
select {
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
