/* AI CFO — Facebook-style UI (HTML5/CSS3) */
:root {
  --topbar-height: 72px;
  --fb-blue: #1877f2;
  --fb-blue-hover: #166fe5;
  --fb-green: #42b72a;
  --fb-green-hover: #36a420;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #dddfe2;
  --text: #050505;
  --text-secondary: #65676b;
  --text-muted: #8a8d91;
  --success: #31a24c;
  --warning: #eab308;
  --error: #e41e3f;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.3333; min-height: 100vh; }
a { color: var(--fb-blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 700; line-height: 1.2; color: var(--text); }
input, button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }

/* Top bar — Facebook-style */
.topbar {
  background: var(--surface);
  box-shadow: var(--shadow);
  min-height: var(--topbar-height);
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}
/* Inner row: logo left, nav links on the right */
.topbar > div {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  min-height: var(--topbar-height);
  width: 100%;
  box-sizing: border-box;
}
.topbar > div > .logo,
.topbar > div > a.logo,
.topbar > div > #dashboardLogo,
.topbar > div > #adminHeaderLogo {
  grid-column: 1;
  justify-self: start;
  min-width: 0;
}
.topbar > div > nav {
  grid-column: 2;
  justify-self: end;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-end;
}
.topbar .logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--fb-blue);
  line-height: 1.1;
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  overflow: hidden;
}
.topbar .logo span { color: var(--text); }
.topbar .logo.logo-has-img {
  font-size: inherit;
  max-width: min(100%, 280px);
  color: var(--text);
  text-decoration: none;
}
.topbar .logo .logo-brand-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 100%;
  min-width: 0;
}
.topbar .logo .logo-brand-img,
.topbar .logo img {
  max-height: 44px;
  max-width: 120px;
  width: auto;
  height: auto;
  object-fit: contain;
  flex-shrink: 0;
}
.topbar .logo-brand-text {
  display: inline-block;
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 11rem;
}
.topbar nav a {
  color: var(--text-secondary);
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  white-space: nowrap;
}
.topbar nav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.topbar nav .btn {
  padding: 0.5rem 1rem;
  background: var(--fb-blue);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.9375rem;
}
.topbar nav .btn:hover { background: var(--fb-blue-hover); text-decoration: none; }
.topbar nav .admin-link { color: var(--warning); }

/* Hero / landing — clean card style */
.hero {
  min-height: calc(100vh - var(--topbar-height));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--bg);
}
.hero-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 2.5rem;
  max-width: 560px;
  width: 100%;
  text-align: center;
}
.hero h1 { font-size: clamp(1.75rem, 4vw, 2.25rem); margin-bottom: 0.75rem; color: var(--text); }
.hero .tagline { font-size: 1rem; color: var(--text-secondary); margin-bottom: 1.5rem; line-height: 1.5; }
.hero .ctas {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: stretch;
  width: 100%;
  max-width: 260px;
  margin: 0 auto;
}
.hero .ctas .region-row {
  width: 100%;
}
.hero .ctas .region-row .btn {
  display: block;
  width: 100%;
  box-sizing: border-box;
}
.hero .ctas .btn {
  padding: 0.7rem 1.25rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.9375rem;
  text-align: center;
  transition: background 0.2s, color 0.2s;
}
.hero .ctas .btn-primary { background: var(--fb-blue); color: #fff; border: 1px solid var(--fb-blue); }
.hero .ctas .btn-primary:hover { background: var(--fb-blue-hover); text-decoration: none; }
.hero .ctas .btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.hero .ctas .btn-secondary:hover { background: var(--bg); border-color: var(--fb-blue); color: var(--fb-blue); text-decoration: none; }
.hero .region-badge {
  margin-top: 1.25rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
}
.hero .region-badge strong { color: var(--text); font-weight: 600; }
.hero .hero-score-link { margin-top: 1.5rem; font-size: 0.9375rem; }
.hero .hero-score-link a { color: var(--fb-blue); }

/* Auth — Facebook-style card */
.auth-page {
  min-height: calc(100vh - var(--topbar-height));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 396px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.5rem;
}
.auth-card h1 { font-size: 1.25rem; margin-bottom: 0.5rem; color: var(--text); }
.auth-card .sub { color: var(--text-secondary); font-size: 0.9375rem; margin-bottom: 1rem; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.25rem; font-size: 0.9375rem; color: var(--text); }
.form-group input,
.form-group select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--fb-blue);
  box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.2);
}
.region-options { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.region-options label {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9375rem;
}
.region-options input { width: auto; margin: 0; }
.region-options label:has(input:checked) { border-color: var(--fb-blue); background: rgba(24, 119, 242, 0.08); }
.btn-block {
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 1rem;
  background: var(--fb-blue);
  color: #fff;
  margin-top: 0.25rem;
}
.btn-block:hover { background: var(--fb-blue-hover); }
.btn-block:disabled { opacity: 0.6; cursor: not-allowed; }
.auth-footer { margin-top: 1rem; text-align: center; font-size: 0.875rem; color: var(--text-secondary); }
.auth-footer a { color: var(--fb-blue); font-weight: 500; }
.message { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9375rem; }
.message.error { background: rgba(228, 30, 63, 0.08); border: 1px solid var(--error); color: #b71c1c; }
.message.success { background: rgba(49, 162, 76, 0.08); border: 1px solid var(--success); color: #1b5e20; }
.hidden { display: none !important; }

/* Dashboard — sidebar + main only; main uses remaining width (no third column) */
.dash-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 1rem;
  max-width: 100%;
  margin: 0 auto;
  padding: 1rem;
  min-height: calc(100vh - var(--topbar-height));
}
.dash-sidebar {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 0.5rem 0;
  height: fit-content;
  position: sticky;
  top: var(--topbar-height);
  min-width: 0;
}
.dash-sidebar .sidebar-brand {
  padding: 0.75rem 1rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--fb-blue);
  border-bottom: 1px solid var(--border);
  display: block;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}
.dash-sidebar .sidebar-brand span { color: var(--text); }
.dash-sidebar .sidebar-brand .logo-brand-wrap {
  max-width: 100%;
  min-width: 0;
  flex-wrap: wrap !important;
}
.dash-sidebar .sidebar-brand .logo-brand-text {
  white-space: normal !important;
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}
.dash-sidebar a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--text);
  font-weight: 500;
  font-size: 0.9375rem;
  border-radius: var(--radius);
  margin: 0 0.25rem;
}
.dash-sidebar a:hover { background: var(--bg); text-decoration: none; }
.dash-sidebar a.active { background: rgba(24, 119, 242, 0.1); color: var(--fb-blue); }
.dash-main {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.25rem;
  min-height: 400px;
}
.dash-header { margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border); }
.dash-header h1 { font-size: 1.25rem; }
.user-email { color: var(--text-secondary); font-size: 0.9375rem; margin-top: 0.25rem; }

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}
.card h2 { font-size: 1.0625rem; margin-bottom: 0.75rem; color: var(--text); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--text-secondary); font-weight: 600; font-size: 0.8125rem; }
.badge { display: inline-block; padding: 0.2rem 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge.active { background: rgba(49, 162, 76, 0.15); color: var(--success); }
.badge.pending { background: rgba(234, 179, 8, 0.2); color: #b45309; }

@media (max-width: 900px) {
  .dash-layout { grid-template-columns: 1fr; }
  .dash-sidebar { position: static; display: flex; flex-wrap: wrap; gap: 0.25rem; padding: 0.5rem; }
  .dash-sidebar a { flex: 1 1 auto; }
}

/* Mobile: keep logo + nav readable without overlap */
@media (max-width: 768px) {
  :root { --topbar-height: auto; }
  .topbar {
    min-height: 0;
    padding: 0.4rem 0;
  }
  .topbar > div {
    grid-template-columns: minmax(0, 1fr) auto !important;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    min-height: 0;
    align-items: center;
  }
  .topbar > div > .logo,
  .topbar > div > a.logo {
    max-width: min(58vw, 200px);
  }
  .topbar .logo .logo-brand-img,
  .topbar .logo img {
    max-height: 32px !important;
    max-width: 72px !important;
  }
  .topbar .logo-brand-text {
    display: inline-block !important;
    font-size: 0.78rem;
    max-width: 6.5rem;
  }
  .topbar > div > nav {
    max-width: 42vw;
    gap: 0.15rem;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .topbar nav a {
    padding: 0.3rem 0.4rem;
    font-size: 0.8125rem;
  }
  .hero {
    min-height: auto;
    padding: 1.25rem 1rem 5.5rem;
  }
  .hero-content {
    padding: 1.25rem;
  }
  .auth-page {
    padding: 1.25rem 1rem 5rem;
  }
  body {
    padding-bottom: 4.5rem;
  }
}
