:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1d2733;
  --muted: #68727e;
  --line: #e3e6ea;
  --accent: #1f4e79;
  --accent-soft: #e8eff6;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --ok: #1e7a46;
  --ok-soft: #e7f4ec;
  --warn-soft: #fff6e5;
  --warn-ink: #8a5a00;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14.5px;
  color: var(--ink);
  background: var(--bg);
}

.layout { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #16283b;
  color: #d5dde6;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  padding: 4px 20px 20px;
  letter-spacing: 0.2px;
}
.brand span { color: #7fa6c9; font-weight: 400; margin-left: 6px; }
.sidebar nav { display: flex; flex-direction: column; }
.sidebar nav a {
  color: #c2cdd8;
  text-decoration: none;
  padding: 11px 20px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.sidebar nav a.active {
  background: rgba(255, 255, 255, 0.08);
  border-left-color: #7fa6c9;
  color: #fff;
  font-weight: 600;
}
.sidebar-foot {
  margin-top: auto;
  padding: 14px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 13px;
  color: #9fb0c0;
}
.sidebar-foot strong { display: block; color: #fff; font-size: 16px; margin-top: 2px; }
.sidebar-foot:not(:has(strong)) { visibility: hidden; }

.sidebar-user {
  padding: 12px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.sidebar-user-name {
  color: #fff;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-user a { color: #9fb0c0; text-decoration: none; }
.sidebar-user a:hover { color: #fff; text-decoration: underline; }

/* ---------- login page ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 36px 40px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.login-card .brand-dark { color: var(--ink); padding: 0; font-size: 22px; }
.login-card .brand-dark span { color: var(--accent); }
.login-btn { text-decoration: none; text-align: center; }
.sidebar-foot strong.danger { color: #ff9e97; }

/* ---------- content ---------- */
.content { flex: 1; padding: 28px 36px 60px; max-width: 1060px; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}
.page-head h1 { margin: 0; font-size: 22px; font-weight: 650; }

.month-nav { display: flex; align-items: center; gap: 6px; }
.month-title { font-size: 16px; font-weight: 600; min-width: 130px; text-align: center; }
.today-link { font-size: 13px; margin-left: 8px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.danger { color: var(--danger); }
.pos { color: var(--ok); font-variant-numeric: tabular-nums; }
.neg { color: var(--danger); font-variant-numeric: tabular-nums; }

/* ---------- cards & summary ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h2 { margin: 0 0 12px; font-size: 16px; }

.summary {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.summary-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 180px;
}
.summary-item strong { font-size: 20px; font-variant-numeric: tabular-nums; }

/* ---------- week card ---------- */
.week-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.week-head h2 { display: inline; margin: 0 8px 0 0; font-size: 17px; }

.toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--muted); }
.toggle input { accent-color: var(--accent); }

.week-totals {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  padding: 10px 0 14px;
  border-bottom: 1px solid var(--line);
}
.total-item { display: flex; flex-direction: column; gap: 1px; }
.total-item strong { font-size: 17px; font-variant-numeric: tabular-nums; }

.progress {
  flex: 1;
  min-width: 140px;
  max-width: 320px;
  height: 8px;
  background: var(--accent-soft);
  border-radius: 4px;
  overflow: hidden;
}
.progress .bar { height: 100%; background: var(--accent); border-radius: 4px; }
.progress .bar-over { background: var(--danger); }

.badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 600;
}
.badge-info { background: var(--accent-soft); color: var(--accent); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- days ---------- */
.day {
  padding: 14px 2px;
  border-bottom: 1px solid var(--line);
}
.day:last-child { border-bottom: none; }
.day.weekend { background: #fafbfc; }
.day.other-month { opacity: 0.55; }

.day-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.day-title { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.day-title strong { font-size: 15px; }
.day-net { display: flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.day-net strong { font-size: 17px; font-variant-numeric: tabular-nums; }

.session-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: 460px;
}
.session-row {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: #fff;
  padding: 7px 8px 7px 12px;
}
.session-row.session-debt { border-left-color: var(--ok); }
.s-times { font-weight: 600; font-variant-numeric: tabular-nums; }
.s-dur { font-variant-numeric: tabular-nums; font-size: 13px; }
.s-spacer { flex: 1; }
.tag {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-radius: 4px;
  padding: 2px 7px;
}
.tag-debt { background: var(--ok-soft); color: var(--ok); }
.row-x {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.row-x:hover { color: var(--danger); background: var(--danger-soft); }

.day-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

.add-time > summary {
  list-style: none;
  cursor: pointer;
  display: inline-block;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  padding: 5px 12px;
  user-select: none;
}
.add-time > summary::-webkit-details-marker { display: none; }
.add-time > summary:hover { border-color: var(--accent); background: var(--accent-soft); }
.add-time[open] > summary { border-style: solid; border-color: var(--accent); background: var(--accent-soft); }
.add-time .add-form { margin-top: 8px; }
.add-time .form-error { margin-top: 6px; }

.add-form { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.dash { color: var(--muted); }

.time-field {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
}
.time-field:focus-within { border-color: var(--accent); }
.time-field input[type="text"] {
  border: none;
  outline: none;
  padding: 6px 2px 6px 9px;
  width: 58px;
  font: inherit;
  font-variant-numeric: tabular-nums;
}
.time-field input[type="time"] {
  border: none;
  outline: none;
  background: transparent;
  width: 26px;
  padding: 0 4px;
  color: transparent;           /* show only the picker icon */
  cursor: pointer;
}
.time-field input[type="time"]::-webkit-datetime-edit { display: none; }

.debt-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--ok);
  font-size: 13px;
  cursor: pointer;
}

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: #173d5f; }
.btn-small { padding: 6px 13px; font-size: 13.5px; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  padding: 4px 10px;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.breakdown { font-size: 13px; color: var(--muted); }
.breakdown summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.breakdown ol { margin: 6px 0 2px; padding-left: 20px; line-height: 1.55; }

.warn {
  background: var(--warn-soft);
  color: var(--warn-ink);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  align-self: flex-start;
}
.form-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  align-self: flex-start;
}
.form-ok {
  background: var(--ok-soft);
  color: var(--ok);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  margin-bottom: 10px;
}

/* ---------- forms & tables ---------- */
.stack-form { display: flex; flex-direction: column; gap: 12px; max-width: 380px; }
.stack-form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.stack-form input {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  font-weight: 400;
}
.stack-form input:focus { outline: none; border-color: var(--accent); }
.stack-form .small { font-weight: 400; }
.stack-form button { align-self: flex-start; }

.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
}
.table td { padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table a { color: var(--accent); }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 8px 12px; }
  .brand { padding: 0 12px 0 0; }
  .sidebar nav { flex-direction: row; }
  .sidebar-foot { display: none; }
  .content { padding: 16px; }
  .day { flex-wrap: wrap; }
}
