/* Global styles and responsive mobile layout */

/* ---------- Design tokens ---------- */
:root {
  color-scheme: light;

  /* Surfaces */
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f3f3f3;
  --surface-hover: #f5f5f5;

  /* Text */
  --text: #202020;
  --muted: #808080;

  /* Borders & shadows */
  --border: #e6e6e6;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.16);

  /* Accent (Todoist-like red) */
  --primary: #dc4c3e;
  --primary-hover: #c53727;
  --primary-soft: #fdefed;

  /* Status */
  --status-pending: #dc4c3e;
  --status-done: #058527;
  --status-failed: #eb8909;

  /* Feedback */
  --success-bg: #ecf7ee;
  --success-border: #9fd8a9;
  --error-bg: #fdefed;
  --error-border: #f0b3ab;

  /* Shape */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #1e1e1e;
  --surface: #282828;
  --surface-2: #333333;
  --surface-hover: #363636;

  --text: #e8e8e8;
  --muted: #9b9b9b;

  --border: #3d3d3d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);

  --primary: #e06156;
  --primary-hover: #ea7a70;
  --primary-soft: #3a2826;

  --status-pending: #e06156;
  --status-done: #4fb15f;
  --status-failed: #f0a23e;

  --success-bg: #21331f;
  --success-border: #3e6b3a;
  --error-bg: #3a2422;
  --error-border: #7a4039;
}

* {
  box-sizing: border-box;
}
html,
body,
#root {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  transition: background 0.2s ease, color 0.2s ease;
}
a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

input,
select,
button {
  font: 15px system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial,
    sans-serif;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
}
input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

button {
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s ease, box-shadow 0.15s ease,
    transform 0.05s ease;
}
button:hover {
  background: var(--primary-hover);
}
button:active {
  transform: translateY(1px);
}
button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.ghost:hover {
  background: var(--surface-hover);
}

.container {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial,
    sans-serif;
  max-width: 1000px;
  margin: 0 auto;
  padding: 12px 16px;
}

.app-header {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 0 14px;
}
.app-header strong {
  font-size: 17px;
  letter-spacing: -0.01em;
}
.app-header .user {
  margin-left: auto;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius-md);
  line-height: 1;
}
.theme-toggle:hover {
  background: var(--surface-hover);
}

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  margin-top: 12px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.list > li {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background 0.12s ease;
}
.list > li.clickable:hover {
  background: var(--surface-hover);
}
.list > li.active {
  background: var(--primary-soft);
  border-left: 3px solid var(--primary);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.alert {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  font-size: 14px;
}
.alert.success {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
}
.alert.error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
}

/* Mobile adjustments */
@media (max-width: 800px) {
  .layout {
    grid-template-columns: 1fr !important;
  }
  .app-header {
    flex-wrap: wrap;
  }
  .app-header .user {
    width: 100%;
    justify-content: flex-end;
  }
  .grid-2 {
    grid-template-columns: 1fr !important;
  }
  .row.stack-sm {
    flex-direction: column;
    align-items: stretch;
  }
  .row.stack-sm > * {
    width: 100%;
  }
  input,
  select,
  button {
    border-radius: 12px;
  }
  .panel {
    padding: 12px;
  }

  /* Off-canvas sidebar for mobile */
  .mobile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 50;
  }
  .mobile-drawer {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 86vw;
    max-width: 360px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 12px;
    z-index: 60;
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .mobile-drawer.open {
    transform: translateX(0);
  }
}

/* Kanban board styles */
.kanban {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 12px;
}
.kanban-col {
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 10px;
  min-height: 200px;
}
.kanban-col.dragging {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.kanban-col-title {
  font-weight: 600;
  margin-bottom: 8px;
}
.kanban-col-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease;
}
.kanban-card:hover {
  box-shadow: var(--shadow-md);
}
.kanban-card.drag-over {
  outline: 2px dashed var(--primary);
}
.kanban-title {
  font-weight: 600;
  margin-bottom: 4px;
}
.kanban-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

@media (max-width: 800px) {
  .kanban {
    grid-template-columns: 1fr;
  }
}

/* Calendar */
.calendar {
  margin-top: 12px;
}
.calendar-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}
.calendar-title {
  font-weight: 700;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.calendar-dow {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}
.calendar-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-height: 100px;
  padding: 6px;
  display: flex;
  flex-direction: column;
}
.calendar-cell.out {
  opacity: 0.5;
}
.calendar-date {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}
.calendar-cell-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.calendar-undated {
  margin-bottom: 8px;
}
.calendar-undated-title {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}
.calendar-undated-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: grab;
}
.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.pill-text {
  font-size: 12px;
}
.pill-done .pill-dot {
  background: var(--status-done);
}
.pill-pending .pill-dot {
  background: var(--status-pending);
}
.pill-failed .pill-dot {
  background: var(--status-failed);
}

/* Simple modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: min(640px, 94vw);
  max-height: 86vh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-weight: 700;
}
.modal-body {
  padding: 14px;
}
.modal-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* View tabs - compact design */
.view-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 8px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  padding: 3px;
}

.view-tabs button {
  border: none;
  background: transparent;
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s ease;
  min-width: 40px;
}

.view-tabs button:hover {
  background: var(--surface-hover);
}

.view-tabs button.active {
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

/* Timeline view styles */
.timeline-view {
  padding: 16px;
}

.timeline-header {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.timeline-grid {
  margin-bottom: 24px;
}

.timeline-hours {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.hour-slot {
  display: flex;
  min-height: 60px;
  border-bottom: 1px solid var(--border);
}

.hour-label {
  width: 60px;
  padding: 8px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  font-weight: 500;
}

.hour-content {
  flex: 1;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.time-entry {
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  margin: 1px 0;
  border-left: 4px solid var(--primary);
  font-size: 12px;
}

.entry-title {
  font-weight: 500;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-time {
  color: var(--muted);
  font-size: 11px;
}

.entry-duration {
  color: var(--text);
  font-size: 11px;
  font-weight: 500;
}

.available-tasks {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.available-tasks h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
  font-weight: 600;
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: box-shadow 0.15s ease;
}
.task-item:hover {
  box-shadow: var(--shadow-sm);
}

.task-info {
  flex: 1;
}

.task-title {
  font-weight: 500;
  margin-bottom: 4px;
}

.task-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
}

.task-actions button {
  min-width: 80px;
}

.stop-tracking {
  background: var(--status-pending);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
}

.tracking-active {
  background: var(--status-done);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

@media (max-width: 800px) {
  .view-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .view-tabs button {
    flex-shrink: 0;
    padding: 6px 8px;
    font-size: 12px;
  }

  .timeline-hours {
    font-size: 11px;
  }

  .hour-label {
    width: 50px;
    padding: 6px;
  }

  .task-item {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
}

/* Productivity Analytics styles */
.productivity-analytics {
  padding: 16px;
}

.analytics-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 16px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  padding: 3px;
  overflow-x: auto;
}

.analytics-tabs button {
  border: none;
  background: transparent;
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.analytics-tabs button:hover {
  background: var(--surface-hover);
}

.analytics-tabs button.active {
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.analytics-content {
  margin-top: 16px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.metric-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.metric-label {
  font-size: 12px;
  color: var(--muted);
}

/* Chart styles */
.chart-container {
  display: flex;
  align-items: end;
  gap: 4px;
  height: 200px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow-x: auto;
}

.chart-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 40px;
  height: 100%;
}

.chart-bar-fill {
  width: 100%;
  min-height: 2px;
  border-radius: 2px 2px 0 0;
  transition: height 0.3s ease;
}

.chart-bar-label {
  margin-top: 8px;
  font-size: 10px;
  color: var(--muted);
  transform: rotate(-45deg);
  white-space: nowrap;
}

.productivity-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.chart-section h4 {
  margin: 0 0 12px 0;
  font-size: 16px;
  font-weight: 600;
}

/* Estimation accuracy styles */
.estimation-tasks {
  margin-top: 24px;
}

.estimation-task {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
}

.task-info {
  flex: 1;
}

.task-title {
  font-weight: 500;
  margin-bottom: 4px;
}

.task-times {
  font-size: 12px;
  color: var(--muted);
}

.accuracy-indicator {
  font-size: 18px;
  padding: 4px;
  border-radius: 50%;
}

.accuracy-indicator.good {
  background: var(--success-bg);
}

.accuracy-indicator.fair {
  background: #fff3e0;
}

.accuracy-indicator.poor {
  background: var(--error-bg);
}

[data-theme="dark"] .accuracy-indicator.fair {
  background: #3a3022;
}

/* Project progress styles */
.project-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.project-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

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

.project-header h4 {
  margin: 0;
  font-size: 16px;
}

.progress-bar {
  position: relative;
  width: 120px;
  height: 20px;
  background: var(--surface-2);
  border-radius: 10px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(
    90deg,
    var(--status-done),
    color-mix(in srgb, var(--status-done) 60%, var(--surface))
  );
  transition: width 0.3s ease;
}

.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}

.project-stats {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--muted);
}

/* AI Reflection styles */
.reflection-section {
  max-width: 800px;
}

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

.reflection-header h3 {
  margin: 0;
}

.daily-summary {
  margin-bottom: 24px;
}

.daily-summary h4 {
  margin: 0 0 16px 0;
}

.ai-reflection {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
}

.ai-reflection h4 {
  margin: 0 0 16px 0;
  color: var(--text);
}

.reflection-text {
  line-height: 1.6;
  color: var(--text);
}

.reflection-text div {
  margin-bottom: 8px;
}

@media (max-width: 800px) {
  .productivity-charts {
    grid-template-columns: 1fr;
  }

  .chart-container {
    height: 150px;
    padding: 12px;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .project-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .progress-bar {
    width: 100%;
  }

  .reflection-header {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }
}
