@import url('https://fonts.googleapis.com/css2?family=Sora:wght@400;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --c-bg: #F1F5F9;
  --c-surface: #FFFFFF;
  --c-border: #E2E8F0;
  --c-border-light: #F1F5F9;
  --c-text: #334155;
  --c-text-secondary: #64748B;
  --c-heading: #0F172A;
  --c-accent: #B91C1C;
  --c-accent-hover: #991B1B;
  --c-accent-subtle: #FEF2F2;
  --c-link: #0891B2;
  --c-link-hover: #0E7490;
  --c-success: #059669;
  --c-success-bg: #ECFDF5;
  --c-warning: #D97706;
  --c-warning-bg: #FFFBEB;
  --c-danger: #DC2626;
  --c-danger-bg: #FEF2F2;
  --c-header-bg: #0F172A;
  --c-header-text: #E2E8F0;
  --c-header-accent: #B91C1C;
  --ff-display: 'Sora', system-ui, sans-serif;
  --ff-body: 'Inter', system-ui, sans-serif;
  --ff-mono: 'JetBrains Mono', monospace;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.04);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

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

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--ff-body);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
  min-height: 100vh;
}

/* ─── Header ─── */

.header {
  position: sticky; top: 0; z-index: 100;
  background: var(--c-header-bg);
  border-top: 3px solid var(--c-header-accent);
  box-shadow: var(--shadow-md);
}

.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem;
  height: 52px;
  max-width: 1440px; margin: 0 auto;
}

.header-brand {
  display: flex; align-items: center; gap: 0.625rem;
  font-family: var(--ff-display);
  font-weight: 700;
  font-size: 1.0625rem;
  color: #fff;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.header-brand-accent {
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--c-header-accent);
  border-radius: 50%;
}

.header-nav {
  display: flex; align-items: center; gap: 0.25rem;
}

.header-nav a {
  color: var(--c-header-text);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.header-nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.header-nav a.active { background: rgba(255,255,255,0.12); color: #fff; }

.header-user {
  display: flex; align-items: center; gap: 0.75rem;
}

.header-user-name {
  color: #94A3B8;
  font-size: 0.8125rem;
}

.header-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--c-header-text);
  padding: 0.3rem 0.625rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-family: var(--ff-body);
  cursor: pointer;
  transition: all 0.15s;
}

.header-btn:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.3); }

/* ─── Layout ─── */

.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.5rem;
}

.page-title {
  font-family: var(--ff-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--c-heading);
  margin-bottom: 1.25rem;
  letter-spacing: -0.02em;
}

/* ─── KPI Cards ─── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--c-surface);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--c-border);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--c-accent);
  opacity: 0.3;
}

.kpi-card.is-primary::before { opacity: 1; }
.kpi-card.is-warning::before { background: var(--c-warning); opacity: 1; }
.kpi-card.is-success::before { background: var(--c-success); opacity: 1; }

.kpi-number {
  font-family: var(--ff-mono);
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--c-heading);
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.kpi-label {
  font-size: 0.8125rem;
  color: var(--c-text-secondary);
  margin-top: 0.25rem;
  font-weight: 500;
}

/* ─── Toolbar ─── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex; align-items: center; gap: 0.375rem;
}

.toolbar-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--c-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.toolbar input,
.toolbar select {
  font-family: var(--ff-body);
  font-size: 0.8125rem;
  padding: 0.4375rem 0.75rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.toolbar input:focus,
.toolbar select:focus {
  border-color: var(--c-link);
  box-shadow: 0 0 0 3px rgba(8,145,178,0.12);
}

.toolbar input { min-width: 200px; }

.toolbar-spacer { flex: 1; }

.toolbar-count {
  font-size: 0.8125rem;
  color: var(--c-text-secondary);
  font-weight: 500;
}

.toolbar-count strong { color: var(--c-heading); font-weight: 600; }

/* ─── Buttons ─── */

.btn {
  display: inline-flex; align-items: center; gap: 0.375rem;
  font-family: var(--ff-body);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--c-accent);
  color: #fff;
}
.btn-primary:hover { background: var(--c-accent-hover); }

.btn-ghost {
  background: transparent;
  color: var(--c-text);
  border: 1px solid var(--c-border);
}
.btn-ghost:hover { background: var(--c-bg); border-color: #CBD5E1; }

.btn-outline { background: transparent; border: 1px solid var(--c-accent); color: var(--c-accent); }
.btn-outline:hover { background: var(--c-accent); color: #fff; }

.btn-link {
  background: transparent;
  color: var(--c-link);
  padding: 0.25rem 0.5rem;
}
.btn-link:hover { background: rgba(8,145,178,0.08); }

.btn-sm { padding: 0.3125rem 0.625rem; font-size: 0.75rem; }
.btn-sm.btn-outline { padding: 0.3125rem 0.625rem; font-size: 0.75rem; background: transparent; border: 1px solid var(--c-accent); color: var(--c-accent); }
.btn-sm.btn-outline:hover { background: var(--c-accent); color: #fff; }
.btn-xs { padding: 0.1875rem 0.4375rem; font-size: 0.6875rem; border-radius: 4px; }

.btn-danger { background: var(--c-danger); color: #fff; }
.btn-danger:hover { background: #B91C1C; }

.btn-outline-danger {
  background: transparent;
  border: 1px solid var(--c-danger);
  color: var(--c-danger);
}
.btn-outline-danger:hover { background: var(--c-danger-bg); }

/* ─── Table ─── */

.table-wrap {
  background: var(--c-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--c-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  text-align: left;
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-border);
  position: sticky; top: 0;
  white-space: nowrap;
}

tbody td {
  padding: 0.6875rem 1rem;
  border-bottom: 1px solid var(--c-border-light);
  font-size: 0.8125rem;
  vertical-align: middle;
}

tbody tr:hover { background: #F8FAFC; }
tbody tr:last-child td { border-bottom: none; }

/* ─── Status Badge ─── */

.status-badge {
  display: inline-flex; align-items: center; gap: 0.375rem;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.1875rem 0.5rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-badge::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
}

.status-ativo {
  background: var(--c-success-bg);
  color: var(--c-success);
}
.status-ativo::before { background: var(--c-success); }

.status-encerrado {
  background: var(--c-bg);
  color: var(--c-text-secondary);
}
.status-encerrado::before { background: var(--c-text-secondary); }

.status-suspenso, .status-rescindido {
  background: var(--c-danger-bg);
  color: var(--c-danger);
}
.status-suspenso::before, .status-rescindido::before { background: var(--c-danger); }

/* ─── Contract Link ─── */

.contract-link {
  font-family: var(--ff-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--c-heading);
  text-decoration: none;
  transition: color 0.15s;
}

.contract-link:hover { color: var(--c-accent); }

/* ─── Value Display ─── */

.value-mono {
  font-family: var(--ff-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--c-heading);
  white-space: nowrap;
}

/* ─── Pagination ─── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--c-border-light);
}

.pagination button {
  font-family: var(--ff-body);
  font-size: 0.8125rem;
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-text);
  cursor: pointer;
  transition: all 0.15s;
}

.pagination button:hover { background: var(--c-bg); border-color: #CBD5E1; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

.pagination-info {
  font-size: 0.8125rem;
  color: var(--c-text-secondary);
  margin: 0 0.5rem;
}

/* ─── Modal ─── */

.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.5);
  backdrop-filter: blur(2px);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-bg.show { display: flex; }

.modal {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  width: 90%;
  max-width: 680px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  animation: modalIn 0.2s ease-out;
}

.modal-section {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--c-border-light);
}

.modal-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.modal-section h4 {
  font-family: var(--ff-display);
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--c-heading);
  margin-bottom: 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--c-border);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal h3 {
  font-family: var(--ff-display);
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--c-heading);
  margin-bottom: 1rem;
}

.modal label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--c-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0.5rem 0 0.2rem;
}

.modal select {
  width: 100%;
  font-family: var(--ff-body);
  font-size: 0.8125rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  color: var(--c-text);
  outline: none;
  transition: border-color 0.15s;
}

.modal select:focus {
  border-color: var(--c-link);
  box-shadow: 0 0 0 3px rgba(8,145,178,0.12);
}

.modal input, .modal select, .modal textarea {
  width: 100%;
  font-family: var(--ff-body);
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  color: var(--c-text);
  outline: none;
  transition: border-color 0.15s;
}

.modal input:focus, .modal select:focus, .modal textarea:focus {
  border-color: var(--c-link);
  box-shadow: 0 0 0 3px rgba(8,145,178,0.12);
}

.modal .btn-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
  justify-content: flex-end;
}

/* ─── Toast ─── */

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 500;
  z-index: 2000;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease-out;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast-info { background: var(--c-heading); }
.toast-success { background: var(--c-success); }
.toast-error { background: var(--c-danger); }

/* ─── Detail Page ─── */

.detail-header {
  background: var(--c-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--c-border);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
}

.detail-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.detail-number {
  font-family: var(--ff-mono);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--c-heading);
  letter-spacing: -0.03em;
}

.detail-number-prefix {
  font-family: var(--ff-display);
  font-weight: 400;
  color: var(--c-accent);
  font-size: 0.875rem;
  margin-right: 0.375rem;
}

.detail-fornecedor {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--c-heading);
  margin: 0.25rem 0 0.5rem;
}

.detail-objeto {
  font-size: 0.8125rem;
  color: var(--c-text-secondary);
  line-height: 1.6;
  max-width: 720px;
}

.detail-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--c-border-light);
}

.detail-meta-item {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.detail-meta-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--c-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-meta-value {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--c-heading);
}

.detail-meta-value.mono { font-family: var(--ff-mono); }

/* ─── Tabs ─── */

.tabs {
  display: flex;
  gap: 0.125rem;
  margin-bottom: 1rem;
  background: var(--c-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--c-border);
  padding: 0.25rem;
  box-shadow: var(--shadow-sm);
}

.tab {
  font-family: var(--ff-body);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border: none;
  background: transparent;
  color: var(--c-text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.tab:hover { color: var(--c-heading); background: var(--c-bg); }
.tab.active { color: var(--c-heading); background: var(--c-bg); font-weight: 600; }

.tab-count {
  display: inline-flex;
  align-items: center; justify-content: center;
  min-width: 18px; height: 18px;
  background: var(--c-bg);
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--c-text-secondary);
  margin-left: 0.375rem;
  padding: 0 0.3125rem;
}

.tab.active .tab-count { background: var(--c-border); }

/* ─── Tab Content ─── */

.tab-content {
  background: var(--c-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.tab-content .table-wrap { border: none; box-shadow: none; border-radius: 0; }

.tab-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--c-border-light);
}

.tab-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--c-heading);
}

.empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--c-text-secondary);
  font-size: 0.875rem;
}

/* ─── Back Link ─── */

.back-link {
  display: inline-flex; align-items: center; gap: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--c-text-secondary);
  text-decoration: none;
  margin-bottom: 1rem;
  transition: color 0.15s;
}

.back-link:hover { color: var(--c-heading); }

/* ─── Login ─── */

.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: var(--c-header-bg);
}

.login-card {
  background: var(--c-surface);
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  border-top: 3px solid var(--c-accent);
}

.login-card h2 {
  font-family: var(--ff-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--c-heading);
}

.login-card p {
  color: var(--c-text-secondary);
  margin: 0.5rem 0 1.5rem;
  font-size: 0.875rem;
}

.login-card a {
  color: var(--c-link);
  text-decoration: none;
  font-weight: 500;
}

.login-card a:hover { text-decoration: underline; }

/* ─── Editable Indicator ─── */

.edit-badge {
  display: inline-flex; align-items: center; gap: 0.375rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--c-link);
  background: rgba(8,145,178,0.08);
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  letter-spacing: 0.02em;
}

/* ─── Responsive ─── */

@media (max-width: 768px) {
  .header-inner { padding: 0 1rem; }
  .page { padding: 1rem; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
  .kpi-card { padding: 1rem; }
  .kpi-number { font-size: 1.375rem; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar input { min-width: 0; }
  .toolbar-group { flex-wrap: wrap; }
  .detail-header-top { flex-direction: column; }
  .detail-number { font-size: 1.25rem; }
  .detail-meta { grid-template-columns: repeat(2, 1fr); }
  .tabs { overflow-x: auto; }
  .header-nav a { padding: 0.375rem 0.5rem; font-size: 0.75rem; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .table-wrap { border-radius: 0; margin: 0 -1rem; border-left: none; border-right: none; }
}

/* ─── Hub-specific ─── */

.sis-bloco {
  display: flex; align-items: center; gap: 0.75rem;
  margin: 0.5rem 0; padding: 0.625rem 0.75rem;
  background: var(--c-bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--c-border);
}
.sis-bloco label { margin: 0; cursor: pointer; font-size: 0.8125rem; }
.sis-bloco select { width: auto; min-width: 130px; }

.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 4px;
  font-size: 0.6875rem;
  font-weight: 600;
  margin-right: 0.25rem;
}
.badge-obz { background: #DBEAFE; color: #1E40AF; }
.badge-contratos { background: #DCFCE7; color: #166534; }
.badge-observador { background: #F1F5F9; color: #64748B; }
.badge-admin { background: #FEF3C7; color: #92400E; }

/* ─── System Cards (Hub landing) ─── */

.sys-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.sys-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
  border-top: 3px solid var(--c-border);
}

.sys-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.sys-card h3 {
  font-family: var(--ff-display);
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--c-heading);
  margin-bottom: 0.25rem;
}

.sys-card p {
  font-size: 0.8125rem;
  color: var(--c-text-secondary);
}

.sys-card.is-obz { border-top-color: #0891B2; }
.sys-card.is-contratos { border-top-color: var(--c-accent); }
.sys-card.is-dashboard { border-top-color: #D97706; }
/* Data da última atualização no cabeçalho */
.header-atualizacao { font-size: 0.75rem; color: #CBD5E1; margin-right: 0.75rem; white-space: nowrap; }
@media (max-width: 760px) { .header-atualizacao { display: none; } }
