:root {
  --bg: #0f1220;
  --bg-2: #171b2e;
  --card: #1c2136;
  --card-2: #232a45;
  --line: #2c3454;
  --text: #e8ebf5;
  --muted: #9aa3c4;
  --accent: #6c8cff;
  --accent-2: #4f6fe0;
  --green: #35d19a;
  --amber: #ffb454;
  --red: #ff6b7a;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 20% -10%, #1b2140 0%, var(--bg) 55%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ============ Dashboard shell ============ */
.shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, #12162a, #0e1120);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.sidebar-title { font-size: 20px; font-weight: 800; letter-spacing: 0.3px; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  border: none; background: transparent; color: var(--muted);
  padding: 11px 14px; border-radius: 10px; cursor: pointer;
  font-size: 14px; font-weight: 600; text-align: left; width: 100%;
  transition: 0.15s;
}
.nav-item:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-item.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: var(--shadow); }
.nav-ico { width: 20px; text-align: center; font-size: 15px; }
.sidebar-foot { color: var(--muted); font-size: 12px; padding: 12px 8px 4px; border-top: 1px solid var(--line); }

/* Main column */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(15,18,32,0.75);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { display: flex; flex-direction: column; line-height: 1.2; margin-right: auto; }
.topbar-title #viewTitle { font-size: 20px; font-weight: 700; }
.topbar-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.hamburger { display: none; background: none; border: none; color: var(--text); font-size: 22px; cursor: pointer; }
.rate-pill {
  background: var(--card); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px;
  font-weight: 600; font-size: 13px; color: var(--accent); white-space: nowrap;
}
.content { padding: 26px 28px 60px; max-width: 1200px; width: 100%; }

/* Summary / KPI cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: var(--shadow);
}
.card-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.card-value { font-size: 24px; font-weight: 700; }
.card-value.paid { color: var(--green); }
.card-value.due { color: var(--amber); }
.card-value.pending { color: var(--amber); }

/* Two-column grid for dashboard panels */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }

/* Panels */
.panel { display: none; animation: fade 0.2s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.block {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.block h2 { margin: 0 0 14px; font-size: 16px; }
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.block-head h2 { margin: 0; }

/* Timer */
.timer-block { text-align: center; }
.timer-display {
  font-size: 52px; font-weight: 800; letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
  margin-bottom: 14px;
}
.timer-controls { display: flex; gap: 10px; max-width: 520px; margin: 0 auto; }
.timer-controls input { flex: 1; }
.hint { color: var(--muted); font-size: 13px; margin: 12px 0 0; }

/* Forms */
.form-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 14px; margin-bottom: 16px;
}
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
label.wide { grid-column: 1 / -1; }
input, select {
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 10px; padding: 11px 12px;
  font-size: 14px; outline: none; transition: 0.15s;
}
input:focus, select:focus { border-color: var(--accent); }
.mini-select { padding: 8px 10px; font-size: 13px; }

/* Buttons */
.btn {
  background: var(--card-2); border: 1px solid var(--line);
  color: var(--text); padding: 11px 18px; border-radius: 10px;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.danger:hover { background: rgba(255,107,122,0.12); }
.btn.tiny { padding: 6px 10px; font-size: 12px; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: rgba(108,140,255,0.06); }
.del-btn { background: transparent; border: none; color: var(--red); cursor: pointer; font-size: 16px; }

/* Periods */
.period {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; background: var(--bg-2);
}
.period.paid { border-color: rgba(53,209,154,0.4); }
.period-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.period-range { font-weight: 700; font-size: 15px; }
.period-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.period-amount { font-size: 20px; font-weight: 800; }
.badge {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; margin-left: 8px;
}
.badge.paid { background: rgba(53,209,154,0.15); color: var(--green); }
.badge.due { background: rgba(255,180,84,0.15); color: var(--amber); }

.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 18px 0; }
.save-note { color: var(--green); font-size: 13px; margin-left: 12px; }
.footer { text-align: center; color: var(--muted); font-size: 12px; margin-top: 30px; }

/* Responsive */
.sidebar-overlay { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 40;
    width: 240px; transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .shell.nav-open .sidebar { transform: translateX(0); }
  .shell.nav-open .sidebar-overlay {
    display: block; position: fixed; inset: 0; z-index: 30;
    background: rgba(0,0,0,0.5);
  }
  .hamburger { display: block; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .timer-display { font-size: 42px; }
  .timer-controls { flex-direction: column; }
  .content { padding: 18px 16px 50px; }
  .topbar { padding: 14px 16px; }
  .topbar-right .rate-pill { display: none; }
}


/* ============================================================
   Cloudflare edition additions: login, roles, loading
   ============================================================ */

/* Loading splash */
.loading {
  min-height: 60vh;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 15px;
}
/* hidden attribute must win over display:grid above */
.loading[hidden] { display: none; }

/* Topbar right cluster */
.topbar-right { display: flex; align-items: center; gap: 10px; }
.role-badge {
  font-size: 11px; font-weight: 800; letter-spacing: 0.6px;
  padding: 4px 10px; border-radius: 999px;
}
.role-badge.admin { background: rgba(108,140,255,0.16); color: var(--accent); }
.role-badge.viewer { background: rgba(255,180,84,0.16); color: var(--amber); }

/* Read-only banner */
.readonly-note {
  background: rgba(255,180,84,0.1);
  border: 1px solid rgba(255,180,84,0.35);
  color: var(--amber);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
  margin-bottom: 18px;
}

/* Login page */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 34px 30px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 14px 0 2px; font-size: 22px; }
.login-card .subtitle { margin: 0 0 22px; }
.login-card form { text-align: left; display: flex; flex-direction: column; gap: 14px; }
.avatar.big {
  width: 64px; height: 64px; font-size: 28px; margin: 0 auto;
  display: grid; place-items: center; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-weight: 700;
}
.btn.full { width: 100%; margin-top: 4px; }
.login-error { color: var(--red); font-size: 13px; min-height: 18px; margin: 4px 0 0; text-align: center; }


/* Change-password / account form feedback */
.save-note.error { color: var(--red); }


/* ============================================================
   Agreement workflow + invoicing
   ============================================================ */

/* Status badges on entries */
.badge.pending  { background: rgba(255,180,84,0.15);  color: var(--amber); }
.badge.agreed   { background: rgba(53,209,154,0.15);  color: var(--green); }
.badge.disputed { background: rgba(255,107,122,0.15); color: var(--red); }

/* Pending summary card */
.card-value.pending { color: var(--amber); }

/* Dispute reason under a note */
.dispute-note {
  margin-top: 6px;
  font-size: 12px;
  color: var(--red);
  background: rgba(255,107,122,0.08);
  border-left: 3px solid var(--red);
  padding: 6px 8px;
  border-radius: 6px;
}

/* Action buttons in the entries table */
.actions-cell { white-space: nowrap; }
.actions-cell .btn.tiny, .actions-cell .del-btn { margin-left: 4px; }

/* Period pending line + controls */
.period-pending { color: var(--amber); font-size: 13px; margin-top: 4px; }
.period-controls { margin-top: 8px; display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.btn.tiny[disabled] { opacity: 0.45; cursor: not-allowed; }


/* ============================================================
   Efficio branding
   ============================================================ */
.brand-icon { display: block; border-radius: 12px; }
.brand-icon.sm { width: 40px; height: 40px; }
.login-card .brand-icon { margin: 0 auto 12px; width: 64px; height: 64px; }


/* ============================================================
   Multi-client
   ============================================================ */
.client-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 10px; margin-bottom: 10px; background: var(--bg-2);
}
#clientSwitcher { max-width: 180px; }


/* ============================================================
   Finance
   ============================================================ */
.finance-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px;
}
.fin-cell {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  font-size: 18px; font-weight: 700;
}
.fin-cell .card-label { font-size: 11px; }
.fin-cell.balance { grid-column: 1 / -1; background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: #fff; }
.fin-cell.balance .card-label { color: rgba(255,255,255,0.85); }
.led-bonus { color: var(--green); }
.led-advance, .led-payment { color: var(--amber); }
@media (max-width: 640px) { .finance-grid { grid-template-columns: 1fr 1fr; } }


/* Overview "needs attention" items */
.attention-item {
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg-2); margin-bottom: 8px; font-size: 14px;
}
