:root {
  --bg: #F6F7F5;
  --surface: #FFFFFF;
  --surface-2: #EFF1EE;
  --ink: #1B1D1F;
  --muted: #6B7075;
  --border: #DFE1DE;
  --accent: #3D5A5C;
  --accent-ink: #FFFFFF;
  --danger: #B23A3A;
  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161A;
    --surface: #1B1E22;
    --surface-2: #20242A;
    --ink: #E8EAED;
    --muted: #9AA0A6;
    --border: #2A2D30;
    --accent: #6FA8A6;
    --accent-ink: #0E1414;
    --danger: #E07A7A;
  }
}
:root[data-theme="dark"] {
  --bg: #14161A;
  --surface: #1B1E22;
  --surface-2: #20242A;
  --ink: #E8EAED;
  --muted: #9AA0A6;
  --border: #2A2D30;
  --accent: #6FA8A6;
  --accent-ink: #0E1414;
  --danger: #E07A7A;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}
.mono { font-family: var(--font-mono); }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; color: var(--ink); }
a { color: inherit; }
::selection { background: var(--accent); color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  max-width: 1180px;
  margin: 0 auto;
}
@media (max-width: 780px) {
  .app { grid-template-columns: 1fr; }
}

/* Sidebar */
.sidebar {
  border-right: 1px solid var(--border);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100vh;
}
@media (max-width: 780px) {
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); min-height: auto; }
}
.brand {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.brand h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
}
.brand .dot { color: var(--accent); }

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  padding-bottom: 2px;
  border-bottom: 1px solid var(--border);
}
.user-row .user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row button {
  background: none; border: none; color: var(--muted); font-size: 12px;
  padding: 4px 0; flex-shrink: 0;
}
.user-row button:hover { color: var(--ink); }

.add-activity-btn {
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 9px 10px;
  font-size: 13.5px;
  text-align: left;
  transition: border-color .12s, color .12s;
}
.add-activity-btn:hover { border-color: var(--accent); color: var(--ink); }

.activity-list { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; flex: 1; }
.activity-block { border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 6px; }
.activity-block:last-child { border-bottom: none; }

.activity-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 4px;
  border-radius: 6px;
}
.swatch { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.activity-name { font-weight: 500; flex: 1; font-size: 14px; }
.icon-btn {
  background: none; border: none; color: var(--muted);
  padding: 3px 5px; border-radius: 4px; font-size: 13px; line-height: 1;
}
.icon-btn:hover { color: var(--ink); background: var(--surface-2); }

.way-list { display: flex; flex-direction: column; gap: 1px; margin-left: 17px; }
.way-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 4px; border-radius: 6px; font-size: 13.5px;
}
.way-row:hover { background: var(--surface-2); }
.way-name { flex: 1; color: var(--ink); }
.way-name.running { color: var(--accent); font-weight: 500; }
.timer-readout { font-size: 12.5px; color: var(--accent); min-width: 54px; text-align: right; }
.timer-btn {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 10px; flex-shrink: 0;
  transition: border-color .12s, color .12s;
}
.timer-btn:hover { border-color: var(--accent); color: var(--accent); }
.timer-btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.add-way-btn {
  margin-left: 17px; background: none; border: none; color: var(--muted);
  font-size: 12.5px; padding: 5px 4px; text-align: left;
}
.add-way-btn:hover { color: var(--accent); }

.empty-sidebar { color: var(--muted); font-size: 13.5px; padding: 10px 4px; line-height: 1.5; }

/* Main */
.main { padding: 26px 30px 60px; min-width: 0; }
@media (max-width: 780px) { .main { padding: 20px 18px 50px; } }

.tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--border); margin-bottom: 26px; }
.tab-btn {
  background: none; border: none; padding: 8px 0 12px; font-size: 14px;
  color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 500; }

.stat-row { display: flex; gap: 34px; margin-bottom: 30px; flex-wrap: wrap; }
.stat-block .stat-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat-block .stat-value { font-family: var(--font-mono); font-size: 26px; font-weight: 500; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 12px; flex-wrap: wrap;
}
.section-title { font-size: 13px; color: var(--muted); }

.segmented { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented button {
  background: var(--surface); border: none; color: var(--muted);
  font-size: 12.5px; padding: 6px 12px; border-right: 1px solid var(--border);
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--accent); color: var(--accent-ink); }

.chart-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 34px; height: 220px; }

.breakdown-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; }
.breakdown-name { width: 130px; flex-shrink: 0; font-size: 13.5px; display: flex; align-items: center; gap: 7px; }
.breakdown-track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.breakdown-fill { height: 100%; border-radius: 4px; }
.breakdown-value { font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); width: 64px; text-align: right; flex-shrink: 0; }

.log-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.select, .btn, .text-input {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  border-radius: 6px; padding: 7px 10px; font-size: 13.5px;
}
.btn { color: var(--muted); }
.btn:hover { color: var(--ink); border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { opacity: 0.9; }

.log-list { display: flex; flex-direction: column; margin-top: 16px; }
.log-row {
  display: grid; grid-template-columns: 70px 1fr 90px 90px auto;
  gap: 12px; align-items: center; padding: 10px 4px;
  border-bottom: 1px solid var(--border); font-size: 13.5px;
}
@media (max-width: 640px) { .log-row { grid-template-columns: 60px 1fr 70px auto; } .log-row .log-note { display:none; } }
.log-date { color: var(--muted); font-family: var(--font-mono); font-size: 12.5px; }
.log-activity { display: flex; align-items: center; gap: 7px; min-width: 0; }
.log-activity-name { font-weight: 500; }
.log-way-name { color: var(--muted); }
.log-note { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-duration { font-family: var(--font-mono); text-align: right; }
.log-actions { display: flex; gap: 4px; justify-content: flex-end; }

.empty-state { color: var(--muted); font-size: 14px; padding: 34px 4px; text-align: center; border: 1px dashed var(--border); border-radius: 8px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  width: 100%; max-width: 380px; padding: 22px;
}
.modal h2 { font-size: 16px; margin: 0 0 16px; font-weight: 600; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.field .text-input, .field .select { width: 100%; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer;
}
.color-swatch.selected { border-color: var(--ink); }
.modal-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 20px; gap: 10px; }
.modal-actions .right { display: flex; gap: 8px; margin-left: auto; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 6px;
  font-size: 13px; z-index: 60; opacity: 0; transition: opacity .2s;
}
.toast.show { opacity: 1; }

.banner {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; font-size: 13px; color: var(--muted); margin-bottom: 20px;
}

/* Auth screen */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 28px; width: 100%; max-width: 360px;
}
.auth-card h1 { font-size: 19px; font-weight: 600; margin: 0; }
.auth-sub { color: var(--muted); font-size: 13px; margin: 6px 0 18px; }
.auth-error {
  color: var(--danger); font-size: 13px; margin-bottom: 14px;
  background: var(--surface-2); border-radius: 6px; padding: 8px 10px;
}
.auth-submit { width: 100%; justify-content: center; text-align: center; margin-top: 4px; }
.auth-switch { text-align: center; margin-top: 16px; font-size: 13px; color: var(--muted); }
.auth-switch a { color: var(--accent); cursor: pointer; text-decoration: underline; }
