/* Time Tracker — app styles. Colours, type and sizes come from design/tokens.css. */
:root {
  --danger: #FF453A; /* "Still running?" banner only (docs/SPEC.md edge cases) */
  --tabbar-h: 50px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body { touch-action: manipulation; }
button { font-family: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */
.app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 520px; /* Phase 1: same layout on Mac, centred. Side-by-side Mac layout is Phase 2. */
  margin: 0 auto;
}
@media (min-width: 560px) {
  .app { border-left: 1px solid var(--track); border-right: 1px solid var(--track); }
}

.content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top) + 12px) calc(24px + env(safe-area-inset-right)) 24px calc(24px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
}

.row-between { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.row-between.center { align-items: center; }
.label { font-size: 13px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); }
.muted { color: var(--text-muted); font-size: 15px; }
.small { font-size: 13px; }
.center-text { text-align: center; }
.accent { color: var(--accent); }
h1 { margin: 0; font-size: 30px; font-weight: 600; letter-spacing: -0.01em; }
h2 { margin: 0; font-size: 20px; font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
.ico { fill: none; stroke: currentColor; stroke-width: 2px; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Timer ---------- */
.timer { flex: 1; display: flex; flex-direction: column; align-items: center; padding-top: 12px; }
.timer > .row-between, .timer > .notice { align-self: stretch; }

.counter {
  margin-top: 72px;
  font-size: var(--counter-size);
  font-weight: 200;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.subline { margin-top: 14px; min-height: 20px; }

.btn-group {
  margin-top: 52px;
  position: relative;
  flex-shrink: 0;
  width: var(--ring-size);
  height: var(--ring-size);
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-group svg { position: absolute; inset: 0; transform: rotate(-90deg); pointer-events: none; }
.ring-track { fill: none; stroke: var(--track); stroke-width: 4px; }
.ring { fill: none; stroke-width: 6px; stroke-linecap: round; transition: stroke var(--motion); }

.big {
  position: relative;
  width: var(--start-size);
  height: var(--start-size);
  border-radius: 50%;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.16em;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  transition: transform var(--motion), background var(--motion), box-shadow var(--motion);
}
.big.enter { animation: big-in var(--motion) backwards; } /* not "both": a held transform would block :active */
@keyframes big-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
.big:focus-visible { outline: 2px solid var(--text); outline-offset: 6px; }
.start {
  border: none;
  background: var(--accent);
  color: var(--bg);
  box-shadow: 0 0 0 10px var(--accent-halo), 0 18px 60px var(--accent-glow);
}
.start:active { transform: scale(0.97); }
.finish {
  border: 2px solid var(--accent);
  background: var(--surface-2);
  color: var(--accent);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.finish small { font-size: 12px; font-weight: 500; letter-spacing: 0.08em; color: var(--text-muted); }
.finish.holding { transform: scale(0.97); }

.today {
  margin-top: auto;
  align-self: stretch;
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.today b { font-size: 17px; font-variant-numeric: tabular-nums; }
.btn-group { margin-bottom: 24px; } /* keeps a gap above the card on short screens */

/* ---------- Notices ---------- */
.notice {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-soft);
}
.notice b { color: var(--text); }
.notice.danger { border-color: var(--danger); background: rgba(255, 69, 58, 0.1); }
.notice.danger b { color: var(--danger); }
.link { display: inline-block; background: none; border: none; padding: 12px 4px; margin: -12px 0 -12px 2px; color: var(--accent); font-weight: 600; font-size: 14px; line-height: 20px; cursor: pointer; } /* 44 px tap target without stretching the line */

/* ---------- History ---------- */
.stack { display: flex; flex-direction: column; gap: 20px; padding-top: 12px; }
.export {
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font: 600 14px var(--font);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.export:active { background: var(--accent-tint); }
.cols, .hrow { display: grid; grid-template-columns: 1.25fr 1fr 1fr 0.8fr; gap: 4px; }
.cols { padding: 0 17px; font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); }
.cols .r { text-align: right; }
.hrow {
  position: relative;
  width: 100%;
  min-height: 52px;
  align-items: center;
  padding: 14px 16px;
  border: none;
  background: var(--surface);
  color: var(--text);
  font: 400 15px var(--font);
  font-variant-numeric: tabular-nums;
  text-align: left;
  white-space: nowrap;
}
button.hrow { cursor: pointer; touch-action: pan-y; transition: transform var(--motion), background var(--motion); }
button.hrow:active { background: var(--surface-2); }
button.hrow:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.hrow .sub { grid-column: 1 / -1; margin-top: 4px; font-size: 13px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }
.list > * + * { border-top: 1px solid var(--divider); }
.swipe { position: relative; overflow: hidden; }
.swipe-del {
  position: absolute; inset: 0 0 0 auto; width: 88px; z-index: 0; /* hidden behind the opaque row */
  border: none; background: var(--danger); color: #fff;
  font: 600 15px var(--font); cursor: pointer;
}
.new { animation: fade-in 150ms ease-out both; }
.hint { margin: -4px 4px 0; }
.hrow .d { font-weight: 600; }
.hrow .h { font-weight: 600; text-align: right; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.week { display: flex; flex-direction: column; gap: 8px; }
.week-head { padding: 0 4px; }
.week-label { letter-spacing: 0.08em; }
.week-total { font-size: 15px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.card.list { overflow: hidden; }
.empty { margin: 8px 4px; }

/* ---------- Settings ---------- */
.set { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px; min-height: 52px; font-size: 15px; }
.set-btn { width: 100%; background: none; border: none; border-top: 1px solid var(--divider); text-align: left; cursor: pointer; font: inherit; font-size: 15px; color: var(--text); }
.set-btn:active { background: var(--surface-2); }

/* ---------- Tab bar ---------- */
.tabbar {
  flex-shrink: 0;
  height: calc(var(--tabbar-h) + max(env(safe-area-inset-bottom), 14px));
  padding-bottom: max(env(safe-area-inset-bottom), 14px);
  border-top: 1px solid var(--track);
  background: var(--bg-bar);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
.tabbar button {
  background: none;
  border: none;
  font: 600 11px var(--font);
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  min-height: 44px;
  transition: color var(--motion);
}
.tabbar button[aria-current="page"] { color: var(--accent); }
.tabbar svg { fill: none; stroke: currentColor; stroke-width: 1.8px; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Toast ---------- */
.toast {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 8px);
  left: 50%;
  transform: translate(-50%, -12px);
  opacity: 0;
  background: var(--toast);
  border: 1px solid var(--toast-border);
  border-radius: var(--radius-pill);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 5;
  pointer-events: none;
  transition: opacity var(--motion), transform var(--motion);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.toast:empty { display: none; }
.toast.has-action { pointer-events: auto; padding: 6px 6px 6px 18px; }
.toast-action {
  min-height: 36px; padding: 0 14px; margin-left: 4px;
  border: none; border-radius: var(--radius-pill);
  background: var(--accent-tint); color: var(--accent);
  font: 600 14px var(--font); cursor: pointer;
}

/* ---------- Export sheet ---------- */
.sheet {
  width: 100%;
  max-width: 520px;
  margin: auto auto 0;
  padding: 0;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
}
@media (min-width: 560px) {
  .sheet { margin: auto; border-radius: 20px; border-bottom: 1px solid var(--border); }
}
.sheet { max-height: 92vh; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain; }
.sheet::backdrop { background: rgba(0, 0, 0, 0.6); }
.sheet[open] { animation: sheet-in var(--motion) both; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
.sheet-body {
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.icon-btn { width: 44px; height: 44px; margin: -10px -10px -10px 0; border: none; background: none; color: var(--text-muted); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font: 500 14px var(--font);
  cursor: pointer;
}
.pill[aria-pressed="true"] { border-color: var(--accent-tint); background: var(--accent-tint); color: var(--accent); font-weight: 600; }
.custom-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.custom-dates label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.custom-dates input {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: 400 16px var(--font); /* 16px stops iOS zooming on focus */
  color-scheme: dark;
}
.summary { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; background: var(--bg); }
.summary-main { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.primary {
  min-height: 52px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: var(--bg);
  font: 600 17px var(--font);
  cursor: pointer;
}
.primary:disabled { opacity: 0.35; cursor: default; }
.primary:not(:disabled):active { transform: scale(0.98); }

/* ---------- Small / short screens ---------- */
@media (max-height: 740px) {
  .counter { margin-top: 40px; }
  .btn-group { margin-top: 36px; }
}
@media (max-width: 360px) {
  .hrow { font-size: 14px; padding: 14px 12px; }
}

/* ---------- Reduced motion: fades only ---------- */
@media (prefers-reduced-motion: reduce) {
  .big, .start:active, .finish.holding, .primary:not(:disabled):active { transform: none !important; }
  .big.enter { animation: fade-in var(--motion) backwards; }
  .sheet[open] { animation: fade-in var(--motion) backwards; }
  .toast, .toast.show { transform: translate(-50%, 0); }
  button.hrow { transition: background var(--motion); }
}

/* ---------- Swipe: the Delete button sits behind the sliding row ---------- */
.swipe .hrow { z-index: 1; }
.swipe:not(.is-open) .swipe-del { visibility: hidden; } /* no red sub-pixel edge while closed */

/* ---------- Job / employee chips ---------- */
.chips { align-self: stretch; display: flex; gap: 8px; justify-content: center; margin-top: 24px; }
.chip {
  min-height: 44px; max-width: calc(50% - 4px); min-width: 0;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font: 500 14px var(--font);
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer;
}
.chip-k { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.chip-v { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.set .chip-v { color: var(--text); }
.has-chips .btn-group { margin-top: 28px; }

/* ---------- Settings controls ---------- */
.settings .set { flex-wrap: wrap; }
.seg { display: inline-flex; padding: 2px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.seg button {
  min-height: 40px; min-width: 44px; padding: 0 12px;
  border: none; border-radius: 8px; background: transparent;
  color: var(--text-muted); font: 500 14px var(--font); cursor: pointer;
  transition: background var(--motion), color var(--motion);
}
.seg button[aria-pressed="true"] { background: var(--accent-tint); color: var(--accent); font-weight: 600; }
.switch {
  position: relative; width: 52px; height: 32px; flex-shrink: 0;
  border: none; border-radius: 16px; background: var(--track); cursor: pointer;
  transition: background var(--motion);
}
.switch span {
  position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--text); transition: transform var(--motion);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] span { transform: translateX(20px); }
.switch:focus-visible, .seg button:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.set-input {
  width: 50%; min-width: 140px; min-height: 40px; padding: 0 12px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font: 400 16px var(--font); text-align: right;
}
.set-input::placeholder { color: var(--text-muted); }

/* ---------- Sheet forms ---------- */
.fields { display: flex; flex-direction: column; gap: 12px; }
.fields label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.fields input, .custom-dates input {
  min-height: 44px; padding: 0 12px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
  font: 400 16px var(--font); /* 16px stops iOS zooming on focus */
  color-scheme: dark;
  width: 100%;
}
.fields input:focus-visible, .set-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.error { color: var(--danger); min-height: 0; }
.error:empty { display: none; }
.sheet-text { margin: 0; font-size: 15px; line-height: 1.45; color: var(--text-soft); }
.secondary, .danger-btn {
  min-height: 48px; border-radius: 14px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text); font: 600 16px var(--font); cursor: pointer;
}
.danger-btn { color: var(--danger); }
.secondary:active, .danger-btn:active { background: var(--surface-2); }

/* ---------- Mac layout: Timer left, History right (>= 900 px) ---------- */
.mac-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.mac-head h1 { font-size: 28px; }
.mac-head .pills { align-items: center; }
.mac-head .pill { min-height: 32px; height: 32px; padding: 0 14px; font-size: 13px; }
.mac-head .export { min-height: 32px; height: 32px; font-size: 13px; margin-left: 8px; }
.gear { margin: 0; width: 36px; height: 36px; border-radius: 50%; }
.gear:hover { background: var(--surface); color: var(--text); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.tablecard { overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; table-layout: fixed; }
th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); padding: 12px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 9px 14px; border-top: 1px solid #1E1E22; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
th:first-child, td:first-child { padding-left: 20px; }
th:nth-child(1) { width: 25%; }
th:nth-child(2) { width: 25%; }
th:nth-child(3), th:nth-child(4) { width: 17%; }
th:nth-child(5) { width: 16%; }
td:first-child { font-weight: 600; }
td:nth-child(2) { color: var(--text-soft); }
th:nth-child(5), td:nth-child(5) { text-align: right; }
td:nth-child(5) { font-weight: 600; }
th.act, td.act { width: 52px; padding: 0 8px; text-align: right; }
td .sub { margin-left: 6px; color: var(--text-muted); font-size: 12px; }
tr.wk td { background: var(--surface-week); border-top: none; padding: 12px 14px 6px 20px; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
tr.wk td:nth-child(2) { color: var(--accent); font-size: 14px; letter-spacing: 0; text-transform: none; text-align: right; padding-left: 14px; }
tr.shift { cursor: pointer; transition: background var(--motion); }
tr.shift:hover, tr.shift:focus-visible { background: var(--surface-2); outline: none; }
tr.shift:focus-visible td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
tr.day-total td { padding-top: 6px; padding-bottom: 6px; font-size: 13px; }
tr.day-total td:nth-child(4) { text-align: right; }
.row-del {
  width: 32px; height: 32px; border-radius: 8px; border: none;
  background: transparent; color: var(--text-muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity var(--motion), background var(--motion), color var(--motion);
}
tr.shift:hover .row-del, tr.shift:focus-within .row-del, .row-del:focus-visible { opacity: 1; }
.row-del:hover { background: rgba(255, 69, 58, 0.12); color: var(--danger); }
.row-del:focus-visible { outline: 2px solid var(--accent); }

@media (min-width: 900px) {
  .app { max-width: none; border: none; }
  .tabbar { display: none; }
  .content { padding: 0; overflow: hidden; }
  .split { flex: 1; min-height: 0; display: flex; }
  .split .left {
    width: 400px; flex-shrink: 0;
    border-right: 1px solid var(--track);
    padding: calc(env(safe-area-inset-top) + 40px) 36px 32px;
    display: flex; flex-direction: column; overflow-y: auto;
  }
  .split .right { flex: 1; min-width: 0; padding: calc(env(safe-area-inset-top) + 36px) 44px 32px; display: flex; flex-direction: column; gap: 18px; overflow-y: auto; }
  .split .right .stack { padding-top: 0; max-width: 640px; }
  .split .timer { padding-top: 0; }
  .split .counter { margin-top: 56px; font-size: var(--counter-size-mac); }
  .split .subline { margin-top: 12px; }
  .split .btn-group { margin-top: 40px; width: 232px; height: 232px; }
  .split .big { width: 188px; height: 188px; font-size: 22px; }
  .split .finish small { font-size: 11px; }
  .split .has-chips .btn-group { margin-top: 24px; }
  .sheet { margin: auto; border-radius: 20px; border-bottom: 1px solid var(--border); }
}
@media (hover: none) { .row-del { opacity: 1; } }

/* ---------- Sync status ---------- */
.sync-status { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.dot.ok { background: #30D158; }
.dot.bad { background: var(--danger); }
