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

:root {
  --color-primary: #4F46E5;
  --color-primary-hover: #4338CA;
  --color-primary-light: #EEF2FF;
  --color-bg: #F9FAFB;
  --color-surface: #FFFFFF;
  --color-border: #E5E7EB;
  --color-text: #111827;
  --color-text-secondary: #6B7280;
  --color-success: #10B981;
  --color-success-hover: #059669;
  --color-danger: #EF4444;
  --color-danger-hover: #DC2626;
  --color-warning: #F59E0B;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sidebar-width: 200px;
  --header-height: 56px;
}

[data-theme="dark"] {
  --color-bg: #0F172A;
  --color-surface: #1E293B;
  --color-border: #334155;
  --color-text: #F1F5F9;
  --color-text-secondary: #94A3B8;
  --color-primary-light: #1E1B4B;
}

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

/* === Header === */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--header-height) + env(safe-area-inset-top));
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top) calc(24px + env(safe-area-inset-right)) 0 calc(24px + env(safe-area-inset-left));
  z-index: 100;
  transition: background 0.2s, border-color 0.2s;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--color-text);
  transition: background 0.2s, border-color 0.2s;
}

.theme-toggle:hover {
  background: var(--color-primary-light);
}

/* === Layout === */
.layout {
  min-height: 100vh;
  padding-top: calc(var(--header-height) + env(safe-area-inset-top));
  padding-left: var(--sidebar-width);
}

/* === Sidebar === */
.sidebar {
  position: fixed;
  top: calc(var(--header-height) + env(safe-area-inset-top));
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background 0.2s, border-color 0.2s;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: none;
  background: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  transition: background 0.15s, color 0.15s;
  width: 100%;
  text-align: left;
}

@media (hover: hover) {
  .nav-btn:hover {
    background: var(--color-primary-light);
    color: var(--color-text);
  }
}

.nav-btn.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: 600;
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
}

/* === Main Content === */
.main {
  padding: 32px;
  max-width: 800px;
  width: 100%;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* === Common Elements === */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-header .section-title {
  margin-bottom: 0;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
  letter-spacing: -0.3px;
}

.section-subtitle {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input {
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s, background 0.2s;
  width: 100%;
}

.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
  margin-top: 12px;
}

.btn {
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  background: var(--color-surface);
  color: var(--color-text);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

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

.btn:active {
  transform: scale(0.97);
}

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

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

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

.btn-cancel {
  background: none;
  color: var(--color-text-secondary);
}

.btn-cancel:hover {
  color: var(--color-text);
}

.btn-danger {
  color: var(--color-danger);
  border-color: transparent;
  background: none;
  padding: 4px 8px;
}

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

.hidden {
  display: none !important;
}

/* === Timer === */
.timer-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: background 0.2s, border-color 0.2s;
}

.timer-display {
  font-size: 64px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  margin-bottom: 24px;
  color: var(--color-text);
  line-height: 1;
}

.timer-display.running {
  color: var(--color-success);
}

.timer-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 400px;
  margin: 0 auto 24px;
}

.project-select {
  cursor: pointer;
}

.project-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.project-btn {
  padding: 6px 16px;
  border: 2px solid;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  font-family: var(--font);
}

.project-btn:hover {
  opacity: 0.85;
}

.project-btn:active {
  transform: scale(0.95);
}

.project-btn.active {
  color: #fff;
}

.btn-start {
  background: var(--color-success);
  color: #fff;
  border: none;
  padding: 14px 48px;
  font-size: 16px;
  font-weight: 700;
  border-radius: var(--radius-lg);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.btn-start:hover {
  background: var(--color-success-hover);
}

.btn-stop {
  background: var(--color-danger);
  color: #fff;
  border: none;
  padding: 14px 48px;
  font-size: 16px;
  font-weight: 700;
  border-radius: var(--radius-lg);
  letter-spacing: 1px;
  text-transform: uppercase;
}

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

/* Tags */
.tag-input-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 6px 10px;
  background: var(--color-surface);
  transition: border-color 0.15s;
}

.tag-input-wrapper:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.tag-input {
  border: none;
  padding: 2px 0;
  flex: 1;
  min-width: 100px;
  box-shadow: none !important;
}

.tag-input:focus {
  box-shadow: none !important;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--color-primary-light);
  color: var(--color-primary);
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
}

.tag-pill button {
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  opacity: 0.6;
}

.tag-pill button:hover {
  opacity: 1;
}

/* Today section */
.today-section {
  margin-top: 32px;
}

.today-total {
  margin-top: 12px;
  font-weight: 600;
  font-size: 15px;
  color: var(--color-text-secondary);
  text-align: right;
}

/* === Entry List === */
.entry-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.entry-group-date {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-top: 20px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--color-border);
}

.entry-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  transition: background 0.15s, border-color 0.2s;
}

.entry-row:hover {
  border-color: var(--color-primary);
}

.entry-color {
  width: 4px;
  height: 32px;
  border-radius: 2px;
  flex-shrink: 0;
}

.entry-time {
  font-size: 13px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  min-width: 100px;
}

.entry-project {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  white-space: nowrap;
}

.entry-desc {
  flex: 1;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-duration {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.entry-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}

.entry-row:hover .entry-actions {
  opacity: 1;
}

.entry-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 14px;
  color: var(--color-text-secondary);
  transition: background 0.15s, color 0.15s;
}

.entry-action-btn:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.entry-action-btn.delete:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--color-danger);
}

.entry-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.entry-tag {
  font-size: 11px;
  color: var(--color-text-secondary);
  background: var(--color-bg);
  padding: 1px 6px;
  border-radius: 99px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-secondary);
}

.empty-state-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.empty-state-text {
  font-size: 14px;
}

/* === Filters (History) === */
.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.filters > * {
  min-width: 0;
}

/* iPhone date boxes otherwise keep a fixed width and spill over their neighbours */
input[type="date"].input {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  min-width: 0;
  min-height: 38px;
  line-height: 1.3;
}

input[type="date"].input::-webkit-date-and-time-value {
  text-align: left;
}

/* === Reports === */
.report-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.report-view-toggle {
  display: flex;
  gap: 4px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 3px;
}

.report-view-toggle .btn-sm {
  border: none;
  background: none;
  border-radius: 6px;
}

.report-view-toggle .btn-sm.active {
  background: var(--color-primary);
  color: #fff;
}

.report-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.report-period {
  font-size: 14px;
  font-weight: 600;
  min-width: 180px;
  text-align: center;
}

.report-total {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 32px;
}

.report-section {
  margin-bottom: 32px;
}

/* Bar chart */
.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bar-label {
  font-size: 13px;
  font-weight: 500;
  min-width: 120px;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  flex: 1;
  height: 28px;
  background: var(--color-bg);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
}

.bar-fill {
  height: 100%;
  transition: width 0.4s ease;
  min-width: 2px;
}

.bar-fill:first-child {
  border-radius: 6px 0 0 6px;
}

.bar-fill:last-child {
  border-radius: 0 6px 6px 0;
}

.bar-fill:only-child {
  border-radius: 6px;
}

.bar-value {
  font-size: 13px;
  font-weight: 600;
  min-width: 70px;
  font-variant-numeric: tabular-nums;
}

/* === Projects === */
.project-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 24px;
}

.project-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}

.project-row:hover {
  border-color: var(--color-primary);
}

.project-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.project-name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
}

.project-form {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.project-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.color-input {
  width: 60px;
  height: 36px;
  padding: 2px;
  cursor: pointer;
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 90%;
  max-width: 440px;
  max-height: calc(100% - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

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


/* === Notes (patient note tally) === */
.notes-daynav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.notes-date-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.notes-date {
  font-weight: 700;
  font-size: 16px;
}

.notes-today-link {
  border: none;
  background: none;
  color: var(--color-primary);
  font-size: 13px;
  cursor: pointer;
  padding: 2px;
}

.notes-total-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  font-weight: 700;
  margin-bottom: 12px;
}

[data-theme="dark"] .notes-total-banner,
[data-theme="dark"] .notes-cell {
  color: #C7D2FE;
}

.notes-total-banner span:last-child {
  font-size: 20px;
}

.notes-prod-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.notes-prod-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--color-success);
}

.notes-prod-unit {
  font-size: 15px;
  font-weight: 600;
}

.notes-prod-detail {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin: 2px 0 10px;
}

.notes-prod-project {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--color-text-secondary);
}

.notes-prod-project .input {
  flex: 1;
  padding: 6px 10px;
}

.notes-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.notes-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.notes-grid {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.notes-grid th:first-child,
.notes-grid td:first-child {
  width: 40%;
}

.notes-grid th {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  padding: 4px;
}

.notes-grid td {
  padding: 5px 4px;
  text-align: center;
  font-size: 15px;
}

.notes-grid td:first-child {
  text-align: left;
}

.notes-cell {
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: var(--radius);
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  transition: transform 0.08s;
}

.notes-cell:active {
  transform: scale(0.94);
}

.notes-hint {
  font-size: 12px;
  color: var(--color-text-secondary);
  text-align: center;
  margin-top: 8px;
}

.notes-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 15px;
}

.notes-row + .notes-row {
  border-top: 1px solid var(--color-border);
}

.notes-stepper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.notes-step {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 20px;
  cursor: pointer;
  touch-action: manipulation;
}

.notes-step-add {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.notes-count {
  min-width: 24px;
  text-align: center;
  font-weight: 700;
  font-size: 17px;
}

.notes-undo {
  display: block;
  margin: 0 auto 20px;
}

.notes-undo:disabled {
  opacity: 0.4;
  cursor: default;
}

.notes-totals .report-controls {
  margin-bottom: 12px;
}

.notes-avg {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin: -6px 0 12px;
  text-align: right;
}

.notes-totals .section-subtitle {
  margin-top: 12px;
}

.notes-total-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 7px 0;
  font-size: 14px;
  border: none;
  border-bottom: 1px solid var(--color-border);
  background: none;
  color: var(--color-text);
  font-family: inherit;
  text-align: left;
}

.notes-total-row span:last-child {
  font-weight: 700;
}

.notes-day-link {
  cursor: pointer;
}

/* === Responsive === */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
  }

  .layout {
    grid-template-columns: 1fr;
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }

  .header {
    padding-left: calc(16px + env(safe-area-inset-left));
    padding-right: calc(16px + env(safe-area-inset-right));
  }

  /* 16px stops iPhone from zooming in when a text box is tapped */
  .input,
  select,
  textarea {
    font-size: 16px;
  }

  body {
    -webkit-tap-highlight-color: transparent;
  }

  .sidebar {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: calc(60px + env(safe-area-inset-bottom));
    border-right: none;
    border-top: 1px solid var(--color-border);
    flex-direction: row;
    justify-content: space-between;
    gap: 4px;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    z-index: 100;
  }

  .nav-btn {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px 2px;
    font-size: 11px;
    line-height: 1.2;
    -webkit-tap-highlight-color: transparent;
  }

  .nav-btn.active {
    font-weight: 500;
  }

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

  .nav-label {
    white-space: nowrap;
  }

  .main {
    padding: 20px 16px;
  }

  .timer-display {
    font-size: 42px;
  }

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

  .report-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .report-nav {
    justify-content: center;
  }

  .bar-label {
    min-width: 80px;
    font-size: 12px;
  }

  .entry-time {
    min-width: auto;
  }

  .entry-desc {
    display: none;
  }

  .entry-actions {
    opacity: 1;
  }
}
