:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --bg-3: #334155;
  --fg: #f1f5f9;
  --fg-dim: #94a3b8;
  --accent: #3b82f6;
  --accent-fg: #ffffff;
  --green: #10b981;
  --red: #ef4444;
  --border: #334155;
  --radius: 12px;
  --header-h: 52px;
}

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

html,
body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button {
  font-family: inherit;
}

a {
  color: var(--accent);
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-header h1 {
  font-size: 17px;
  font-weight: 600;
}

.app-header nav {
  display: flex;
  gap: 4px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 20px;
  cursor: pointer;
  padding: 6px 10px;
  text-decoration: none;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 36px;
}

.icon-btn:active {
  background: var(--bg-3);
}

/* ===== Main / split layout ===== */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.section-label {
  font-size: 11px;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
  font-weight: 600;
}

/* Upper: active timers (pinned below header) */
.active-section {
  padding: 14px 16px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--header-h);
  z-index: 10;
  display: none;
}

.active-section.has-timers {
  display: block;
}

.active-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.timer-card {
  background: var(--bg-2);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.timer-card .meta {
  flex: 1;
  min-width: 0;
}

.timer-card .project-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timer-card .task-name {
  font-size: 12px;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.timer-card .clock {
  font-family: "SF Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 600;
  color: var(--green);
}

/* Lower: projects */
.projects-section {
  padding: 16px;
  flex: 1;
}

.projects-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.project-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-2);
  padding: 14px 16px;
  border-radius: var(--radius);
  border-left: 4px solid var(--accent);
  gap: 12px;
  min-width: 0;
}

.project-row .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-row .name {
  font-weight: 500;
  flex: 1;
  cursor: pointer;
  user-select: none;
}

/* Toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--bg-3);
  transition: background-color 0.2s;
  border-radius: 999px;
}

.slider::before {
  position: absolute;
  content: "";
  height: 24px;
  width: 24px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.switch input:checked + .slider {
  background: var(--green);
}

.switch input:checked + .slider::before {
  transform: translateX(22px);
}

.actions {
  display: grid;
  gap: 8px;
  margin-top: 20px;
}

.empty-state {
  color: var(--fg-dim);
  font-size: 14px;
  text-align: center;
  padding: 20px 12px;
}

/* Today's entries (below projects) */
.entries-section {
  padding: 0 16px 20px;
}

.entries-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
}

.entry-row {
  background: var(--bg-2);
  padding: 10px 14px;
  border-radius: var(--radius);
  border-left: 4px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  min-width: 0;
}

.entry-row:active {
  background: var(--bg-3);
}

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

.entry-row .project-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-row .task-name {
  font-size: 13px;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-row .entry-time-range {
  font-size: 11px;
  color: var(--fg-dim);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.entry-row .entry-dur {
  font-family: "SF Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}

.entry-row.source-manual {
  border-left-style: dashed;
}

/* ===== Buttons ===== */
.btn-primary,
.btn-secondary,
.btn-danger {
  border: none;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

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

.btn-secondary {
  background: var(--bg-2);
  color: var(--fg);
  border: 1px solid var(--border);
}

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

.btn-primary:active {
  filter: brightness(0.9);
}

.btn-primary.big {
  padding: 16px 24px;
  font-size: 17px;
  width: 100%;
}

/* ===== Modals ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.modal[hidden] {
  display: none;
}

.modal-content {
  background: var(--bg-2);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  display: grid;
  gap: 12px;
}

.modal-content h3 {
  font-size: 18px;
}

.modal-subtitle {
  color: var(--fg-dim);
  font-size: 13px;
  margin-top: -8px;
}

.modal-content label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--fg-dim);
}

.modal-content input,
.modal-content select {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 12px;
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
}

.modal-content input[type="color"] {
  padding: 4px;
  height: 44px;
}

.modal-content input:focus,
.modal-content select:focus {
  outline: none;
  border-color: var(--accent);
}

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

.modal-actions .btn-danger {
  margin-right: auto;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.task-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.task-suggestions button {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg-dim);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}

.task-suggestions button:hover {
  color: var(--fg);
}

/* ===== Auth pages ===== */
.auth-body {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  background: var(--bg-2);
  border-radius: 16px;
  padding: 32px 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  display: grid;
  gap: 18px;
  margin: auto;
}

.auth-card h1 {
  font-size: 26px;
}

.auth-card section {
  display: grid;
  gap: 14px;
}

.auth-tagline {
  color: var(--fg-dim);
  font-size: 14px;
}

.auth-card label {
  display: grid;
  gap: 6px;
  text-align: left;
  font-size: 13px;
  color: var(--fg-dim);
}

.auth-card input {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 12px;
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
}

.auth-card details summary {
  cursor: pointer;
  color: var(--fg-dim);
  font-size: 13px;
}

.auth-card details a {
  color: var(--accent);
}

.status {
  font-size: 13px;
  min-height: 18px;
  color: var(--fg-dim);
}

.status.error {
  color: var(--red);
}

.status.success {
  color: var(--green);
}

/* ===== Reports ===== */
.reports-main {
  padding: 16px;
  display: grid;
  gap: 16px;
}

.range-picker {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 12px;
}

.range-picker label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--fg-dim);
}

.range-picker input,
.range-picker select {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px;
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}

.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.preset-buttons button {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}

.preset-buttons button:active {
  background: var(--accent);
  color: white;
}

.total-section {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 16px;
}

.total-display {
  font-family: "SF Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 36px;
  font-weight: 600;
  color: var(--green);
  margin-top: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-2);
  border-radius: var(--radius);
  overflow: hidden;
}

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

tr:last-child th,
tr:last-child td {
  border-bottom: none;
}

th {
  color: var(--fg-dim);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td:last-child,
th:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
