/* =========================================
   CSS Custom Properties
   ========================================= */
:root {
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-surface-hover: #f1f5f9;
  --color-border: #e2e8f0;
  --color-border-light: #f1f5f9;
  --color-text: #0f172a;
  --color-text-secondary: #64748b;
  --color-text-muted: #94a3b8;
  --color-primary: #6366f1;
  --color-primary-hover: #4f46e5;
  --color-danger: #ef4444;
  --color-danger-hover: #dc2626;
  --color-success: #10b981;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);

  --nav-height: 56px;
  --font-stack: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  --transition-fast: 150ms ease;
  --transition-normal: 200ms ease;
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-stack);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* =========================================
   Main Content Area
   ========================================= */
#app {
  padding: 16px 16px calc(var(--nav-height) + 24px);
  max-width: 800px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
}

/* =========================================
   Bottom Navigation
   ========================================= */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.04);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 0.68rem;
  font-weight: 500;
  transition: color var(--transition-fast);
  user-select: none;
  -webkit-user-select: none;
}

.nav-tab:active {
  background: var(--color-surface-hover);
}

.nav-tab.active {
  color: var(--color-primary);
}

.nav-icon {
  width: 22px;
  height: 22px;
}

/* =========================================
   Cards
   ========================================= */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  border: 1px solid var(--color-border-light);
  transition: box-shadow var(--transition-normal);
}

.card + .card {
  margin-top: 12px;
}

/* =========================================
   Buttons
   ========================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-stack);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 10px 18px;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  -webkit-user-select: none;
  text-decoration: none;
  line-height: 1.2;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  padding: 8px 12px;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

.btn-danger {
  color: var(--color-danger);
}

.btn-danger:hover:not(:disabled) {
  background: #fef2f2;
  color: var(--color-danger-hover);
}

.btn-stop {
  background: var(--color-danger);
  color: white;
  padding: 12px 28px;
  font-size: 0.95rem;
  border-radius: var(--radius-full);
}

.btn-stop:hover:not(:disabled) {
  background: var(--color-danger-hover);
}

.btn-stop:active:not(:disabled) {
  transform: scale(0.96);
}

.btn-sm {
  font-size: 0.8rem;
  padding: 6px 12px;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-text-muted);
}

.btn-pill {
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  padding: 8px 16px;
  font-size: 0.8rem;
}

.btn-pill.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.btn-pill:hover:not(.active):not(:disabled) {
  background: var(--color-surface-hover);
}

/* =========================================
   Forms
   ========================================= */
.form-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-stack);
  font-size: 0.9rem;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.form-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.color-input {
  width: 44px;
  height: 38px;
  padding: 2px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--color-surface);
}

.color-input--full {
  width: 100%;
  height: 42px;
}

.date-input {
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-stack);
  font-size: 0.85rem;
  color: var(--color-text);
  background: var(--color-surface);
  outline: none;
  transition: border-color var(--transition-fast);
}

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

/* =========================================
   Modal
   ========================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  animation: fadeIn 200ms ease;
}

.modal-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 250ms ease;
}

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

.modal-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close-btn {
  font-size: 1.3rem;
  padding: 4px 8px !important;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

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

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

/* =========================================
   Loading States
   ========================================= */
.loading-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-shimmer {
  background: linear-gradient(90deg, var(--color-surface-hover) 25%, #e8ecf1 50%, var(--color-surface-hover) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* =========================================
   Section Titles
   ========================================= */
.view-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 16px;
  letter-spacing: -0.02em;
}

.section {
  margin-top: 24px;
}

.section-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  margin-bottom: 10px;
}

.section-title--archived {
  margin-top: 24px;
  color: var(--color-text-muted);
}

/* =========================================
   Color Dot
   ========================================= */
.color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.color-swatch {
  display: inline-block;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(0, 0, 0, 0.06);
}

/* =========================================
   Dashboard - Timer Card
   ========================================= */
.timer-card {
  text-align: center;
  overflow: hidden;
}

.timer-card--active {
  border: 2px solid var(--color-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1), var(--shadow-md);
}

.timer-idle {
  padding: 20px 0 12px;
}

.timer-idle-icon {
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.timer-idle-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-secondary);
}

.timer-idle-hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 4px;
}

.timer-active {
  padding: 16px 0;
}

.timer-category {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

.timer-category .color-dot {
  width: 12px;
  height: 12px;
}

.timer-category-name {
  font-size: 1rem;
  font-weight: 700;
}

.timer-elapsed {
  font-size: 2.75rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--color-text);
  margin-bottom: 6px;
  line-height: 1.1;
}

.timer-started {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: 16px;
}

/* =========================================
   Dashboard - Quick Start Grid
   ========================================= */
.quick-start-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.quick-start-btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 16px 12px;
  min-height: 76px;
  color: white;
  font-family: var(--font-stack);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all var(--transition-fast);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.quick-start-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, rgba(0,0,0,0.05) 100%);
  pointer-events: none;
}

.quick-start-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.quick-start-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.97);
}

.quick-start-btn:disabled {
  opacity: 0.85;
  cursor: default;
}

.quick-start-btn--active {
  animation: pulse-border 2s ease-in-out infinite;
}

.quick-start-name {
  position: relative;
  z-index: 1;
}

.quick-start-running {
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.85;
  position: relative;
  z-index: 1;
}

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4); }
  50% { box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.15); }
}

/* =========================================
   Dashboard - Today Summary
   ========================================= */
.today-stats {
  padding: 16px;
}

.today-row {
  margin-bottom: 14px;
}

.today-row:last-of-type {
  margin-bottom: 16px;
}

.today-row-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.today-cat-name {
  font-size: 0.85rem;
  font-weight: 600;
  flex: 1;
}

.today-cat-time {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-text-secondary);
  font-variant-numeric: tabular-nums;
}

.today-bar-track {
  height: 8px;
  background: var(--color-border-light);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.today-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 400ms ease;
}

.today-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 14px;
  border-top: 1px solid var(--color-border-light);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-text-secondary);
}

.today-total-time {
  font-size: 1rem;
  color: var(--color-text);
}

.today-empty {
  text-align: center;
  padding: 32px 16px;
}

/* =========================================
   History View
   ========================================= */
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.date-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.date-picker-row .date-input {
  flex: 1;
  text-align: center;
}

.entry-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.entry-main {
  flex: 1;
  min-width: 0;
}

.entry-category {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.entry-category-name {
  font-weight: 700;
  font-size: 0.9rem;
}

.entry-times {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.entry-time {
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-secondary);
}

.entry-time-sep {
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

.entry-duration {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-text);
  margin-left: 4px;
  background: var(--color-surface-hover);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.entry-note {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 4px;
  font-style: italic;
}

.entry-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.badge-running {
  background: #dcfce7;
  color: #16a34a;
  animation: badge-pulse 2s ease-in-out infinite;
}

@keyframes badge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* =========================================
   Reports View
   ========================================= */
.period-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.custom-range {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.range-sep {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.charts-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.chart-card {
  padding: 20px 16px;
}

.chart-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.chart-container {
  position: relative;
}

.chart-container--doughnut {
  height: 280px;
  max-width: 360px;
  margin: 0 auto;
}

.chart-container--bar {
  height: 240px;
}

.summary-table-card {
  margin-top: 16px;
  padding: 20px 16px;
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.summary-table th {
  text-align: left;
  padding: 8px 12px 8px 0;
  border-bottom: 2px solid var(--color-border);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.summary-table td {
  padding: 10px 12px 10px 0;
  border-bottom: 1px solid var(--color-border-light);
  white-space: nowrap;
}

.summary-table td:first-child {
  display: flex;
  align-items: center;
  gap: 8px;
}

.summary-table .text-right {
  text-align: right;
  padding-right: 0;
}

.summary-table th.text-right {
  text-align: right;
  padding-right: 0;
}

.total-row td {
  border-bottom: none;
  border-top: 2px solid var(--color-border);
  padding-top: 12px;
}

/* =========================================
   Categories View
   ========================================= */
.add-category-card {
  margin-bottom: 16px;
}

.add-category-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.add-category-form .form-input {
  flex: 1;
  margin-bottom: 0;
}

.categories-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.categories-grid--archived {
  opacity: 0.7;
}

.category-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
}

.category-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.category-name {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* =========================================
   Empty & Error States
   ========================================= */
.empty-state {
  text-align: center;
  padding: 32px 16px;
}

.empty-text {
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.error-card {
  text-align: center;
  padding: 24px 16px;
  color: var(--color-danger);
}

.error-card h3 {
  margin-bottom: 8px;
}

/* =========================================
   Setup Modal
   ========================================= */
#setup-modal .modal-card {
  text-align: center;
}

#setup-modal h2 {
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: 8px;
}

#setup-modal p {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  margin-bottom: 20px;
}

#setup-modal .form-input {
  margin-bottom: 12px;
  text-align: center;
}

/* =========================================
   Entry Form (in modal)
   ========================================= */
.entry-form .form-label:last-of-type {
  margin-bottom: 16px;
}

/* =========================================
   Responsive: Tablet+
   ========================================= */
@media (min-width: 768px) {
  :root {
    --nav-height: 0px;
  }

  .bottom-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: auto;
    width: 220px;
    height: 100vh;
    height: 100dvh;
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--color-border);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.03);
    padding: 24px 0;
    gap: 4px;
  }

  .nav-tab {
    flex: unset;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 24px;
    font-size: 0.9rem;
    border-radius: 0;
  }

  .nav-tab.active {
    background: rgba(99, 102, 241, 0.08);
    border-right: 3px solid var(--color-primary);
  }

  .nav-icon {
    width: 20px;
    height: 20px;
  }

  #app {
    margin-left: 220px;
    padding: 32px 32px 32px;
    max-width: 900px;
  }

  .quick-start-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .chart-container--doughnut {
    height: 300px;
    max-width: none;
  }

  .chart-container--bar {
    height: 300px;
  }

  .entry-card {
    align-items: center;
  }

  .entry-actions {
    flex-direction: row;
  }
}

/* =========================================
   Responsive: Large Desktop
   ========================================= */
@media (min-width: 1200px) {
  .quick-start-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* =========================================
   Accessibility - Focus Styles
   ========================================= */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Remove focus outline for mouse users */
:focus:not(:focus-visible) {
  outline: none;
}

/* =========================================
   Dark Mode (prefers-color-scheme)
   ========================================= */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-surface-hover: #334155;
    --color-border: #334155;
    --color-border-light: #1e293b;
    --color-text: #f1f5f9;
    --color-text-secondary: #94a3b8;
    --color-text-muted: #64748b;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.2);
  }

  .form-input, .date-input {
    background: #0f172a;
    color: var(--color-text);
    border-color: var(--color-border);
  }

  .color-input {
    background: #0f172a;
    border-color: var(--color-border);
  }

  .modal-overlay {
    background: rgba(0, 0, 0, 0.6);
  }

  .btn-danger:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.15);
  }

  .loading-shimmer {
    background: linear-gradient(90deg, var(--color-surface) 25%, #2a3a50 50%, var(--color-surface) 75%);
    background-size: 200% 100%;
  }

  .badge-running {
    background: rgba(22, 163, 106, 0.2);
    color: #4ade80;
  }

  .entry-duration {
    background: rgba(255, 255, 255, 0.08);
  }

  .summary-table th {
    border-bottom-color: var(--color-border);
  }

  .summary-table td {
    border-bottom-color: rgba(255, 255, 255, 0.05);
  }

  .total-row td {
    border-top-color: var(--color-border);
  }
}

/* =========================================
   Print Styles (hide nav)
   ========================================= */
@media print {
  .bottom-nav {
    display: none;
  }

  #app {
    margin: 0;
    padding: 0;
  }
}
