:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --line: #e3e6ee;
  --primary: #2f6fed;
  --danger: #dc2626;
  --probe: #0ea5e9;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
button:hover { border-color: #c5cad6; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.danger { color: var(--danger); border-color: #f3c4c4; }
button.small { padding: 3px 8px; font-size: 12px; }
button.active { background: #e8efff; border-color: var(--primary); }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; margin: 0; }
.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

/* Filter bar */
.filterbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.flabel { color: var(--muted); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 13px;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.chip.on { background: #e8efff; border-color: var(--primary); }
label.inline { flex-direction: row; align-items: center; gap: 6px; }
label.inline select { padding: 4px 6px; }

/* Clients */
.vis-item .cl {
  display: inline-block; padding: 0 5px; margin-right: 4px; border-radius: 4px;
  background: rgba(255,255,255,.88); color: #1f2430; font-size: 10px; font-weight: 700;
  line-height: 16px; vertical-align: 1px;
}
.member-row input.code { flex: 0 0 120px; min-width: 0; }
#client-add input[name=name], #client-rows input[name=name] { flex: 1; min-width: 160px; }

/* Hours report */
.report-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.report-wrap { overflow: auto; max-height: 55vh; border: 1px solid var(--line); border-radius: 8px; }
table.report { border-collapse: collapse; width: 100%; font-size: 13px; }
table.report th, table.report td { padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.report td { text-align: right; font-variant-numeric: tabular-nums; }
table.report thead th { position: sticky; top: 0; background: #f8fafc; font-weight: 600; text-align: right; }
table.report thead th:first-child, table.report tbody th, table.report tfoot th { text-align: left; }
table.report tbody th { font-weight: 500; }
table.report tfoot td, table.report tfoot th, table.report .tot { font-weight: 700; }
table.report tfoot td, table.report tfoot th { background: #f8fafc; }
table.report td.error, table.report td.log-empty { text-align: left; }

.lock { font-size: 11px; }

/* Deactivated members */
.inactive-box summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.inactive-box ul { list-style: none; margin: 6px 0 0; padding: 0; }
.inactive-box li { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.inactive-box li button { margin-left: auto; }
.inactive-box .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.muted { color: var(--muted); font-size: 12px; }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding: 16px;
}
.stat {
  display: flex; align-items: baseline; gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px 28px;
}
.stat b { font-size: 34px; line-height: 1; color: #1e293b; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 16px; }
@media (max-width: 800px) {
  .stats { grid-template-columns: 1fr; gap: 8px; padding: 8px 16px; }
  .stat { padding: 12px 16px; }
  .stat b { font-size: 26px; }
}

/* Priority badges */
.pr {
  display: inline-block; padding: 0 5px; border-radius: 4px;
  font-size: 10px; font-weight: 700; line-height: 16px; vertical-align: 1px;
  color: #fff; text-decoration: none;
}
.pr-urgent { background: #b91c1c; }
.pr-high { background: #ea580c; }
.pr-medium { background: #64748b; }
.pr-low { background: #cbd5e1; color: #334155; }
.vis-item .pr { box-shadow: 0 0 0 1px rgba(255,255,255,.7); margin-right: 3px; }
.vis-item.prio-urgent { border-width: 2px; border-color: #7f1d1d !important; }

/* Member task list */
.member-tasks { margin-top: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.member-tasks h2 { font-size: 15px; margin: 0 0 8px; }
.member-tasks table { width: 100%; border-collapse: collapse; }
.member-tasks th, .member-tasks td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.member-tasks th { font-size: 12px; color: var(--muted); font-weight: 500; }
.member-tasks tbody tr { cursor: pointer; }
.member-tasks tbody tr:hover { background: #f3f6ff; }
.member-tasks tr.done td { color: var(--muted); text-decoration: line-through; }
.member-tasks .when { white-space: nowrap; color: var(--muted); }
.member-tasks .empty-row td { color: var(--muted); font-style: italic; cursor: default; }
.now-card { cursor: pointer; }
.now-card:hover { border-color: #c5cad6; }
.now-card.focused { background: #f3f6ff; }
.vis-label { cursor: pointer; }

/* Audit log */
dialog.wide { width: min(760px, calc(100vw - 32px)); }
.log-list { list-style: none; margin: 0; padding: 0; max-height: 55vh; overflow-y: auto; }
.log {
  border-left: 3px solid #94a3b8;
  padding: 6px 10px;
  margin-bottom: 6px;
  background: #f8fafc;
  border-radius: 0 6px 6px 0;
}
.log-create { border-left-color: #16a34a; }
.log-update { border-left-color: var(--primary); }
.log-delete { border-left-color: var(--danger); }
.log-head { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.log-time { color: var(--muted); font-size: 12px; margin-left: auto; }
.log-body { margin-top: 3px; font-size: 13px; color: #374151; }
.log-body div { margin-top: 1px; }
.log-body .f { color: var(--muted); }
.log-body del { color: #9ca3af; }
.log-empty { color: var(--muted); font-style: italic; padding: 6px 0; }
#task-history summary { cursor: pointer; color: var(--muted); font-size: 13px; }
#task-history .log-list { max-height: 200px; margin-top: 6px; }
#btn-me.unset { border-color: #f59e0b; background: #fffbeb; }

/* Login */
.login-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 16px;
}
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 32px 28px; width: min(380px, 100%); text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.06);
}
.login-card h1 { font-size: 20px; margin: 0 0 6px; }
.google-btn {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 14px;
  padding: 10px 18px; border: 1px solid #dadce0; border-radius: 6px;
  color: #3c4043; background: #fff; text-decoration: none; font-weight: 500;
}
.google-btn:hover { background: #f8f9fa; border-color: #c6c9cc; }
.login-card .error { margin-top: 14px; }

dialog form.member-row { flex-direction: row; flex-wrap: wrap; padding: 0; gap: 6px; }
.member-row input[name=name] { min-width: 90px; }
.member-row input[name=role] { min-width: 110px; }
.member-row input[name=email] { flex: 1.5; min-width: 160px; }
.chk { flex-direction: row; align-items: center; gap: 3px; white-space: nowrap; font-size: 12px; }

/* List view (phones) */
.list-view { display: flex; flex-direction: column; gap: 14px; }
.lv-day h3 { font-size: 13px; margin: 0 0 6px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.lv-item {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--c, #94a3b8);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 6px; cursor: pointer;
}
.lv-item:active { background: #f3f6ff; }
.lv-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 84px; line-height: 1.35; }
.lv-main { flex: 1; min-width: 0; }
.lv-title { font-weight: 600; overflow-wrap: anywhere; }
.lv-meta { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.lv-meta .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 3px; }
.lv-meta .clt { border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-weight: 600; color: var(--text); }
.lv-item.now { box-shadow: 0 0 0 2px var(--probe) inset; }
.lv-now { color: var(--probe); font-weight: 600; font-size: 11px; }
.lv-item.status-done .lv-title { text-decoration: line-through; color: var(--muted); }
.lv-item.status-blocked { background-image: repeating-linear-gradient(45deg, rgba(0,0,0,.035) 0 6px, transparent 6px 12px); }
.lv-item.conflict { outline: 2px dashed #f97316; outline-offset: -2px; }
.lv-empty { color: var(--muted); font-style: italic; padding: 4px 0 8px; }

/* Top-left corner of the timeline: the period on screen */
#timeline { position: relative; }
.tl-corner {
  position: absolute; top: 1px; left: 1px; z-index: 2; box-sizing: border-box;
  display: flex; flex-direction: column; justify-content: center; gap: 1px;
  padding: 4px 10px; overflow: hidden; pointer-events: none;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  border-top-left-radius: 8px; background: var(--panel);
}
.tl-corner .c-main { font-size: 15px; font-weight: 700; color: var(--text); white-space: nowrap; line-height: 1.2; }
.tl-corner .c-main.we { color: #64748b; }
.tl-corner .c-sub { font-size: 12px; color: var(--muted); white-space: nowrap; }
.tl-corner .c-sub b { color: var(--primary); font-weight: 600; }
.tl-corner .c-hol {
  font-size: 11px; font-weight: 600; color: #b91c1c; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.tl-corner .wd-short { display: none; }
@media (max-width: 700px) {
  .tl-corner .wd-long { display: none; }
  .tl-corner .wd-short { display: inline; }
  .tl-corner { padding: 2px 6px; }
  .tl-corner .c-main { font-size: 12px; }
  .tl-corner .c-sub, .tl-corner .c-hol { font-size: 10px; }
}

/* Weekends and public holidays */
.vis-item.vis-background.weekend { background: rgba(100, 116, 139, .07); }
.vis-item.vis-background.holiday { background: rgba(220, 38, 38, .08); }
.vis-item.vis-background .vis-item-content {
  color: #b91c1c; font-size: 11px; font-weight: 600; padding: 2px 6px; white-space: nowrap;
}
.vis-time-axis .vis-text.vis-saturday, .vis-time-axis .vis-text.vis-sunday { color: #94a3b8; }
.vis-time-axis .ax-hol { color: #b91c1c; font-weight: 700; }
.vis-time-axis .ax-we { color: #94a3b8; }
.hol-tip {
  position: absolute; z-index: 5; pointer-events: none; max-width: 260px;
  padding: 6px 9px; border-radius: 6px; font-size: 12px; line-height: 1.4;
  background: #1f2430; color: #fff; box-shadow: 0 6px 18px rgba(0,0,0,.2);
}
.hol-tip b { color: #fecaca; }
.hol-tip .hol-note { margin-top: 3px; color: #cbd5e1; font-size: 11px; }
.hol {
  display: inline-block; margin-left: 4px; padding: 1px 6px; border-radius: 4px;
  background: #fbebeb; color: #b91c1c; font-size: 11px; font-weight: 600;
  text-transform: none; letter-spacing: 0; vertical-align: 1px;
}
#probe-holiday { margin: 4px 0 0; }
.lv-day.weekend h3 { color: #94a3b8; }
.warn { margin: 0; padding: 6px 10px; border-radius: 6px; background: #fff7ed; color: #9a3412; font-size: 13px; }

/* Phone-only controls */
.mobile-only { display: none; }
.more-menu { display: contents; } /* desktop: its buttons sit inline in the toolbar */
.seg { display: inline-flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
.seg button.active { background: #e8efff; border-color: var(--primary); }

@media (max-width: 700px) {
  .mobile-only { display: inline-flex; }
  .desk { display: none; }

  .topbar { position: sticky; top: 0; z-index: 20; padding: 8px 12px; gap: 6px; }
  .topbar h1 { font-size: 16px; }
  .toolbar { width: 100%; gap: 4px; flex-wrap: nowrap; position: relative; }
  .toolbar > button { padding: 6px 8px; font-size: 13px; white-space: nowrap; }
  .mobile-bar button { white-space: nowrap; }
  .toolbar .sep { display: none; }
  #btn-more { margin-left: auto; }
  .more-menu {
    display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
    flex-direction: column; gap: 2px; min-width: 210px; padding: 6px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
    box-shadow: 0 12px 30px rgba(0,0,0,.15);
  }
  .more-menu.open { display: flex; }
  .more-menu button { border: 0; text-align: left; padding: 10px 12px; }

  .mobile-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
  #btn-filters.on { background: #e8efff; border-color: var(--primary); }

  .filterbar { display: none; padding: 8px 12px; }
  .filterbar.open { display: flex; }
  .filterbar .flabel, .filterbar .sep { display: none; }
  .chips { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 2px; }
  .chip { white-space: nowrap; }
  .filterbar label.inline { width: 100%; }
  .filterbar label.inline select { flex: 1; }

  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; padding: 8px 12px; }
  .stat { flex-direction: column; align-items: flex-start; gap: 3px; padding: 8px 10px; border-radius: 10px; }
  .stat b { font-size: 22px; }
  .stat span { font-size: 11px; line-height: 1.25; }

  .now-panel { max-height: 30vh; padding: 8px 12px; }
  .now-panel .hint { display: none; }
  .layout.mode-list .now-panel,
  .layout.mode-list .legend,
  .layout.mode-list #member-tasks { display: none; }
  .timeline-wrap { padding: 8px 12px 24px; }
  .legend .tip { display: none; }
  .vis-label .vis-inner { max-width: 84px; padding: 4px 6px; overflow: hidden; }
  .grp .role { display: none; }

  dialog, dialog.wide { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  dialog form, .members-box { padding: 14px; }
  .row { flex-direction: column; gap: 10px; }
  /* 16px stops iPhones from zooming in when a field is tapped (beats the later `font: inherit`). */
  body input, body select, body textarea { font-size: 16px; }
  .report-controls > * { flex: 1 1 140px; }
}

/* Layout */
.layout { flex: 1; display: flex; min-height: 0; }
.now-panel {
  width: 280px;
  flex-shrink: 0;
  padding: 12px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
.timeline-wrap { flex: 1; min-width: 0; padding: 12px; overflow: auto; }

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .now-panel { width: auto; border-right: 0; border-bottom: 1px solid var(--line); max-height: 40vh; }
}

/* "Now" panel */
.now-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.now-title { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.probe-time { font-size: 16px; font-weight: 600; color: var(--probe); }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 10px; }
.now-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--c, #999);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
.now-card .who { font-weight: 600; }
.now-card .role { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 4px; }
.now-card .what { margin-top: 4px; }
.now-card .what div { margin-top: 2px; }
.now-card .when { color: var(--muted); font-size: 12px; }
.now-card.free .what { color: var(--muted); font-style: italic; }
.now-card.busy-2 { background: #fff7ed; }

/* Timeline */
#timeline { background: var(--panel); border-radius: 8px; }
.vis-timeline { border-color: var(--line); border-radius: 8px; font-family: inherit; }
.vis-label .vis-inner { padding: 6px 10px; }
.grp { display: flex; align-items: center; gap: 6px; }
.grp .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.grp .role { color: var(--muted); font-size: 11px; display: block; }

.vis-item {
  color: #fff;
  border-radius: 5px;
  border-width: 1px;
  font-size: 12px;
}
.vis-item .vis-item-content { padding: 3px 6px; }
.vis-item .st { opacity: .85; font-size: 11px; }
.vis-item.vis-selected { box-shadow: 0 0 0 2px #111 inset; }
.vis-item.status-todo { opacity: .75; }
.vis-item.status-done { opacity: .45; text-decoration: line-through; }
.vis-item.status-blocked {
  background-image: repeating-linear-gradient(45deg, rgba(0,0,0,.18) 0 6px, transparent 6px 12px);
}
.vis-item.conflict { outline: 2px dashed #f97316; outline-offset: 1px; }
.vis-current-time { background-color: #ef4444; width: 2px; }
.vis-custom-time.probe { background-color: var(--probe); width: 3px; cursor: ew-resize; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 10px; color: var(--muted); font-size: 12px; }
.lg::before {
  content: ""; display: inline-block; width: 14px; height: 10px; border-radius: 3px;
  margin-right: 4px; vertical-align: -1px; background: #64748b;
}
.lg.todo::before { opacity: .75; }
.lg.done::before { opacity: .45; }
.lg.blocked::before { background-image: repeating-linear-gradient(45deg, rgba(0,0,0,.3) 0 3px, transparent 3px 6px); }
.lg.conflict::before { background: transparent; outline: 2px dashed #f97316; }
.legend .tip { margin-left: auto; }

.empty { background: var(--panel); border: 1px dashed var(--line); border-radius: 8px; padding: 24px; text-align: center; margin-bottom: 12px; }

/* Dialogs */
dialog { border: 0; border-radius: 10px; padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(15, 23, 42, .35); }
dialog form, .members-box { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
dialog h2 { margin: 0 0 4px; font-size: 17px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text);
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
input[type=color] { padding: 2px; width: 38px; height: 34px; }
.row { display: flex; gap: 10px; }
.row label { flex: 1; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.grow { flex: 1; }
.error { color: var(--danger); margin: 0; }

.member-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.member-row input[name=name] { flex: 1; min-width: 0; }
.member-row input[name=role] { flex: 1.3; min-width: 0; }
.member-row.add { padding-top: 8px; border-top: 1px solid var(--line); flex-direction: row; gap: 6px; }
