:root {
  --primary: #1F4E78;
  --primary-light: #2d6da3;
  --primary-dark: #163a5c;
  --accent: #ff8a3d;
  --bg: #f0f3f7;
  --card-bg: #ffffff;
  --border: #e4e8ed;
  --text: #1a1f28;
  --text-muted: #6b7280;
  --success: #1e8e5a;
  --success-bg: #e3f6ed;
  --warning: #b8720c;
  --warning-bg: #fff3e0;
  --danger: #c8382f;
  --danger-bg: #fdeceb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16,24,40,0.06), 0 1px 2px rgba(16,24,40,0.04);
  --shadow-md: 0 4px 12px rgba(16,24,40,0.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Topbar ---------- */
.topbar {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: -0.2px; }
.topbar h1 .emoji { margin-right: 6px; }
.topbar .userinfo { font-size: 14px; display: flex; align-items: center; gap: 12px; }
.topbar button {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.35);
  color: white;
  padding: 7px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
}
.topbar button:hover { background: rgba(255,255,255,0.28); }

/* ---------- Layout ---------- */
.container { max-width: 1150px; margin: 24px auto; padding: 0 20px 60px; }
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

/* ---------- Tabs (desktop) ---------- */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 2px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 11px 18px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--accent); }
.tab:hover:not(.active) { color: var(--primary-light); }
.tab-content { display: none; animation: fadeIn 0.2s ease; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { color: var(--text-muted); font-weight: 700; text-transform: uppercase; font-size: 11px; letter-spacing: 0.4px; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: #f8fafc; }

/* ---------- Badges ---------- */
.badge { padding: 3px 11px; border-radius: 20px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.badge-signed, .badge-completed, .badge-in_progress, .badge-extended { background: var(--success-bg); color: var(--success); }
.badge-draft, .badge-not_started { background: #eef0f3; color: var(--text-muted); }
.badge-sent, .badge-sent_for_sign { background: var(--warning-bg); color: var(--warning); }
.badge-cancelled, .badge-on_hold { background: var(--danger-bg); color: var(--danger); }
.badge-closed { background: #ede9fe; color: #6d28d9; }
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  background: #eef2ff;
  color: #4338ca;
}
.pill-project { background: #ecfdf5; color: #047857; }

/* ---------- Forms ---------- */
form.inline-form { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 4px; align-items: center; }
input, select, textarea {
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-light); }
textarea { resize: vertical; min-height: 40px; }
button.primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(31,78,120,0.25);
  transition: transform 0.1s, box-shadow 0.1s;
}
button.primary:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(31,78,120,0.32); }
button.primary:active { transform: translateY(0); }
button.link {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 8px;
}
button.link:hover { text-decoration: underline; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 55%, var(--primary-light) 100%);
  padding: 20px;
}
.login-box {
  background: white;
  padding: 40px 36px;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 340px;
}
.login-box .brand { text-align: center; margin-bottom: 8px; font-size: 30px; }
.login-box h2 { margin: 0 0 22px; color: var(--primary); text-align: center; font-size: 20px; }
.login-box input { width: 100%; margin-bottom: 12px; padding: 11px 14px; }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; text-align: center; }

/* ---------- Reports / exports ---------- */
.export-links a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 10px 10px 0;
  padding: 10px 16px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  text-decoration: none;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(31,78,120,0.2);
}
.export-links a:hover { transform: translateY(-1px); }

.section-title { font-size: 15.5px; font-weight: 700; margin-bottom: 14px; color: var(--primary-dark); display: flex; align-items: center; gap: 6px; }
.helper-text { color: var(--text-muted); font-size: 12.5px; margin-top: 10px; }

/* ---------- Simple CSS bar chart for forecasts (legacy, kept for reuse) ---------- */
.forecast-bars { display: flex; align-items: flex-end; gap: 10px; height: 160px; padding: 10px 0 4px; }
.forecast-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.forecast-bar {
  width: 100%;
  max-width: 44px;
  background: linear-gradient(180deg, var(--accent) 0%, #ff6b1a 100%);
  border-radius: 6px 6px 2px 2px;
  min-height: 4px;
  transition: height 0.4s ease;
}
.forecast-bar.hours { background: linear-gradient(180deg, #34d399 0%, #059669 100%); }
.forecast-bar-label { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.forecast-bar-value { font-size: 11px; color: var(--text); font-weight: 700; }

/* ---------- Fancy SVG area/line chart ---------- */
.chart-container { width: 100%; padding: 6px 0; }
.chart-container svg circle { transition: r 0.15s; cursor: pointer; }
.chart-container svg circle:hover { r: 7; }
.chart-stats { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.chart-stat { flex: 1; min-width: 120px; }
.chart-stat-label { display: block; font-size: 10.5px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; }
.chart-stat-value { display: block; font-size: 15px; font-weight: 800; color: var(--primary-dark); margin-top: 2px; }

/* ---------- Revenue breakdown bars ---------- */
.breakdown-list { display: flex; flex-direction: column; gap: 12px; }
.breakdown-row { display: grid; grid-template-columns: 160px 1fr 90px; align-items: center; gap: 12px; }
.breakdown-label { font-size: 13.5px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breakdown-track { height: 10px; background: #eef1f5; border-radius: 6px; overflow: hidden; }
.breakdown-fill { height: 100%; background: linear-gradient(90deg, #6366f1, #4338ca); border-radius: 6px; transition: width 0.4s ease; }
.breakdown-value { font-size: 13px; font-weight: 700; color: var(--primary-dark); text-align: right; }
@media (max-width: 600px) {
  .breakdown-row { grid-template-columns: 100px 1fr 70px; gap: 8px; }
  .breakdown-label { font-size: 12px; }
}

/* ---------- Stat cards ---------- */
.stat-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 4px; }
.stat-card {
  flex: 1;
  min-width: 140px;
  background: linear-gradient(135deg, #fff 0%, #f6f9fc 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-card .label { font-size: 11.5px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; }
.stat-card .value { font-size: 22px; font-weight: 800; color: var(--primary-dark); margin-top: 4px; }

/* ---------- Mobile hamburger ---------- */
.hamburger {
  display: none;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.35);
  color: white;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
}

/* ---------- Modal (detail view) ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 32px 16px;
  z-index: 100;
  overflow-y: auto;
}
.modal-box {
  background: var(--card-bg);
  border-radius: 14px;
  width: 100%;
  max-width: 780px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: modalIn 0.18s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border-radius: 14px 14px 0 0;
}
.modal-header h2 { margin: 0; font-size: 17px; font-weight: 700; }
.modal-close {
  background: rgba(255,255,255,0.18);
  border: none; color: white;
  width: 30px; height: 30px; border-radius: 50%;
  cursor: pointer; font-size: 16px; line-height: 1;
}
.modal-body { padding: 20px 22px 28px; max-height: 78vh; overflow-y: auto; }
.modal-section { margin-bottom: 24px; }
.modal-section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--primary); margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between;
}
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; }
.detail-field label { display: block; font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin-bottom: 3px; }
.detail-field .value { font-size: 14px; color: var(--text); }
.detail-field.full { grid-column: 1 / -1; }
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: #eef2ff; color: #4338ca;
  padding: 5px 12px; border-radius: 20px; font-size: 12.5px; font-weight: 600;
}
.tag button { background: none; border: none; color: #4338ca; cursor: pointer; font-size: 13px; padding: 0; }
.note-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.note-item:last-child { border-bottom: none; }
.note-meta { font-size: 11.5px; color: var(--text-muted); margin-bottom: 3px; font-weight: 600; }
.note-body { font-size: 13.5px; color: var(--text); white-space: pre-wrap; }
.attachment-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.attachment-item:last-child { border-bottom: none; }
.attachment-item a { color: var(--primary); text-decoration: none; font-weight: 600; }
.attachment-item a:hover { text-decoration: underline; }
.small-form { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.small-form input, .small-form select, .small-form textarea { flex: 1; min-width: 100px; }
.linklike { color: var(--primary); cursor: pointer; font-weight: 700; text-decoration: none; }
.linklike:hover { text-decoration: underline; }
button.secondary {
  background: #eef0f3; color: var(--text); border: 1px solid var(--border);
  padding: 7px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600;
}
button.small { padding: 6px 12px; font-size: 12.5px; }

@media (max-width: 640px) {
  .modal-box { max-width: 100%; }
  .modal-body { padding: 16px; }
  .detail-grid { grid-template-columns: 1fr; }
  .small-form { flex-direction: column; }
}
@media (max-width: 768px) {
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 16px; }
  .container { padding: 0 12px 40px; margin: 16px auto; }
  .card { padding: 16px; }
  form.inline-form { flex-direction: column; align-items: stretch; }
  form.inline-form input, form.inline-form select, form.inline-form textarea { width: 100%; }
  form.inline-form button.primary { width: 100%; }
  .tabs { gap: 2px; }
  .tab { padding: 9px 12px; font-size: 13px; }
  table { min-width: 480px; }
  .stat-row { flex-direction: column; }
  .export-links a { width: 100%; justify-content: center; margin-right: 0; }
  .userinfo span { display: none; }
  .forecast-bars { height: 130px; }
}
@media (max-width: 420px) {
  .login-box { padding: 30px 22px; }
}

/* ---------- Category bar chart (revenue by status/type/PM) ---------- */
.cat-bar-row { display: grid; grid-template-columns: 140px 1fr 90px; align-items: center; gap: 12px; margin-bottom: 10px; }
.cat-bar-label { font-size: 13px; font-weight: 600; color: var(--text); text-transform: capitalize; }
.cat-bar-count { color: var(--text-muted); font-weight: 500; font-size: 11.5px; }
.cat-bar-track { background: #eef1f5; border-radius: 20px; height: 14px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 20px; transition: width 0.4s ease; }
.cat-bar-value { font-size: 13px; font-weight: 700; color: var(--primary-dark); text-align: right; }

/* ---------- Donut chart with legend ---------- */
.donut-wrap { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.donut-legend { flex: 1; min-width: 180px; }
.donut-legend-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.donut-swatch { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.donut-legend-label { flex: 1; color: var(--text); font-weight: 600; text-transform: capitalize; }
.donut-legend-value { color: var(--text-muted); font-weight: 600; font-size: 12.5px; }

/* ---------- Revenue summary total boxes ---------- */
.revenue-totals { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.revenue-total-box {
  flex: 1; min-width: 150px;
  background: linear-gradient(135deg, #fff 0%, #f6f9fc 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.revenue-total-box.highlight { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%); border: none; }
.revenue-total-box.highlight .label { color: rgba(255,255,255,0.85); }
.revenue-total-box.highlight .value { color: white; }
.revenue-total-box .label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; }
.revenue-total-box .value { font-size: 20px; font-weight: 800; color: var(--primary-dark); margin-top: 4px; }

@media (max-width: 640px) {
  .cat-bar-row { grid-template-columns: 100px 1fr 70px; gap: 8px; }
  .donut-wrap { flex-direction: column; align-items: center; }
}
