:root {
  --primary: #0a3d62;
  --primary-hover: #07517f;
  --accent: #1687a7;
  --background: #f4f7fa;
  --surface: #ffffff;
  --text: #1d2a35;
  --muted: #667786;
  --border: #dce5eb;
  --danger: #a83232;
  --success: #277649;
  --shadow: 0 12px 35px rgba(10, 61, 98, 0.08);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

.topbar {
  min-height: 68px;
  padding: 0 max(24px, calc((100% - 1120px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: #fff;
  background: var(--primary);
  box-shadow: 0 3px 14px rgba(10, 61, 98, 0.18);
}

.brand { color: #fff; font-size: 21px; font-weight: 800; letter-spacing: -0.02em; }
.brand:hover, .topbar nav a:hover { color: #cfeaf2; }
.topbar nav { display: flex; align-items: center; gap: 22px; }
.topbar nav a, .link-button { color: #fff; }
.topbar form { margin: 0; }
.link-button { padding: 0; border: 0; background: none; font: inherit; cursor: pointer; }

.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 40px 24px 64px; }
.context-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 42px;
  padding: 8px max(24px, calc((100% - 1120px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  color: #10384e;
  background: #d9eef4;
  border-bottom: 1px solid #b9dce6;
}
.context-bar a { font-weight: 750; text-decoration: underline; }

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.025em; }
h1 { margin: 0 0 6px; font-size: clamp(28px, 4vw, 36px); }
h2 { margin: 30px 0 15px; font-size: 22px; }
p { margin: 8px 0 18px; }
.muted { color: var(--muted); }

.panel, .stat {
  padding: 25px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.page-heading {
  margin-bottom: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.login-wrap { min-height: calc(100vh - 104px); display: grid; place-items: center; }
.login-card { width: min(430px, 100%); padding: 38px; }
.login-card h1 { margin-top: 22px; }
.logo-mark {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  font-size: 20px;
  font-weight: 800;
}

label { display: block; margin: 17px 0; font-size: 14px; font-weight: 700; }

input, select {
  width: 100%;
  margin-top: 7px;
  padding: 12px 13px;
  border: 1px solid #bdcbd5;
  border-radius: 9px;
  outline: none;
  background: #fff;
  color: var(--text);
  font: inherit;
  transition: border-color .18s, box-shadow .18s;
}

input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 135, 167, 0.14);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 19px;
  border: 0;
  border-radius: 9px;
  color: #fff;
  background: var(--primary);
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  transition: transform .15s, background .15s, box-shadow .15s;
}

.button:hover {
  transform: translateY(-1px);
  color: #fff;
  background: var(--primary-hover);
  box-shadow: 0 7px 18px rgba(10, 61, 98, .18);
}

.button.secondary { color: var(--primary); background: #e8f0f5; }
.button.secondary:hover { color: var(--primary); background: #dce9f0; }
.button.full { width: 100%; margin-top: 7px; }

.module-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.client-context-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.context-client-card { display: flex; min-height: 210px; flex-direction: column; }
.context-client-card h2 { margin: 20px 0 4px; }
.context-client-card p { flex: 1; }
.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 5px;
  border-radius: 50%;
  background: #2e9c63;
}
.status-dot.inactive { background: #aeb8be; }
.status-label { color: var(--muted); font-size: 12px; }
.module-card { display: flex; min-height: 230px; flex-direction: column; transition: transform .18s, box-shadow .18s; }
.module-card:hover { transform: translateY(-3px); box-shadow: 0 17px 38px rgba(10, 61, 98, .13); }
.module-card h2 { margin: 17px 0 7px; }
.module-card p { flex: 1; color: var(--muted); }
.module-card .button { align-self: flex-start; }
.module-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--primary);
  background: #dff0f5;
  font-size: 24px;
}

.upload-card { display: flex; align-items: end; gap: 20px; }
.upload-card label { flex: 1; }
.upload-card small { padding-bottom: 12px; color: var(--muted); }
.button:disabled { opacity: .68; cursor: wait; transform: none; box-shadow: none; }
.processing-panel {
  margin-top: 16px;
  padding: 18px 20px;
  border: 1px solid #c8dce7;
  border-radius: 10px;
  background: #eef6fa;
}
.processing-panel[hidden] { display: none; }
.processing-panel p { margin: 11px 0 0; color: #35596d; }
.indeterminate-progress {
  position: relative;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #c9dce6;
}
.indeterminate-progress span {
  position: absolute;
  inset: 0 auto 0 -40%;
  width: 40%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  animation: loading-slide 1.15s ease-in-out infinite;
}
@keyframes loading-slide {
  0% { left: -40%; }
  100% { left: 100%; }
}

.stats-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; }
.stat { padding: 18px; box-shadow: 0 5px 18px rgba(10, 61, 98, .05); }
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat strong { font-size: 23px; }
.stat.warning { border-top: 4px solid #e3a21a; }
.stat.danger { border-top: 4px solid var(--danger); }

.alert { margin-bottom: 20px; padding: 14px 17px; border-radius: 9px; }
.alert-error { color: #852626; background: #fae5e5; }
.alert-success { color: #21613d; background: #e2f3e8; }

.table-wrap { overflow-x: auto; }
.table-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.heading-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.result-stats { margin-bottom: 24px; }
.grid-panel { padding: 0; overflow: hidden; }
.grid-toolbar { padding: 18px 18px 0; border-bottom: 1px solid var(--border); }
.tabs { display: flex; gap: 5px; overflow-x: auto; }
.tab {
  padding: 11px 14px;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab span { font-size: 12px; font-weight: 500; }
.grid-actions {
  padding: 15px 0;
  display: flex;
  justify-content: space-between;
  gap: 14px;
}
.grid-actions input { max-width: 420px; margin: 0; }
.grid-status { padding: 9px 18px; color: var(--muted); background: #f9fbfc; font-size: 13px; }
.grid-status.error { color: var(--danger); }
.resultados-grid { width: 100%; height: 650px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.badge { padding: 4px 9px; border-radius: 999px; background: #edf0f2; }
.badge.sucesso { color: var(--success); background: #dff2e6; }
.badge.erro { color: var(--danger); background: #f8dddd; }

.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.admin-grid h2 { margin-top: 0; }
.client-row {
  margin-bottom: 15px;
  display: grid;
  grid-template-columns: 1.2fr 1fr auto;
  align-items: end;
  gap: 24px;
}
.check { font-weight: 400; }
.check input { display: inline; width: auto; margin-right: 7px; }
.empty { padding: 44px; text-align: center; }

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .module-grid, .client-context-grid { grid-template-columns: repeat(2, 1fr); }
  .client-row { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .container { padding: 28px 16px 50px; }
  .topbar { padding: 0 16px; }
  .topbar nav { gap: 12px; font-size: 13px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .module-grid, .admin-grid, .client-context-grid { grid-template-columns: 1fr; }
  .upload-card { display: block; }
  .grid-actions { align-items: stretch; flex-direction: column; }
  .grid-actions input { max-width: none; }
  .resultados-grid { height: 560px; }
  .login-card { padding: 28px 23px; }
}
