:root {
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: #1b2635;
  background: #f3f6f8;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding: 26px 5vw 22px;
  color: #fff;
  background: linear-gradient(135deg, #123d55, #176b73);
}

h1, h2, h3, p { margin: 0; }
h1 { margin-top: 4px; font-size: clamp(24px, 3vw, 34px); }
h2 { font-size: 26px; }
h3 { font-size: 18px; }
.eyebrow { color: #7e93a2; font-size: 11px; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase; }
.topbar .eyebrow { color: #b8e5e3; }
.topbar-actions, .dialog-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.user-pill {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px;
  color: #e5fbfa;
  font-weight: 800;
}
.button {
  border: 0;
  border-radius: 9px;
  padding: 11px 16px;
  font-weight: 700;
  transition: .18s ease;
}
.button:hover { transform: translateY(-1px); }
.button.primary { color: #fff; background: #e56b43; box-shadow: 0 4px 11px rgba(95, 39, 20, .2); }
.button.secondary { color: #315061; background: #fff; border: 1px solid #dce5e9; }
.button.danger { color: #fff; background: #b94c3b; }
.file-button input { display: none; }

.page-shell { width: min(1440px, 92vw); margin: 0 auto; padding: 22px 0 48px; }
.tabs { display: flex; gap: 6px; margin-bottom: 20px; border-bottom: 1px solid #d9e1e5; }
.tab { padding: 12px 16px; border: 0; color: #6d7d87; background: transparent; font-weight: 800; }
.tab.active { color: #176b73; border-bottom: 3px solid #176b73; }
.view { display: none; }
.view.active { display: block; }
.section-heading, .panel-heading, .dialog-heading {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
}
.section-heading { margin: 0 0 16px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.stat-card, .panel, .person-card {
  border: 1px solid #e0e8eb; border-radius: 14px; background: #fff;
  box-shadow: 0 5px 18px rgba(33, 58, 69, .05);
}
.stat-card { padding: 18px; }
.stat-card .value { margin-top: 9px; color: #183849; font-size: clamp(20px, 2.6vw, 30px); font-weight: 800; }
.stat-card .hint { margin-top: 6px; color: #71828c; font-size: 13px; }
.stat-card .positive { color: #257c66; }
.stat-card .negative { color: #d45e40; }

.dashboard-grid { display: grid; grid-template-columns: 1.7fr 1fr; gap: 16px; margin-bottom: 16px; }
.panel { padding: 18px; }
.panel-heading { margin-bottom: 16px; }
.chart { min-height: 270px; overflow-x: auto; }
.chart svg { min-width: 620px; width: 100%; height: 270px; overflow: visible; }
.chart-label { fill: #81919b; font-size: 11px; }
.chart-line { fill: none; stroke: #176b73; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: url(#trendGradient); }
.chart-dot { fill: #fff; stroke: #176b73; stroke-width: 3; }
.chart-grid { stroke: #e8eef0; stroke-width: 1; }

.ranking-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; padding: 11px 0; border-bottom: 1px solid #edf1f2; }
.ranking-row:last-child { border-bottom: 0; }
.rank { display: grid; width: 24px; height: 24px; place-items: center; border-radius: 50%; color: #176b73; background: #e5f3f2; font-size: 12px; font-weight: 800; }
.ranking-row strong { color: #23404d; font-size: 14px; }

.toolbar { display: grid; grid-template-columns: 1fr 220px 200px; gap: 10px; margin-bottom: 14px; }
.journal-toolbar { grid-template-columns: minmax(260px, 560px); }
input, select, textarea {
  width: 100%; border: 1px solid #d3dee2; border-radius: 8px; padding: 10px 12px; color: #28404e; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(23, 107, 115, .14); border-color: #176b73; }
.period-filter label, .form-grid label { display: grid; gap: 6px; color: #60747e; font-size: 12px; font-weight: 800; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 10px; border-bottom: 1px solid #edf1f2; text-align: left; white-space: nowrap; }
th { color: #84949d; font-size: 11px; letter-spacing: .5px; text-transform: uppercase; }
td { color: #405763; font-size: 14px; }
tr:last-child td { border-bottom: 0; }
.amount { color: #173f50; font-weight: 800; }
.amount.negative { color: #d45e40; }
.amount.positive { color: #257c66; }
.link-button { border: 0; color: #176b73; background: transparent; font-weight: 800; }
.muted { color: #91a0a8; font-size: 13px; }
.login-help { margin-top: 12px; }
.empty { padding: 30px 10px; color: #81919b; text-align: center; }

.people-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.person-card { padding: 18px; }
.person-card h3 { margin-bottom: 14px; }
.person-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.person-metric { padding: 10px; border-radius: 9px; background: #f5f8f8; }
.person-metric span { display: block; color: #8a9aa3; font-size: 11px; font-weight: 800; text-transform: uppercase; }
.person-metric strong { display: block; margin-top: 5px; color: #244454; font-size: 17px; }

dialog { width: min(680px, 94vw); border: 0; padding: 0; border-radius: 14px; box-shadow: 0 20px 70px rgba(10, 36, 47, .3); }
dialog::backdrop { background: rgba(17, 43, 53, .45); }
.dialog-card { padding: 22px; }
#clientDialog { width: min(1000px, 96vw); max-width: 96vw; }
.client-card { width: auto; min-height: 360px; overflow: hidden; }
.icon-button { border: 0; color: #71828c; background: transparent; font-size: 28px; line-height: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 20px; }
.full-width { grid-column: 1 / -1; }
.dialog-actions { justify-content: flex-end; margin-top: 20px; }
.split-actions { justify-content: flex-start; }
.action-spacer { flex: 1; }
.journal-comment { min-width: 220px; max-width: 420px; white-space: normal; }
.client-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 20px 0; }
.client-summary div { padding: 12px; border-radius: 9px; background: #f4f8f8; }
.client-summary span { display: block; color: #84949d; font-size: 11px; font-weight: 800; text-transform: uppercase; }
.client-summary strong { display: block; margin-top: 5px; color: #23404d; }
.client-details { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 20px; }
.client-history {
  max-height: min(340px, 42vh);
  margin-top: 8px;
  padding-right: 10px;
  overflow-x: hidden;
  overflow-y: auto;
}
.client-history .history-item { min-width: 0; }
.client-history .history-top { align-items: flex-start; flex-wrap: wrap; }
.client-history .history-item p { overflow-wrap: anywhere; white-space: normal; }
.history-item { padding: 13px 0; border-top: 1px solid #e9eff1; }
.history-top { display: flex; justify-content: space-between; gap: 12px; }
.history-item p { margin-top: 6px; color: #677b85; font-size: 14px; }
.tag { display: inline-block; padding: 3px 7px; border-radius: 20px; color: #176b73; background: #e5f3f2; font-size: 11px; font-weight: 800; }

.toast {
  position: fixed; right: 22px; bottom: 22px; max-width: 340px; padding: 12px 16px; border-radius: 9px;
  color: #fff; background: #244d5b; box-shadow: 0 8px 24px rgba(20, 50, 61, .25);
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: .2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .people-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .page-shell { width: min(94vw, 620px); }
  .toolbar, .form-grid { grid-template-columns: 1fr; }
  .full-width { grid-column: auto; }
  .people-grid { grid-template-columns: 1fr; }
  .client-summary { grid-template-columns: 1fr; }
}
