/*
 * Fundação visual do application shell (Issue #24).
 * Tokens e fontes são escolha de implementação deste incremento.
 * Não são decisão canônica de produto: não há ADR que os fixe.
 */

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/fraunces-latin-600-normal.woff2") format("woff2");
}

:root {
  --bg: #f4f6f8;
  --fg: #1c2433;
  --muted: #5c6678;
  --accent: #243656;
  --accent-contrast: #f7f8fa;
  --border: #e1e5eb;
  --card: #ffffff;
  --radius: 0.5rem;
  --shadow: 0 1px 2px rgb(28 36 51 / 0.06);
  --sidebar: #1b2744;
  --sidebar-fg: #e8edf5;
  --sidebar-muted: #a7b0c2;
  --sidebar-accent: #2c3d62;
  --sidebar-border: #31466f;
  --success: #1f7a4d;
  --success-bg: #eef7f2;
  --warning: #8a5b10;
  --warning-bg: #fbf6ea;
  --danger: #9b2c2c;
  --danger-bg: #fdf2f2;
  --info: #1e4d7b;
  --info-bg: #f1f6fb;
  --ring: #3d5a8a;
  --font-sans: "IBM Plex Sans", "Segoe UI", sans-serif;
  --font-display: "Fraunces", "Iowan Old Style", Palatino, serif;
  --sidebar-width: 16.5rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

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

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

.skip-link {
  position: absolute;
  left: var(--space-2);
  top: -3rem;
  z-index: 50;
  padding: var(--space-2) var(--space-3);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.skip-link:focus {
  top: var(--space-2);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  min-height: 100vh;
}

.shell-sidebar {
  position: fixed;
  z-index: 40;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  background: var(--sidebar);
  color: var(--sidebar-fg);
  transform: translateX(-105%);
  transition: transform 160ms ease;
}

.app-shell.is-nav-open .shell-sidebar {
  transform: none;
}

.shell-sidebar :focus-visible {
  outline: 2px solid #f4f6f8;
  outline-offset: 2px;
}

.shell-backdrop {
  display: none;
  position: fixed;
  z-index: 30;
  inset: 0;
  background: rgb(16 24 40 / 0.45);
}

.app-shell.is-nav-open .shell-backdrop {
  display: block;
}

.shell-brand {
  display: block;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--sidebar-border);
  color: var(--sidebar-fg);
  text-decoration: none;
}

.shell-brand-mark {
  display: block;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.shell-brand-sub {
  display: block;
  margin-top: 0.35rem;
  color: var(--sidebar-muted);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.shell-nav {
  flex: 1;
  overflow: auto;
  padding: var(--space-4) var(--space-3);
}

.shell-nav-label {
  margin: 0.85rem 0.5rem 0.35rem;
  color: var(--sidebar-muted);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.shell-nav-label:first-child {
  margin-top: 0;
}

.shell-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.shell-nav-link {
  display: block;
  margin: 0.1rem 0;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius);
  color: var(--sidebar-muted);
  font-size: 0.95rem;
  text-decoration: none;
}

.shell-nav-link:hover {
  background: rgb(44 61 98 / 0.65);
  color: var(--sidebar-fg);
}

.shell-nav-link[aria-current="page"] {
  background: var(--sidebar-accent);
  color: var(--sidebar-fg);
  font-weight: 500;
}

.shell-new-intake {
  margin: 0.75rem 0.15rem 0;
}

.shell-new-intake button {
  width: 100%;
  justify-content: flex-start;
  background: transparent;
  color: var(--sidebar-fg);
  border: 1px solid var(--sidebar-border);
  font-size: 0.92rem;
}

.shell-new-intake button:hover {
  background: var(--sidebar-accent);
}

.shell-user {
  padding: var(--space-4);
  border-top: 1px solid var(--sidebar-border);
}

.shell-user-label {
  margin: 0;
  color: var(--sidebar-muted);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.shell-user-email {
  margin: 0.25rem 0 0.75rem;
  overflow: hidden;
  color: var(--sidebar-fg);
  font-size: 0.85rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shell-logout {
  margin: 0;
}

.shell-logout button {
  width: 100%;
  background: transparent;
  color: var(--sidebar-muted);
  border: 1px solid var(--sidebar-border);
  font-size: 0.85rem;
}

.shell-logout button:hover {
  background: var(--sidebar-accent);
  color: var(--sidebar-fg);
}

.shell-content {
  min-width: 0;
  min-height: 100vh;
}

.shell-topbar {
  --shell-topbar-height: 3.25rem;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--shell-topbar-height);
  padding: 0 var(--space-4);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 50;
}

.shell-menu-button {
  display: inline-flex;
  align-items: center;
  width: auto;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
}

.shell-topbar-brand {
  color: var(--fg);
  font-family: var(--font-display);
  font-size: 1.05rem;
  text-decoration: none;
}

.site-main {
  width: 100%;
  margin: 0;
  padding: var(--space-5) var(--space-4) var(--space-6);
}

body.has-shell .site-main {
  max-width: 70rem;
}

body.is-guest {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #eef2f6 0%, var(--bg) 12rem);
}

body.is-guest .site-main {
  width: 100%;
  max-width: 32rem;
  margin: auto;
  padding: var(--space-5) var(--space-4);
}

.auth-panel,
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow);
}

.auth-panel {
  padding: var(--space-6) var(--space-5);
}

.auth-panel h1,
.home-panel h1 {
  margin: 0 0 var(--space-3);
  font-size: 2rem;
}

.auth-panel p,
.home-user,
.home-lead,
.muted,
.empty-state {
  color: var(--muted);
  line-height: 1.5;
}

.home-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.home-user,
.home-lead {
  margin: 0;
}

.home-lead {
  max-width: 38rem;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4) var(--space-5);
  padding: var(--space-4) var(--space-5);
}

.home-cta,
.home-nav {
  margin: 0;
}

.home-section h2 {
  margin: 0 0 var(--space-3);
  font-size: 1.35rem;
}

.home-empty {
  margin: 0;
  padding: var(--space-4) 1.15rem;
}

.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}

.button-secondary {
  background: transparent;
  color: var(--accent);
  border-color: var(--border);
}

.badge {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  background: var(--info-bg);
  color: var(--info);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.4;
}

.intake-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
}

.intake-list__item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2) var(--space-3);
  padding: 0.9rem 1rem;
}

.intake-list__item a {
  font-weight: 500;
  text-decoration: none;
}

.intake-list__item a:hover {
  text-decoration: underline;
}

.field,
input[type="text"],
input[type="email"],
textarea {
  font: inherit;
  color: var(--fg);
}

.flash-messages {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0 0 var(--space-5);
  padding: 0;
}

.flash-message {
  margin: 0;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  line-height: 1.4;
}

.flash-error {
  border-left: 3px solid var(--danger);
  background: var(--danger-bg);
}

.flash-success {
  border-left: 3px solid var(--success);
  background: var(--success-bg);
}

.flash-warning {
  border-left: 3px solid var(--warning);
  background: var(--warning-bg);
}

.flash-info,
.flash-debug {
  border-left: 3px solid var(--info);
  background: var(--info-bg);
}

@media (min-width: 64rem) {
  .app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }

  .shell-sidebar,
  .app-shell.is-nav-open .shell-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    transform: none;
    z-index: 1;
  }

  .shell-backdrop,
  .app-shell.is-nav-open .shell-backdrop,
  .shell-topbar {
    display: none;
  }

  .site-main {
    padding: var(--space-6) var(--space-6) 3rem;
  }
}

@media (max-width: 63.99rem) {
  .app-shell.is-nav-open .shell-sidebar {
    top: 3.25rem;
    height: calc(100dvh - 3.25rem);
  }

  .app-shell.is-nav-open .shell-backdrop {
    top: 3.25rem;
    right: 0;
    bottom: 0;
    left: 0;
    height: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .shell-sidebar {
    transition: none;
  }
}
