/* === NewCo Charts - Global Styles === */

:root {
  --color-primary: #1e6c93;
  --color-primary-dark: #154d6b;
  --color-primary-light: #2a8ab8;
  --color-accent: #1a73e8;
  --color-bar: #4a90d9;
  --color-bg: #f5f7f9;
  --color-surface: #ffffff;
  --color-text: #333333;
  --color-text-light: #666666;
  --color-text-muted: #999999;
  --color-border: #e0e0e0;
  --color-border-light: #f0f0f0;
  --nav-width: 280px;
  --header-height: 56px;
  --chart-min-height: 280px;
  --transition: 0.2s ease;
}

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

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

body {
  font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  min-height: 100vh;
}

/* === Navigation Sidebar === */

#main-nav {
  width: var(--nav-width);
  background: var(--color-primary-dark);
  color: #fff;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform var(--transition);
}

.nav-header {
  padding: 20px 16px;
  background: var(--color-primary);
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.nav-header h1 {
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.nav-header h1 a {
  color: #fff;
  text-decoration: none;
}

.nav-section {
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.nav-link {
  display: block;
  padding: 8px 16px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 0.92rem;
  transition: background var(--transition), color var(--transition);
}

.nav-link:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.nav-link.active {
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-weight: 600;
}

.nav-children {
  padding-left: 12px;
}

.nav-children .nav-link {
  font-size: 0.85rem;
  padding: 6px 16px;
  color: rgba(255,255,255,0.7);
}

.nav-children .nav-link:hover {
  color: #fff;
}

.nav-parent-label {
  display: block;
  padding: 8px 16px;
  color: rgba(255,255,255,0.6);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
  margin-top: 4px;
}

/* Mobile nav toggle */
.nav-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 1.2rem;
  cursor: pointer;
}

/* === Main Content === */

main {
  margin-left: var(--nav-width);
  flex: 1;
  min-width: 0;
}

.page-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 20px 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-primary-dark);
  margin-bottom: 12px;
}

/* === Controls === */

.controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.control-label {
  font-size: 0.85rem;
  color: var(--color-text-light);
  font-weight: 500;
}

.btn-group {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  overflow: hidden;
}

.btn-group button {
  padding: 6px 14px;
  border: none;
  background: var(--color-surface);
  color: var(--color-text-light);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  border-right: 1px solid var(--color-border);
}

.btn-group button:last-child {
  border-right: none;
}

.btn-group button:hover {
  background: var(--color-bg);
}

.btn-group button.active {
  background: var(--color-primary);
  color: #fff;
}

/* === Chart Grid === */

.chart-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 16px 24px;
}

.chart-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: 8px;
  padding: 12px;
  min-height: var(--chart-min-height);
  transition: box-shadow var(--transition);
}

.chart-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.chart-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text);
  text-align: center;
  margin-bottom: 4px;
  line-height: 1.3;
  min-height: 2.6em;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-container {
  width: 100%;
  height: 230px;
}

.chart-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 230px;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

.chart-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 230px;
  color: #c0392b;
  font-size: 0.85rem;
}

/* === Landing Page === */

.landing-hero {
  background: linear-gradient(135deg, var(--color-primary-dark), var(--color-primary-light));
  color: #fff;
  padding: 60px 24px;
  text-align: center;
}

.landing-hero h1 {
  font-size: 2.4rem;
  margin-bottom: 12px;
}

.landing-hero p {
  font-size: 1.1rem;
  opacity: 0.9;
}

.section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}

.section-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 20px;
  text-decoration: none;
  color: var(--color-text);
  transition: box-shadow var(--transition), transform var(--transition);
}

.section-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transform: translateY(-2px);
}

.section-card h3 {
  color: var(--color-primary);
  margin-bottom: 6px;
}

.section-card p {
  color: var(--color-text-light);
  font-size: 0.9rem;
}

/* === NIPA Index === */

.index-list {
  list-style: none;
  max-width: 800px;
  margin: 0 auto;
  padding: 24px;
}

.index-list li {
  margin-bottom: 8px;
}

.index-list a {
  display: block;
  padding: 12px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
  transition: background var(--transition);
}

.index-list a:hover {
  background: var(--color-bg);
}

/* === Responsive === */

@media (max-width: 1400px) {
  .chart-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 1000px) {
  .chart-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  #main-nav {
    transform: translateX(-100%);
  }
  #main-nav.open {
    transform: translateX(0);
  }
  .nav-toggle {
    display: block;
  }
  main {
    margin-left: 0;
  }
  .page-header {
    padding-left: 56px;
  }
  .chart-grid {
    grid-template-columns: 1fr;
    padding: 12px;
  }
}

/* === Chat Panel === */

.chat-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--color-primary);
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: background var(--transition), transform var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-toggle:hover {
  background: var(--color-primary-dark);
  transform: scale(1.05);
}

.chat-toggle.open {
  background: #c0392b;
}

.chat-panel {
  position: fixed;
  bottom: 80px;
  right: 20px;
  z-index: 299;
  width: 420px;
  max-height: 520px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.chat-panel.open {
  display: flex;
}

.chat-header {
  padding: 14px 16px;
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-header-icon {
  font-size: 1.1rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 360px;
  min-height: 200px;
}

.chat-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--color-bg);
  color: var(--color-text);
  border-bottom-left-radius: 4px;
}

.chat-msg.assistant p {
  margin: 0 0 6px 0;
}

.chat-msg.assistant p:last-child {
  margin-bottom: 0;
}

.chat-msg.assistant strong {
  font-weight: 600;
}

.chat-msg.system {
  align-self: center;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 4px;
}

.chat-typing {
  align-self: flex-start;
  padding: 10px 14px;
  background: var(--color-bg);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  display: none;
}

.chat-typing.visible {
  display: block;
}

.chat-input-row {
  padding: 10px 14px;
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 8px;
  background: var(--color-surface);
}

.chat-input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  resize: none;
  min-height: 38px;
  max-height: 80px;
}

.chat-input:focus {
  border-color: var(--color-primary-light);
}

.chat-send {
  padding: 0 14px;
  border: none;
  border-radius: 8px;
  background: var(--color-primary);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}

.chat-send:hover {
  background: var(--color-primary-dark);
}

.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 768px) {
  .chat-panel {
    width: calc(100vw - 24px);
    right: 12px;
    bottom: 76px;
    max-height: 70vh;
  }
}
