/* F.O.C.O: componentes e layout. Depende de foco-design-tokens.css. */

/* ------------------------------------------------------------------ base */

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-text);
  font-size: var(--fs-14);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
p,
ol,
ul,
dl,
dd,
pre,
figure {
  margin: 0;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: var(--lh-tight);
  color: var(--text);
}

/* Skip link (app shell) */
.app-skip {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 80;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--text-primary);
  color: var(--bg-canvas);
  font-size: var(--fs-13);
  font-weight: 600;
  text-decoration: none;
}
.app-skip:focus {
  top: 12px;
  outline: var(--focus-outline);
  outline-offset: 2px;
}

ul,
ol {
  padding: 0;
}

/* Blocos de texto consecutivos nunca encostam: 8px entre parágrafos, 16px antes de outro bloco. */
p + p {
  margin-top: var(--sp-2);
}

p + .btn-row,
p + .stack-xs,
p + .field,
p + .alert,
p + .callout,
.alert + p,
.callout + p,
ol + p,
ul + p {
  margin-top: var(--sp-4);
}

a {
  color: var(--link);
}

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

:focus-visible {
  outline: var(--focus-outline);
  outline-offset: 2px;
}

.icon {
  flex: none;
  display: inline-block;
  vertical-align: middle;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.95em;
}

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

.small {
  font-size: var(--fs-13);
}

.strong {
  font-weight: 700;
  color: var(--text);
}

.text-right {
  text-align: right;
}

.truncate {
  max-width: 28rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  color: var(--link);
  font-weight: 500;
  text-decoration: none;
}

.link:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.plan-offers {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.plan-offer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 12px;
  row-gap: 4px;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.plan-offer__name { font-weight: 600; }

.plan-offer__price { font-variant-numeric: tabular-nums; white-space: nowrap; }

.plan-offer__text { grid-column: 1 / -1; line-height: 1.45; }

.stack-xs {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-5);
  align-items: start;
}

.layout-aside {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: var(--sp-5);
  align-items: start;
}

/* ------------------------------------------------------------------ shell */

.app {
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr);
  transition: grid-template-columns 0.2s ease;
  grid-template-rows: var(--header-h) auto;
  grid-template-areas:
    "header header"
    "nav main";
  min-height: 100vh;
}

.app--nav-collapsed {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "header"
    "main";
}

.app-header {
  grid-area: header;
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  height: var(--header-h);
  padding: 0 var(--sp-4) 0 var(--sp-2);
  background: var(--header-bg);
  color: var(--header-fg);
  border-bottom: 1px solid var(--border-subtle);
}

.app-header__start,
.app-header__end {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand__accent {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--fs-20);
  letter-spacing: 0.02em;
}

.brand__sep {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.35);
}

.brand__name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-16);
  letter-spacing: 0.08em;
}

.brand__desc {
  font-size: var(--fs-13);
  color: var(--header-fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.icon-btn--inverse {
  width: 40px;
  height: 40px;
  color: var(--header-fg);
}

.icon-btn--inverse:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--header-fg);
}

.icon-btn--inverse:focus-visible {
  outline-color: var(--text-primary);
}

.conn-status {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 40px;
  padding: 0 var(--sp-3);
  color: var(--header-fg);
  text-align: left;
}

.conn-status__text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.conn-status__label {
  font-size: var(--fs-13);
  font-weight: 700;
}

.conn-status__host {
  font-size: var(--fs-12);
  color: var(--header-fg-muted);
}

.status-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-subtle);
}

.status-dot--ok {
  background: #08ce79;
}

.status-dot--off {
  background: #a2a8b1;
}

.status-dot--live {
  background: var(--foco-cyan);
}

.user-menu {
  position: relative;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 40px;
  padding: 0 var(--sp-2) 0 var(--sp-1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  background: transparent;
  color: var(--header-fg);
  font-size: var(--fs-13);
  cursor: pointer;
}

.user-chip:hover,
.user-chip[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.1);
}

.user-chip:focus-visible {
  outline-color: var(--text-primary);
}

.user-menu__panel {
  position: absolute;
  right: 0;
  top: calc(100% + var(--sp-2));
  z-index: 60;
  width: 288px;
  padding: var(--sp-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-2);
  transform-origin: top right;
  animation: foco-menu-in var(--duration-normal) var(--ease-out-quart) both;
}

@keyframes foco-menu-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.user-menu__panel[hidden] {
  display: none;
}

.user-menu__label {
  font-size: var(--fs-12);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.user-menu__value {
  margin-top: var(--sp-1);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.user-menu__value + .user-menu__label {
  margin-top: var(--sp-3);
}

.user-menu__foot {
  margin-top: var(--sp-4);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--divider);
}

.btn--on-dark {
  border-color: var(--border-strong);
}

.user-chip__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  font-weight: 700;
  font-size: var(--fs-12);
}

/* Navegação lateral */

.app-nav {
  grid-area: nav;
  position: sticky;
  top: var(--header-h);
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  height: calc(100vh - var(--header-h));
  padding: var(--sp-5) var(--sp-3) var(--sp-4);
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.nav__section {
  margin: 0 0 var(--sp-2);
  padding: 0 var(--sp-3);
  font-size: var(--fs-12);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nav__list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav__link {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  min-height: 36px;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  color: var(--text-2);
  font-weight: 500;
  text-decoration: none;
}

.nav__link:hover {
  background: var(--surface-3);
  color: var(--text);
}

.nav__link--active {
  background: var(--brand-badge-bg);
  color: var(--foco-navy);
  font-weight: 700;
}

[data-theme="dark"] .nav__link--active {
  color: #ffffff;
}

.nav__link--active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 2px;
  background: var(--foco-blue);
}

.nav__link--disabled {
  color: var(--text-subtle);
  cursor: not-allowed;
}

.nav__link--disabled:hover {
  background: none;
  color: var(--text-subtle);
}

.nav__badge {
  font-size: var(--fs-12);
  font-weight: 500;
  color: var(--info);
}

.nav__version {
  margin-top: auto;
  padding: 0 var(--sp-3);
  font-size: var(--fs-12);
  color: var(--text-subtle);
}

.app-main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#panel {
  flex: 1;
}

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border);
  font-size: var(--fs-12);
  color: var(--text-muted);
}

/* ------------------------------------------------------------------ página */

.page {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-6) var(--sp-8);
}

.page--wide {
  max-width: var(--content-max-wide);
}

.page--report {
  max-width: var(--content-max-wide);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
  font-size: var(--fs-13);
  color: var(--text-muted);
}

.breadcrumb a {
  color: var(--link);
  text-decoration: none;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

.breadcrumb [aria-current] {
  color: var(--text-2);
}

.breadcrumb__sep {
  color: var(--text-subtle);
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}

.page-header__actions {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.page-title {
  font-size: var(--fs-32);
  font-weight: 600;
  color: var(--foco-navy);
  letter-spacing: -0.02em;
}

[data-theme="dark"] .page-title {
  color: var(--text);
}

.page-lead {
  margin-top: var(--sp-2);
  max-width: var(--measure);
  font-size: var(--fs-16);
  color: var(--text-2);
}

.eyebrow {
  margin-bottom: var(--sp-1);
  font-size: var(--fs-12);
  font-weight: 550;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--text-muted);
}

[data-theme="dark"] .eyebrow {
  color: var(--text-muted);
}

@media (prefers-reduced-motion: reduce) {
  .btn:active:not(:disabled) {
    transform: none;
  }
  .user-menu__panel {
    animation: none;
  }
}

/* ------------------------------------------------------------------ card */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: none;
  min-width: 0;
}

.card + .card {
  margin-top: var(--sp-4);
}

/* Superfície contínua: divisores 1px, sem card-dentro-de-card */
.surface-list {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.surface-list > * + * {
  border-top: 1px solid var(--border-subtle);
}

.surface-list__row {
  padding: var(--sp-4);
  transition: background-color var(--duration-fast) var(--ease-out-quart);
}

.surface-list__row:hover {
  background: var(--bg-surface-hover);
}

.card--flush {
  overflow: hidden;
}

.card__head {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--divider);
}

.card__head--row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.card__title {
  font-size: var(--fs-16);
  font-weight: 700;
  color: var(--text);
}

.card__sub {
  font-size: var(--fs-13);
  line-height: var(--lh-prose);
  color: var(--text-muted);
}

.card__body {
  padding: var(--sp-5);
}

.card__foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--divider);
  background: var(--surface-2);
}

.card__foot-spacer {
  flex: 1;
}

/* ------------------------------------------------------------------ botões */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 40px;
  padding: 0 var(--sp-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-text);
  font-size: var(--fs-14);
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color var(--duration-fast) var(--ease-out-quart),
    border-color var(--duration-fast) var(--ease-out-quart),
    color var(--duration-fast) var(--ease-out-quart),
    transform var(--duration-fast) var(--ease-out-quart);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
}

.btn--primary:hover:not(:disabled) {
  background: var(--btn-primary-bg-hover);
}

.btn--secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-fg);
  border-color: var(--btn-secondary-border);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--btn-secondary-bg-hover);
}

.btn--ghost {
  background: transparent;
  color: var(--link);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface-3);
}

.btn--danger {
  background: var(--danger);
  color: #ffffff;
}

[data-theme="dark"] .btn--danger {
  color: #1e2023;
}

.btn--danger:hover:not(:disabled) {
  filter: brightness(0.92);
}

.btn--sm {
  min-height: 32px;
  padding: 0 var(--sp-3);
  font-size: var(--fs-13);
}

.btn--block {
  width: 100%;
}

.btn:focus-visible {
  outline: var(--focus-outline);
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

.btn-row {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

/* ------------------------------------------------------------------ formulários */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  min-width: 0;
}

.field--grow {
  flex: 1;
}

.field__label {
  font-size: var(--fs-13);
  font-weight: 700;
  color: var(--text-2);
}

.field__hint {
  font-size: var(--fs-13);
  line-height: var(--lh-prose);
  color: var(--text-muted);
}

.field__hint + .field__hint {
  margin-top: var(--sp-1);
}

.field__error {
  margin-top: var(--sp-2);
  font-size: var(--fs-13);
  color: var(--danger);
}

.input {
  width: 100%;
  min-height: 40px;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.input::placeholder {
  color: var(--text-subtle);
}

.input:hover:not(:disabled) {
  border-color: var(--text-muted);
}

.input:focus {
  outline: none;
  border-color: var(--foco-blue);
  box-shadow: var(--focus-ring);
}

.input:disabled {
  background: var(--surface-3);
  color: var(--text-muted);
  cursor: not-allowed;
}

.input--mono {
  font-family: var(--font-mono);
  font-size: var(--fs-14);
}

.form-row {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-3);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  font-size: var(--fs-13);
  color: var(--text-2);
  cursor: pointer;
}

.check input,
.action-row input {
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--foco-blue);
  flex: none;
}

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 2px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.seg__btn {
  min-height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-13);
  font-weight: 500;
  cursor: pointer;
}

.seg__btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--foco-navy);
  font-weight: 700;
  box-shadow: var(--shadow-1);
}

[data-theme="dark"] .seg__btn[aria-pressed="true"] {
  color: var(--text);
  background: var(--surface-2);
}
