:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #dde1e7;
  --text: #1d2330;
  --muted: #667085;
  --primary: #2f5bea;
  --primary-hover: #2449c4;
  --danger: #c8322b;
  --row-alt: #fafbfc;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; gap: 12px; align-items: center; }
.navlink { color: var(--muted); text-decoration: none; }
.navlink:hover { color: var(--text); }

main { max-width: 1280px; margin: 0 auto; padding: 24px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }

.back-link { display: inline-block; margin-bottom: 10px; color: var(--muted); text-decoration: none; }
.back-link:hover { color: var(--primary); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.subtotal { color: var(--muted); }
.subtotal b { color: var(--text); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
  color: var(--text); font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f0f2f5; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.icon-btn { border: none; background: none; cursor: pointer; color: var(--muted); padding: 2px 5px; font-size: 14px; border-radius: 4px; }
.icon-btn:hover { background: #eef0f3; color: var(--text); }
.icon-btn.del:hover { color: var(--danger); }

.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
input, select, textarea {
  font: inherit; color: inherit; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--surface); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47, 91, 234, .25); border-color: var(--primary); }
input.readonly { background: var(--bg); color: var(--muted); cursor: default; }
input.readonly:focus { outline: none; border-color: var(--border); }
.filters input { max-width: 320px; }
.filters select { max-width: 200px; }
textarea { resize: vertical; min-height: 38px; line-height: 1.4; }

.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.form-grid .wide { grid-column: span 2; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field .link-open { font-size: 12px; margin-left: 6px; font-weight: 400; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover, th.sorted { color: var(--text); }
th.sortable::after { content: attr(data-arrow); margin-left: 4px; opacity: .5; }
th.sorted::after { opacity: 1; }
.list tbody tr { cursor: pointer; }
.list tbody tr:hover { background: var(--row-alt); }
.num { text-align: left; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 32px; }

.items td { padding: 6px; }
.items input, .items textarea { padding: 6px 8px; }
.items .hours { width: 90px; text-align: right; }
.items .row-actions { white-space: nowrap; width: 1%; }
.items tfoot td { border-bottom: none; padding-top: 10px; }

.total-bar {
  display: flex; justify-content: flex-end; align-items: center; gap: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; font-size: 15px;
}
.total-bar .grand { font-size: 20px; font-weight: 700; }
.total-bar { flex-wrap: wrap; }
.total-bar .sep { width: 1px; align-self: stretch; background: var(--border); }

/* Not-invoiced hours: open (still to invoice) / done (fully invoiced) / over (invoiced more than estimated) */
.diff { font-weight: 600; font-variant-numeric: tabular-nums; }
.diff-open { color: #8a5a00; }
.diff-done { color: #146c34; }
.diff-over { color: var(--danger); }
.stat-invoice { border-style: dashed; }

.invoicing { margin-top: 20px; }
.invoicing p { margin: 0; }
.invoices td { vertical-align: middle; }
.invoices th.num, .invoices td.num { text-align: right; }
.invoice-add { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-top: 14px; }
.invoice-add .f-month { flex: 0 0 150px; }
.invoice-add .f-year { flex: 0 0 90px; }
.invoice-add .f-hours { flex: 0 0 100px; }
.invoice-add .f-hours input { text-align: right; }
.invoice-add .f-note { flex: 1 1 200px; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-Draft { background: #eef0f3; color: #475467; }
.badge-In-review { background: #fff4d6; color: #8a5a00; }
.badge-Sent-to-client { background: #e0ebff; color: #1e46b8; }
.badge-Approved { background: #dcf5e4; color: #146c34; }
.badge-Rejected { background: #fde4e2; color: #a42520; }
.badge-In-development { background: #ece4fd; color: #5b2bb8; }
.badge-Development-done { background: #d9f2f2; color: #0f6566; }

.summary { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; min-width: 160px;
  font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.stat:hover { border-color: #b8c0cc; }
.stat.active { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.stat .v { font-size: 20px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }

/* ---------- auth / roles ---------- */
.user-chip { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-weight: 600; margin-left: 8px; }
.role-tag { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; padding: 1px 7px; border-radius: 999px; }
.role-admin { background: #e0ebff; color: #1e46b8; }
.role-client { background: #dcf5e4; color: #146c34; }

.login-wrap { display: flex; justify-content: center; padding-top: 8vh; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0; }
.login-card p { margin: -10px 0 4px; }
.btn-block { width: 100%; justify-content: center; padding: 9px 14px; }
.form-error { background: #fde4e2; color: #a42520; border-radius: 6px; padding: 8px 10px; }

.decision { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  border-color: #b8ccff; background: #f3f6ff; }
.btn-danger:hover { background: #fde4e2; }
.read-only .card input, .read-only .card textarea, .read-only .card select { background: var(--bg); }
.read-only .card select:disabled { color: var(--text); opacity: 1; }

.users-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
.users tbody tr.selected { background: #eef3ff; }
.user-form { display: flex; flex-direction: column; gap: 12px; }
.user-form .card-head { margin-bottom: 0; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; }
.narrow { max-width: 480px; display: flex; flex-direction: column; gap: 12px; }
.narrow h2 { margin: 0; }

.toast {
  position: fixed; bottom: 24px; right: 24px; background: #1d2330; color: #fff;
  padding: 10px 16px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.toast.error { background: var(--danger); }

@media (max-width: 800px) {
  .users-layout { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .topbar nav { flex-wrap: wrap; }
  main { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .table-wrap { overflow-x: auto; }
}
