@layer base, layout, components, utilities;

@layer base {
  :root {
    /* OKLCH Color Palette */
    --color-bg: oklch(0.12 0.01 250);
    --color-surface: oklch(0.18 0.02 250);
    --color-text: oklch(0.95 0.01 250);
    --color-text-dim: oklch(0.7 0.02 250);
    
    --color-swim: oklch(0.65 0.15 220);
    --color-bike: oklch(0.6 0.2 40);
    --color-run: oklch(0.6 0.15 140);
    --color-ai: oklch(0.6 0.2 280);
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-deep: 0 20px 25px -5px rgb(0 0 0 / 0.2), 0 8px 10px -6px rgb(0 0 0 / 0.2);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 24px;
    
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'Roboto Mono', monospace;
  }

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

  body {
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
  }
}

@layer layout {
  .app-container {
    display: flex;
    min-height: 100vh;
  }

  .sidebar {
    width: 260px;
    background-color: var(--color-surface);
    border-right: 1px solid oklch(0.25 0.02 250);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
  }

  .main-content {
    flex: 1;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
  }

  .top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
  }

  .view {
    display: none;
    animation: fadeIn 0.4s ease-out;
  }

  .view.active {
    display: block;
  }

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

@layer components {
  /* Sidebar */
  .logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 800;
    font-size: 1.25rem;
    margin-bottom: 3rem;
    color: var(--color-text);
  }

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .nav-btn {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1rem;
    border: none;
    background: transparent;
    color: var(--color-text-dim);
    font-family: inherit;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
  }

  .nav-btn:hover {
    background-color: oklch(0.22 0.02 250);
    color: var(--color-text);
  }

  .nav-btn.active {
    background-color: oklch(0.25 0.03 250);
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
  }

  .nav-btn.ai-btn.active {
    background-color: oklch(0.6 0.2 280 / 0.2);
    color: var(--color-ai);
  }

  .sidebar-footer {
    margin-top: auto;
    font-size: 0.75rem;
    color: var(--color-text-dim);
    text-align: center;
  }

  /* Filter Bar */
  .filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-bottom: 2rem;
    background-color: var(--color-surface);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid oklch(0.25 0.02 250);
  }

  .filter-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  .filter-group label {
    margin-bottom: 0;
    white-space: nowrap;
  }

  .filter-group select {
    width: 120px;
    padding: 0.5rem;
  }

  /* Metric Cards */
  .metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
  }

  .metric-card {
    background-color: var(--color-surface);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-deep);
    position: relative;
    overflow: hidden;
    border: 1px solid oklch(0.25 0.02 250);
  }

  .metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
  }

  .swim-card::before { background-color: var(--color-swim); }
  .bike-card::before { background-color: var(--color-bike); }
  .run-card::before { background-color: var(--color-run); }

  .card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-text-dim);
    margin-bottom: 1rem;
  }

  .card-header h3 {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .card-value {
    font-family: var(--font-mono);
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
  }

  .card-subtext {
    font-size: 0.875rem;
    color: var(--color-text-dim);
  }

  /* Charts */
  .charts-container {
    background-color: var(--color-surface);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-deep);
    border: 1px solid oklch(0.25 0.02 250);
  }

  .chart-wrapper h3 {
    margin-bottom: 1.5rem;
    font-size: 1.25rem;
  }

  /* Form Styling */
  .log-container {
    background-color: var(--color-surface);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-deep);
    max-width: 600px;
    margin: 0 auto;
  }

  .log-container h2 {
    margin-bottom: 2rem;
  }

  /* Badges */
  .badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
  }

  .badge.swim { background-color: oklch(0.65 0.15 220 / 0.2); color: var(--color-swim); }
  .badge.bike { background-color: oklch(0.6 0.2 40 / 0.2); color: var(--color-bike); }
  .badge.run { background-color: oklch(0.6 0.15 140 / 0.2); color: var(--color-run); }

  /* AI Container */
  .ai-container {
    height: calc(100vh - 12rem);
    display: flex;
    flex-direction: column;
  }

  ai-assistant {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .ai-assistant-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    height: 100%;
  }

  .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background-color: oklch(0.12 0.01 250);
    border-radius: var(--radius-lg);
    border: 1px solid oklch(0.25 0.02 250);
  }

  .chat-bubble {
    max-width: 80%;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    line-height: 1.6;
  }

  .chat-bubble.ai {
    align-self: flex-start;
    background-color: var(--color-surface);
    border-bottom-left-radius: 2px;
    border: 1px solid oklch(0.6 0.2 280 / 0.3);
  }

  .chat-bubble.user {
    align-self: flex-end;
    background-color: var(--color-ai);
    color: white;
    border-bottom-right-radius: 2px;
  }

  .ai-input-area {
    display: flex;
    gap: 0.75rem;
  }

  .ai-input-area input {
    flex: 1;
  }

  .ai-input-area button {
    width: 50px;
    background-color: var(--color-ai);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: grid;
    place-items: center;
  }
}

@layer utilities {
  .hidden { display: none !important; }
}

/* Custom Elements Styling */
log-activity-form {
  display: block;
}

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

label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-dim);
}

input, select {
  width: 100%;
  padding: 0.75rem 1rem;
  background-color: oklch(0.12 0.01 250);
  border: 1px solid oklch(0.25 0.02 250);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-family: inherit;
  font-size: 1rem;
  transition: border-color 0.2s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--color-swim);
}

.submit-btn {
  width: 100%;
  padding: 1rem;
  background-color: var(--color-swim);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
  margin-top: 1rem;
}

.submit-btn:hover {
  opacity: 0.9;
}

.activity-item {
  background-color: var(--color-surface);
  padding: 1.25rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-left: 4px solid transparent;
  box-shadow: var(--shadow-md);
}

.activity-item.swim { border-left-color: var(--color-swim); }
.activity-item.bike { border-left-color: var(--color-bike); }
.activity-item.run { border-left-color: var(--color-run); }

.activity-info h4 {
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
}

.activity-info p {
  font-size: 0.875rem;
  color: var(--color-text-dim);
}

.activity-metrics {
  text-align: right;
  font-family: var(--font-mono);
}

@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    padding: 1rem;
  }
  .sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
  }
  .nav-btn span {
    display: none;
  }
}
