:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --fg: #1c2330;
  --muted: #6a7384;
  --border: #d9dde5;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --running: #15803d;
  --waiting: #b45309;
  --danger: #b91c1c;
  --interruption-bg: #fff4dc;
  --interruption-border: #e8b04b;
  --error-bg: #fde8e8;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d;
    --card: #1e232c;
    --fg: #e6e9ef;
    --muted: #98a1b3;
    --border: #333a47;
    --accent: #5b8def;
    --accent-fg: #0b1020;
    --running: #4ade80;
    --waiting: #fbbf24;
    --danger: #f87171;
    --interruption-bg: #3a2f14;
    --interruption-border: #a87a1f;
    --error-bg: #4a1f1f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
}

h1, h2 { margin: 0; font-weight: 600; }
a { color: var(--accent); }
.muted, .hint { color: var(--muted); }
.hint { font-size: 12px; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

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

button {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
button.warn { border-color: var(--interruption-border); background: var(--interruption-bg); }
button.stop:hover { border-color: var(--danger); color: var(--danger); }
button.link { border: 0; background: none; padding: 0 4px; color: var(--accent); }
button.link:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="datetime-local"], textarea {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
}

.error {
  margin: 0;
  padding: 6px 10px;
  background: var(--error-bg);
  border: 1px solid var(--danger);
  border-radius: 6px;
  color: var(--fg);
  display: flex;
  gap: 8px;
  justify-content: space-between;
  align-items: flex-start;
}
.error-inline { color: var(--danger); font-size: 12px; }

/* Text edited in place: looks like text until hovered or focused. */
.editable {
  width: 100%;
  border-color: transparent;
  background: transparent;
}
.editable:hover { border-color: var(--border); }
.editable:focus { border-color: var(--accent); background: var(--card); }
.editable.title { font-weight: 600; }
textarea.editable { resize: vertical; font-size: 13px; color: var(--muted); }

.timer, .length, .total { font-variant-numeric: tabular-nums; }

.badge {
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted);
}
.badge.running { color: var(--running); border-color: var(--running); }
.badge.waiting { color: var(--waiting); border-color: var(--waiting); }

/* ---- Login ---- */

body.login { display: grid; place-items: center; min-height: 100vh; }
body.login main {
  width: min(320px, 92vw);
  padding: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}
body.login h1 { margin-bottom: 12px; font-size: 20px; }
body.login form { display: grid; gap: 10px; }
body.login label { display: grid; gap: 3px; color: var(--muted); font-size: 12px; }
body.login input { color: var(--fg); font-size: 14px; }

/* ---- Compact window ---- */

body.compact {
  display: flex;
  flex-direction: column;
  height: 100vh;
  font-size: 13px;
}
.compact header { padding: 8px; border-bottom: 1px solid var(--border); }
.compact #start-form { display: grid; gap: 6px; }
.compact #description { width: 100%; padding: 6px 8px; font-size: 14px; }
.compact .actions { display: flex; flex-wrap: wrap; gap: 6px; }
/* Six buttons do not fit 360 px on a line: the two icons go to a second one, on the right. */
body.compact:not(.mini) #open-day-panel { margin-left: auto; }
.compact .actions button { flex: 1; padding: 5px 4px; white-space: nowrap; }
.compact .error { margin: 6px 8px 0; font-size: 12px; }
.compact main {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.compact footer {
  display: flex;
  justify-content: space-between;
  padding: 4px 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.compact .card {
  padding: 6px 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--running);
  border-radius: 8px;
}
.compact .card.waiting { border-left-color: var(--waiting); }
.compact .card.paused { opacity: 0.55; border-left-color: var(--border); }
.compact .card.interruption {
  background: var(--interruption-bg);
  border-color: var(--interruption-border);
  border-left-color: var(--interruption-border);
}
.compact .card.pause { border-left-color: var(--muted); background: var(--bg); }
.compact .card.pause .since { font-size: 14px; font-weight: 600; }
.compact .card .kind { font-size: 11px; font-weight: 600; color: var(--waiting); padding-left: 8px; }
.compact .meta { display: flex; align-items: center; gap: 6px; padding-left: 8px; }
.compact .meta .timer { font-size: 16px; font-weight: 600; }
.compact .meta button { padding: 2px 8px; }
.compact .empty { margin: 16px 0; text-align: center; color: var(--muted); }
.compact .actions button.icon { flex: 0 0 auto; padding: 5px 8px; }

/* ---- The bar of the browser ---- */

/* Only in a browser, and not in the mini (one line). The Windows client keeps the footer, which takes
   less height: "in-client" is put on the body by the script as soon as it sees window.pywebview. */
.compact .topbar { display: none; }
body.compact:not(.in-client):not(.mini) .topbar {
  display: flex;
  position: static;
  flex: none;
}
body.compact:not(.in-client) footer { display: none; }

/* ---- Mini: the whole window is one line ---- */

#drag-handle { display: none; }
.mini-only { display: none; }
#description.has-error { border-color: var(--danger); }
#description.has-error::placeholder { color: var(--danger); opacity: 1; }

body.compact.mini {
  overflow: hidden;
  border: 1px solid var(--border);
}
body.compact.mini .topbar,
body.compact.mini main,
body.compact.mini footer,
body.compact.mini #error { display: none; }
body.compact.mini header { padding: 3px 4px; border-bottom: 0; }
body.compact.mini #start-form { display: flex; align-items: center; gap: 4px; }
body.compact.mini .actions { display: contents; }
body.compact.mini .label { display: none; }
body.compact.mini .compact-only { display: none; }
body.compact.mini #description { flex: 1; width: auto; min-width: 0; padding: 3px 8px; font-size: 13px; }
body.compact.mini .actions button { flex: none; width: 28px; padding: 3px 0; text-align: center; }
body.compact.mini .actions button.mini-only { display: inline-block; }
body.compact.mini #interruption.ending {
  background: var(--interruption-border);
  border-color: var(--interruption-border);
  color: #1c2330;
  font-weight: 700;
}
body.compact.mini .actions button.stopping { border-color: var(--danger); }
body.compact.mini #pause.ending {
  background: var(--interruption-border);
  border-color: var(--interruption-border);
  color: #1c2330;
  font-weight: 700;
}
/* A handle to move the window, only where there is a window to move (the Windows client). */
body.compact.mini.in-client #drag-handle {
  display: inline-flex;
  align-items: center;
  flex: none;
  padding: 0 2px;
  color: var(--muted);
  cursor: move;
  user-select: none;
  letter-spacing: -2px;
}

/* Day panel: covers the whole window. */
#day-panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
#day-panel .panel-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}
#day-panel h2 { min-width: 96px; text-align: center; font-size: 14px; }
.panel-filter { padding: 6px 8px; font-size: 12px; color: var(--muted); }
#day-panel .error { margin: 0 8px 6px; font-size: 12px; }
#panel-list {
  flex: 1;
  margin: 0;
  padding: 0 8px 8px;
  overflow-y: auto;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#panel-list .row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
#panel-list .row.interruption { opacity: 0.55; background: var(--interruption-bg); }
#panel-list .info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#panel-list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
#panel-list .name.none { font-weight: 400; color: var(--muted); }
#panel-list .when { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
#panel-list .row-actions { display: flex; gap: 4px; }
#panel-list .empty { margin: 16px 0; text-align: center; color: var(--muted); }

/* ---- Full view ---- */

body.full header,
.topbar {
  box-sizing: border-box;
  min-height: 48px; /* the same height with or without the controls of the full view */
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
.full h1, .topbar h1 { font-size: 16px; }
.full .days { display: flex; gap: 4px; }
.full .error { position: sticky; top: 46px; z-index: 1; margin: 8px 16px 0; }
.full main { max-width: 860px; margin: 0 auto; padding: 12px 16px 40px; }
.full h2 { margin: 4px 0 10px; font-size: 18px; }
.full h2::first-letter { text-transform: uppercase; }
.full .empty { color: var(--muted); }
.full #report { margin-bottom: 14px; overflow-x: auto; }
.full #report table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 13px;
}
.full #report th, .full #report td { padding: 3px 8px; text-align: left; border-bottom: 1px solid var(--border); }
.full #report thead th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.full #report tfoot th { border-bottom: 0; }
.full #report .number { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.full #report tr.interruption td { background: var(--interruption-bg); }
.full .activity {
  margin-bottom: 10px;
  padding: 8px 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 8px;
}
.full .activity.running { border-left-color: var(--running); }
.full .activity.waiting { border-left-color: var(--waiting); }
.full .activity.interruption {
  background: var(--interruption-bg);
  border-color: var(--interruption-border);
}
.full .head { display: flex; align-items: center; gap: 8px; }
.full .head .editable { flex: 1; min-width: 0; }
.full .total { color: var(--muted); white-space: nowrap; font-size: 13px; }
.full .segments { margin: 4px 0; padding: 0 0 0 8px; list-style: none; }
.full .segment { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 1px 0; font-size: 13px; }
.full .segment .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--running); }
.full .segment.waiting .dot { background: var(--waiting); }
.full .segment .state { width: 60px; color: var(--muted); }
.full .segment .length { color: var(--muted); }
.full .segment.editing { padding: 4px 0; }
.full .segment.editing .state { width: auto; }
.full .nested {
  margin: 6px 0 0 14px;
  padding-left: 10px;
  border-left: 2px solid var(--interruption-border);
}
.full .activity.pause { background: var(--bg); opacity: 0.75; border-left-color: var(--border); }
.full .activity.pause .kind { margin-right: 2px; }
.full .nested-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.full .nested .activity { margin: 4px 0; }

@media (max-width: 560px) {
  body.full header { flex-wrap: wrap; }
  .full .head { flex-wrap: wrap; }
}
