/* ═══════════════════════════════════════════════════════════════
   Financial Ratio Calculator — Styles
   Modern analytics dashboard with dark/light theme support
   ═══════════════════════════════════════════════════════════════ */

/* ─── Google Fonts (loaded in HTML) ─── */

/* ─── CSS Custom Properties ─── */
:root {
  /* Shared */
  --font-display: 'Sora', sans-serif;
  --font-body: 'DM Sans', sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-width: 300px;
  --nav-height: 64px;
}

/* ─── Dark Theme (Default) ─── */
[data-theme="dark"] {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.8);
  --bg-card-hover: rgba(22, 31, 48, 0.9);
  --bg-sidebar: #0d1117;
  --bg-input: rgba(30, 41, 59, 0.7);
  --bg-input-focus: rgba(30, 41, 59, 1);
  --border-color: rgba(56, 189, 248, 0.08);
  --border-hover: rgba(56, 189, 248, 0.2);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.15);
  --accent-soft: rgba(56, 189, 248, 0.1);
  --good: #34d399;
  --good-bg: rgba(52, 211, 153, 0.12);
  --neutral-color: #fbbf24;
  --neutral-bg: rgba(251, 191, 36, 0.12);
  --poor: #f87171;
  --poor-bg: rgba(248, 113, 113, 0.12);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 24px rgba(56, 189, 248, 0.08);
}

/* ─── Light Theme ─── */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-card-hover: rgba(248, 250, 252, 1);
  --bg-sidebar: #ffffff;
  --bg-input: rgba(241, 245, 249, 0.8);
  --bg-input-focus: #ffffff;
  --border-color: rgba(15, 23, 42, 0.08);
  --border-hover: rgba(15, 23, 42, 0.15);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent: #0284c7;
  --accent-glow: rgba(2, 132, 199, 0.1);
  --accent-soft: rgba(2, 132, 199, 0.06);
  --good: #059669;
  --good-bg: rgba(5, 150, 105, 0.08);
  --neutral-color: #d97706;
  --neutral-bg: rgba(217, 119, 6, 0.08);
  --poor: #dc2626;
  --poor-bg: rgba(220, 38, 38, 0.08);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.08);
  --shadow-glow: 0 0 24px rgba(2, 132, 199, 0.06);
}

/* ─── Reset & Base ─── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
  line-height: 1.6;
}

/* ─── Navigation Bar ─── */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
  backdrop-filter: blur(12px);
  transition: background var(--transition), border-color var(--transition);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.navbar-logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
}

.navbar-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  transition: color var(--transition);
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hamburger-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

#theme-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 1rem;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}

#theme-toggle:hover {
  border-color: var(--border-hover);
  background: var(--bg-input-focus);
  box-shadow: var(--shadow-glow);
}

.theme-icon {
  font-size: 1.1rem;
  line-height: 1;
}

/* ─── Layout Shell ─── */
.app-layout {
  min-height: calc(100vh - var(--nav-height));
  margin-top: var(--nav-height);
}

/* ─── Sidebar ─── */
.sidebar {
  position: fixed;
  top: var(--nav-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  padding: 20px 0;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
  z-index: 90;
}

.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.sidebar-search {
  padding: 0 16px 16px;
}

.sidebar-search input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.875rem;
  outline: none;
  transition: all var(--transition);
}

.sidebar-search input::placeholder {
  color: var(--text-muted);
}

.sidebar-search input:focus {
  border-color: var(--accent);
  background: var(--bg-input-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.sidebar-search-wrapper {
  position: relative;
}

.sidebar-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.875rem;
  pointer-events: none;
}

/* ─── Sidebar Groups ─── */
.sidebar-group {
  margin-bottom: 4px;
}

.sidebar-group-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--transition);
}

.sidebar-group-header:hover {
  color: var(--text-primary);
}

.sidebar-group-icon {
  font-size: 0.875rem;
}

.sidebar-group-name {
  flex: 1;
  text-align: left;
}

.sidebar-group-chevron {
  font-size: 0.75rem;
  transition: transform var(--transition);
  transform: rotate(-90deg);
}

.sidebar-group-header[aria-expanded="true"] .sidebar-group-chevron {
  transform: rotate(0deg);
}

.sidebar-ratio-list {
  overflow: hidden;
  max-height: 500px;
  transition: max-height 0.35s ease, opacity 0.3s ease;
  opacity: 1;
}

.sidebar-ratio-list.collapsed {
  max-height: 0;
  opacity: 0;
}

.sidebar-ratio-item {
  width: 100%;
  display: block;
  padding: 9px 16px 9px 42px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}

.sidebar-ratio-item:hover {
  color: var(--text-primary);
  background: var(--accent-soft);
}

.sidebar-ratio-item.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-left-color: var(--accent);
  font-weight: 500;
}

.sidebar-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ─── Mobile Overlay ─── */
.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 85;
  opacity: 0;
  transition: opacity var(--transition);
}

.mobile-overlay.open {
  opacity: 1;
}

/* ─── Main Content ─── */
.main-content {
  margin-left: var(--sidebar-width);
  padding: 32px 48px;
  max-width: calc(800px + var(--sidebar-width));
  width: 100%;
}

/* ─── Welcome Panel ─── */
.welcome-panel {
  text-align: center;
  padding: 80px 32px;
}

.welcome-panel.hidden {
  display: none;
}

.welcome-icon {
  font-size: 4rem;
  margin-bottom: 24px;
  display: block;
}

.welcome-panel h2 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 12px;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.welcome-panel p {
  color: var(--text-secondary);
  font-size: 1rem;
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.7;
}

/* ─── Calc Panel ─── */
.calc-panel {
  animation: fadeSlideIn 0.4s ease;
}

.calc-panel.hidden {
  display: none;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ─── Ratio Title ─── */
.ratio-header {
  margin-bottom: 24px;
}

.ratio-header h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

/* ─── Formula Card ─── */
.formula-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.formula-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.formula-text {
  font-family: 'DM Mono', 'SF Mono', 'Fira Code', monospace;
  font-size: 1.05rem;
  color: var(--text-primary);
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

.description-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.7;
}

/* ─── Input Panel ─── */
.input-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border-color var(--transition);
}

.input-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.input-panel-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.input-actions {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
  background: var(--bg-input-focus);
}

.btn-accent {
  background: var(--accent-soft);
  border-color: rgba(56, 189, 248, 0.2);
  color: var(--accent);
}

.btn-accent:hover {
  background: rgba(56, 189, 248, 0.2);
  border-color: var(--accent);
}

/* ─── Input Groups ─── */
.inputs-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color var(--transition);
}

.input-group input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.95rem;
  outline: none;
  transition: all var(--transition);
  -moz-appearance: textfield;
  appearance: textfield;
}

.input-group input::-webkit-outer-spin-button,
.input-group input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

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

.input-group input:focus {
  border-color: var(--accent);
  background: var(--bg-input-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-group input.input-invalid {
  border-color: var(--poor);
  box-shadow: 0 0 0 3px var(--poor-bg);
}

.input-error {
  font-size: 0.78rem;
  color: var(--poor);
  min-height: 1em;
}

/* ─── Result Card ─── */
.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow-md);
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.result-card.hidden {
  display: none;
}

.result-animate {
  animation: resultPop 0.35s ease;
}

@keyframes resultPop {
  0% { transform: scale(0.97); opacity: 0.5; }
  50% { transform: scale(1.01); }
  100% { transform: scale(1); opacity: 1; }
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.result-title {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.result-value {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
  transition: color var(--transition);
}

.indicator-good { color: var(--good); }
.indicator-neutral { color: var(--neutral-color); }
.indicator-poor { color: var(--poor); }

/* ─── Result Bar ─── */
.result-bar {
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 16px;
}

.result-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease, background var(--transition);
  width: 0%;
}

.indicator-bg-good { background: var(--good); }
.indicator-bg-neutral { background: var(--neutral-color); }
.indicator-bg-poor { background: var(--poor); }

/* ─── Result Meta ─── */
.result-formula {
  font-family: 'DM Mono', monospace;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.result-interpretation {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
  padding: 12px 16px;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  margin-top: 12px;
}

.result-actions {
  margin-top: 16px;
  display: flex;
  gap: 8px;
}

/* ─── Footer ─── */
.footer {
  margin-left: var(--sidebar-width);
  text-align: center;
  padding: 24px;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.82rem;
  transition: border-color var(--transition), color var(--transition);
}

.footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition);
}

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

/* ═══════════════════════════════════════
   Responsive Design
   ═══════════════════════════════════════ */

/* Tablet */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 260px;
  }

  .main-content {
    padding: 24px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .hamburger-btn {
    display: block;
  }

  .navbar-title {
    font-size: 1rem;
  }

  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    z-index: 95;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-overlay {
    display: block;
    pointer-events: none;
  }

  .mobile-overlay.open {
    pointer-events: auto;
  }

  .main-content {
    margin-left: 0;
    padding: 20px 16px;
  }

  .welcome-panel {
    padding: 48px 16px;
  }

  .welcome-panel h2 {
    font-size: 1.35rem;
  }

  .result-value {
    font-size: 2rem;
  }

  .input-panel-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .footer {
    margin-left: 0;
  }
}

/* Small mobile */
@media (max-width: 420px) {
  .navbar {
    padding: 0 16px;
  }

  .input-actions {
    flex-wrap: wrap;
  }

  .btn {
    font-size: 0.75rem;
    padding: 6px 10px;
  }
}
