:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #252525;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --accent: #4a9eff;
  --success: #00d084;
  --warning: #f59e0b;
  --danger: #ff4757;
  --border: #333;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
}

.navbar {
  background: var(--bg-secondary);
  padding: 0.75rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-size: 1.25rem;
  font-weight: 600;
  background: var(--brand-gradient, linear-gradient(135deg, var(--accent), #00d084));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav-links {
  display: flex;
  gap: 0.5rem;
}

.nav-links a {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  transition: all 0.2s;
  font-size: 0.95rem;
  font-weight: 500;
}

.nav-links a:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.nav-links a.active {
  color: var(--accent);
  background: rgba(74, 158, 255, 0.1);
}

.nav-logout {
  margin-left: auto;
  padding: 0.5rem 1rem;
  background: var(--danger);
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}

#app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 2rem 2rem;
}

.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-primary);
  padding: 1rem;
}

.login-card {
  max-width: 400px;
  width: 100%;
}

.card {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
  overflow: visible;
}

.header-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
  align-items: stretch;
}

.stat-card {
  background: var(--bg-tertiary);
  padding: 1.5rem;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stat-label {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: bold;
  line-height: 1.1;
}

.stat-sublabel {
  font-size: 0.9rem;
  font-weight: 500;
  margin-top: 0.3rem;
}

.positive { color: var(--success); }
.negative { color: var(--danger); }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-secondary);
  font-weight: 500;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  transition: opacity 0.3s;
}

button:hover {
  opacity: 0.8;
}

input:not([type="checkbox"]):not([type="radio"]), select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.75rem;
  border-radius: 6px;
  font-size: 1rem;
  width: 100%;
  appearance: none;
  cursor: pointer;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a0a0a0' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

h2, h3 {
  margin-bottom: 1rem;
}

.recommendation {
  padding: 1rem;
  margin-bottom: 0.5rem;
  border-radius: 6px;
  background: var(--bg-tertiary);
}

.recommendation.high {
  border-left: 4px solid var(--danger);
}

.recommendation.medium {
  border-left: 4px solid orange;
}

.toast {
  position: fixed;
  top: 2rem;
  right: 2rem;
  background: var(--bg-secondary);
  border: 1px solid var(--success);
  border-radius: 8px;
  padding: 1rem 1.5rem;
  color: var(--text-primary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 9999;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.2s ease-out;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  animation: scaleIn 0.2s ease-out;
}

.modal-content h3 {
  margin: 0 0 1rem 0;
  color: var(--text-primary);
}

.modal-content p {
  margin: 0 0 1.5rem 0;
  color: var(--text-secondary);
}

.modal-buttons {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
}

.modal-buttons button {
  padding: 0.75rem 1.5rem;
}

.modal-buttons .btn-cancel {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.modal-buttons .btn-danger {
  background: var(--danger);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.tab-btn {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  margin-right: 0.5rem;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.3s;
}

.tab-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.search-results {
  position: relative;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 0.5rem;
  max-height: 300px;
  overflow-y: auto;
}

.search-result-item {
  padding: 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}

.search-result-item:hover {
  background: var(--bg-secondary);
}

.search-result-item:last-child {
  border-bottom: none;
}

table button {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  margin-right: 0.5rem;
  margin-bottom: 0.5rem;
}

.mobile-menu-btn {
  display: none;
}

.mobile-overlay {
  display: none;
}

.tab-selector,
.tab-dropdown,
.timeframe-selector,
.timeframe-dropdown {
  display: none;
}

@media (max-width: 768px) {
  .navbar {
    position: fixed;
    top: 0;
    left: -250px;
    width: 250px;
    height: 100vh;
    flex-direction: column;
    padding: 1rem;
    transition: left 0.3s ease;
    z-index: 1000;
    border-right: 1px solid var(--border);
    border-bottom: none;
    justify-content: flex-start;
  }

  .navbar.open {
    left: 0;
  }

  .nav-brand {
    margin-bottom: 2rem;
  }

  .nav-links {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-top: 0;
    width: 100%;
  }

  .nav-links a {
    margin-left: 0;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
  }

  .nav-logout {
    margin-left: 0;
    width: 100%;
    padding: 1rem;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    color: var(--danger);
    text-align: left;
    font-size: 1rem;
  }

  .mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }

  .mobile-overlay.active {
    display: block;
  }

  .mobile-menu-btn {
    display: flex;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1001;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
    width: 44px;
    height: 44px;
  }

  .mobile-menu-btn.hidden {
    opacity: 0;
    pointer-events: none;
  }

  .mobile-menu-btn svg {
    width: 24px;
    height: 24px;
    stroke: var(--text-primary);
    stroke-width: 2;
    stroke-linecap: round;
  }

  #app {
    padding: 4rem 1rem 1rem 1rem;
    margin: 0;
  }

  body.login-page {
    overflow: hidden;
    height: 100dvh;
  }

  body.login-page #app {
    padding: 0;
    height: 100dvh;
    max-width: 100%;
    display: flex;
  }

  .login-wrapper {
    padding: 0;
    flex: 1;
    min-height: unset;
    height: 100%;
    align-items: stretch;
  }

  .login-card {
    border-radius: 0;
    flex: 1;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow-y: auto;
    background: transparent;
    box-shadow: none;
    border: none;
    margin-bottom: 0;
  }

  .header-stats {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .stat-card {
    padding: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .stat-sublabel {
    display: none;
  }

  .stat-label {
    font-size: 0.8rem;
    margin-bottom: 0;
  }

  .stat-value {
    font-size: 1.25rem;
  }

  .timeframe-selector {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 6px;
    cursor: pointer;
    margin-top: 1rem;
  }

  .timeframe-dropdown {
    display: none;
    position: absolute;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-top: 0.5rem;
    z-index: 100;
    width: calc(100% - 2rem);
  }

  .timeframe-dropdown.active {
    display: block;
  }

  .timeframe-dropdown button {
    width: 100%;
    text-align: left;
    padding: 0.75rem;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
  }

  .timeframe-dropdown button:last-child {
    border-bottom: none;
  }

  .timeframe-dropdown button.active {
    background: var(--accent);
  }

  .timeframe-buttons {
    display: none;
  }

  canvas {
    max-height: 300px !important;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .card {
    padding: 1rem;
  }

  button {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
  }

  table button {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    margin-right: 0.25rem;
  }

  .card > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }

  .card > div[style*="grid-template-columns"] > div {
    padding: 0;
    margin: 0;
    max-width: 100%;
    overflow: hidden;
  }

  .card canvas {
    max-width: 100%;
    margin: 0 auto;
    display: block;
  }

  .tab-selector {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 1.5rem;
  }

  .tab-dropdown {
    display: none;
    position: absolute;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-top: 0.5rem;
    z-index: 100;
    width: calc(100% - 2rem);
  }

  .tab-dropdown.active {
    display: block;
  }

  .tab-dropdown button {
    width: 100%;
    text-align: left;
    padding: 0.75rem;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
  }

  .tab-dropdown button:last-child {
    border-bottom: none;
  }

  .tab-dropdown button.active {
    background: var(--accent);
  }

  .tab-btn {
    display: none;
  }
}

.timeframe-btn {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  cursor: pointer;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.timeframe-btn:first-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.timeframe-btn:last-child {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.timeframe-btn:not(:first-child):not(:last-child) {
  border-radius: 0;
  border-left: none;
  border-right: none;
}

.timeframe-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

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