/* ============================================================
   ApexRoutine — style.css
   Pure dark theme (#0d0d0d). Orange gradient accents.
   Mobile-first, fully responsive (320px -> desktop), no h-scroll.
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  --bg: #0d0d0d;
  --card: #1a1a1a;
  --card-2: #202020;
  --border: #2a2a2a;
  --border-soft: #232323;

  --text: #f2f2f2;
  --text-soft: #cfcfcf;
  --muted: #8a8a8a;

  --accent-1: #ff8a00;
  --accent-2: #ff5e00;
  --gradient: linear-gradient(120deg, var(--accent-1), var(--accent-2));
  --accent-glow: rgba(255, 138, 0, 0.16);

  --ok: #34d17b;
  --danger: #ff5e5e;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);

  --font: "Inter", "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;

  --gap: 14px;
  --pad: 18px;
  --container: 980px;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent-1);
  outline-offset: 2px;
  border-radius: 6px;
}

img {
  max-width: 100%;
  height: auto;
}

/* ---------- Layout ---------- */
.site {
  max-width: var(--container);
  margin: 0 auto;
  padding: clamp(12px, 3vw, 28px);
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--pad);
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

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

.brand-icon {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  filter: drop-shadow(0 4px 14px var(--accent-glow));
}

.brand-name {
  font-size: clamp(20px, 4.5vw, 26px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-tag {
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.clock {
  text-align: right;
  min-width: 0;
}

.clock-time {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: clamp(18px, 4.5vw, 24px);
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.clock-date {
  color: var(--muted);
  font-size: 12.5px;
}

/* ---------- Current task ---------- */
.current {
  --ring: transparent;
  position: relative;
  border-color: var(--border);
}

.current.is-active {
  border-color: transparent;
  background:
    linear-gradient(var(--card), var(--card)) padding-box,
    var(--gradient) border-box;
  box-shadow: 0 10px 34px var(--accent-glow);
}

.current-label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--accent-1);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.current-title {
  margin-top: 6px;
  font-size: clamp(19px, 5vw, 27px);
  letter-spacing: -0.01em;
  word-wrap: break-word;
}

.current-range {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.current-progress {
  margin-top: 14px;
}

/* ---------- Progress bars ---------- */
.progress {
  height: 8px;
  border-radius: 999px;
  background: #262626;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--gradient);
  transition: width 0.45s ease;
  width: 0%;
}

/* ---------- Stats ---------- */
.stats {
  display: grid;
  gap: var(--gap);
  grid-template-columns: 1fr;
}

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

.stat-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12.5px;
}

/* ---------- Icons ---------- */
.ico {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.ico-sm {
  width: 15px;
  height: 15px;
}

/* ---------- Settings ---------- */
.settings {
  padding: 0;
  overflow: hidden;
}

.settings-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: var(--pad);
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  text-align: left;
}

.settings-toggle .ico {
  color: var(--accent-1);
}

.toggle-arrow {
  margin-left: auto;
  color: var(--muted);
  transition: transform 0.2s ease;
}

.settings[data-open="true"] .toggle-arrow {
  transform: rotate(180deg);
}

.settings-body {
  padding: 0 var(--pad) var(--pad);
}

.settings-hint {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 14px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
  letter-spacing: 0.04em;
}

.field input {
  width: 100%;
  min-width: 0;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  color: var(--text);
  transition: border-color 0.15s ease;
}

.field input:focus {
  border-color: var(--accent-1);
  outline: none;
}

.field input[readonly] {
  color: var(--muted);
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
}

.settings-status {
  color: var(--muted);
  font-size: 13px;
  min-height: 1em;
  word-break: break-word;
}

.settings-status.ok {
  color: var(--ok);
}

.settings-status.err {
  color: var(--danger);
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 600;
  transition: filter 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--gradient);
  color: #0d0d0d;
  box-shadow: 0 6px 18px var(--accent-glow);
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-ghost {
  border: 1px solid var(--border);
  color: var(--text-soft);
  background: var(--card-2);
}

.btn-ghost:hover {
  border-color: var(--accent-1);
  color: var(--accent-1);
}

.btn-sm {
  padding: 7px 10px;
  font-size: 12.5px;
}

.btn-icon {
  gap: 6px;
}

/* ---------- Section head ---------- */
.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 6px 0 4px;
}

.section-head h2 {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.section-day {
  color: var(--muted);
  font-size: 12.5px;
  text-transform: capitalize;
}

.section-head .btn {
  margin-left: auto;
}

/* ---------- Timeline ---------- */
.timeline {
  list-style: none;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: 10px 0 4px;
}

/* The vertical connector line. */
.timeline::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 18px;
  bottom: 18px;
  width: 2px;
  background: linear-gradient(var(--accent-1), var(--border), var(--accent-2));
  opacity: 0.55;
  border-radius: 2px;
}

.tli {
  position: relative;
  min-width: 0;
}

.tli-dot {
  position: absolute;
  left: 7px;
  top: 30px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--card-2);
  border: 2px solid var(--border);
  z-index: 1;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.tli.is-active .tli-dot {
  background: var(--accent-2);
  border-color: var(--accent-1);
  box-shadow: 0 0 0 5px var(--accent-glow);
}

.tli.is-done .tli-dot {
  background: var(--ok);
  border-color: var(--ok);
}

/* ---------- Task card ---------- */
.task {
  margin-left: 28px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.task.is-active {
  border-color: transparent;
  background:
    linear-gradient(var(--card), var(--card)) padding-box,
    var(--gradient) border-box;
}

.task.is-done {
  opacity: 0.82;
}

.task.is-done .task-title {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: rgba(255, 255, 255, 0.35);
}

.task-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.task-time {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent-1);
  font-size: 12.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.task-title {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  word-break: break-word;
}

.task-desc {
  color: var(--muted);
  font-size: 13px;
  word-break: break-word;
}

/* Badge */
.badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.badge.st-not-started {
  color: var(--muted);
}

.badge.st-in-progress {
  color: #fff;
  border: none;
  background: var(--gradient);
}

.badge.st-completed {
  color: #06280f;
  border: none;
  background: var(--ok);
}

/* ---------- Task actions ---------- */
.task-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

/* Checkbox */
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.check-box {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 2px solid var(--border);
  display: grid;
  place-items: center;
  color: transparent;
  transition: border-color 0.15s ease, background 0.15s ease;
  flex-shrink: 0;
}

.check-box svg {
  width: 14px;
  height: 14px;
}

.check input:checked + .check-box {
  background: var(--gradient);
  border-color: transparent;
  color: #0d0d0d;
}

.check input:focus-visible + .check-box {
  outline: 2px solid var(--accent-1);
  outline-offset: 2px;
}

.check-label {
  font-size: 13px;
  color: var(--text-soft);
}

.check input:checked ~ .check-label {
  color: var(--ok);
}

/* ---------- Popovers (snooze / reschedule) ---------- */
.pop {
  position: relative;
}

.pop-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 8px);
  left: 0;
  min-width: 168px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pop-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 4px 8px 6px;
}

.pop-item {
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-soft);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.pop-item:hover {
  background: var(--accent-glow);
  color: var(--accent-1);
}

.resched-menu {
  min-width: 236px;
}

.resched-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.resched-input {
  flex: 1;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 9px;
  color-scheme: dark;
}

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 10px 0 16px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(20px);
  background: var(--card-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-1);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13.5px;
  max-width: min(92vw, 420px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 60;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.ok {
  border-left-color: var(--ok);
}

.toast.err {
  border-left-color: var(--danger);
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* ---------- Tablet (>=600px) ---------- */
@media (min-width: 600px) {
  :root {
    --pad: 22px;
    --gap: 16px;
  }

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

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

  .field-grid .field:first-child {
    grid-column: span 2;
  }
}

/* ---------- Desktop (>=860px) ---------- */
@media (min-width: 860px) {
  :root {
    --container: 1020px;
  }

  .site {
    padding-top: 40px;
    padding-bottom: 40px;
  }

  .task-title {
    font-size: 16.5px;
  }
}

/* ---------- Small (<=359px) safety ---------- */
@media (max-width: 359px) {
  :root {
    --pad: 14px;
  }

  .section-head .btn {
    margin-left: 0;
    flex: 1 1 100%;
  }

  .settings-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-row {
    width: 100%;
  }

  .btn-row .btn {
    flex: 1;
  }
}