:root {
  color-scheme: light;
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-soft: #eef2ef;
  --line: #dbe1dc;
  --line-strong: #c8d0ca;
  --text: #17201b;
  --muted: #68736c;
  --brand: #167354;
  --brand-strong: #0e5a40;
  --brand-soft: #e2f1e9;
  --amber: #b26914;
  --amber-soft: #fff0d8;
  --red: #b53d3d;
  --red-soft: #fde9e8;
  --blue: #276c96;
  --blue-soft: #e3f0f7;
  --shadow: 0 8px 24px rgba(31, 45, 36, 0.08);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #edf1ed;
}

.login-panel {
  width: min(420px, 100%);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.brand-lockup > div { min-width: 0; display: grid; gap: 2px; }
.brand-lockup strong { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-lockup span:not(.brand-mark) { color: var(--muted); font-size: 12px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
}

.login-form {
  display: grid;
  gap: 18px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-form h1 { margin: 0 0 6px; font-size: 22px; }
.login-form p { margin: 0; color: var(--muted); }
label { display: grid; gap: 7px; font-weight: 600; }
.checkbox-field { display: flex; align-items: center; gap: 9px; }
.checkbox-field input { width: 18px; height: 18px; accent-color: var(--brand); }

.compensation-box {
  margin: 4px 0 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.compensation-box legend { padding: 0 6px; font-weight: 750; }
.commission-settings { display: grid; gap: 10px; }
.subsection-heading { min-height: 38px; display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 700; }
#service-rate-list { display: grid; gap: 8px; }
.service-rate-row { display: grid; grid-template-columns: minmax(180px, 1fr) 130px 36px; gap: 8px; align-items: center; }
.percent-input { position: relative; }
.percent-input input { padding-right: 34px; }
.percent-input span { position: absolute; right: 12px; top: 11px; color: var(--muted); }
.field-note { margin: 0; color: var(--muted); font-size: 12px; font-weight: 500; }
.calculation-preview { min-height: 44px; display: flex; align-items: center; padding: 10px 12px; background: var(--brand-soft); color: var(--brand-strong); border-radius: 6px; font-weight: 700; }
.earnings-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.earnings-strip > div { display: grid; gap: 4px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.earnings-strip span, .earnings-strip small { color: var(--muted); }
.earnings-strip strong { font-size: 20px; }

input, select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(22, 115, 84, 0.12); }
.password-field { position: relative; }
.password-field input { padding-right: 44px; }
.password-field .icon-button { position: absolute; right: 3px; top: 3px; }

.form-error { min-height: 18px; color: var(--red) !important; font-weight: 600; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: #18241e;
  color: #fff;
  border-right: 1px solid #26362d;
  z-index: 30;
}

.sidebar-brand { padding: 18px; margin: 0; border-bottom: 1px solid #2b3a32; }
.sidebar-brand span:not(.brand-mark) { color: #aebbb3; }
.main-nav { display: grid; align-content: start; gap: 4px; padding: 14px 10px; overflow-y: auto; }

.nav-button {
  width: 100%;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #cbd5cf;
  text-align: left;
}
.nav-button:hover { background: #23332a; color: #fff; }
.nav-button.active { background: #2c4939; color: #fff; }
.nav-button svg { width: 18px; height: 18px; flex: 0 0 18px; }

.sidebar-user {
  min-width: 0;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 36px;
  gap: 10px;
  align-items: center;
  padding: 14px;
  border-top: 1px solid #2b3a32;
}
.sidebar-user > div { min-width: 0; display: grid; gap: 2px; }
.sidebar-user strong, .sidebar-user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user span { color: #aebbb3; font-size: 12px; }
.user-avatar { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: #d9eadf; color: #154a36 !important; font-weight: 800; }

.workspace { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 72px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  background: rgba(255,255,255,0.96);
  border-bottom: 1px solid var(--line);
}
.topbar > div:nth-child(2) { min-width: 0; }
.topbar h1 { margin: 0; font-size: 20px; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.connection-state { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.connection-state > span { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.connection-state.offline > span { background: var(--red); }

.page-content { max-width: 1540px; margin: 0 auto; padding: 22px 24px 40px; outline: none; }
.page-head { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head h2 { margin: 0; font-size: 17px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.button-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

.icon-button, .primary-button, .secondary-button, .danger-button {
  border: 0;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px;
  font-weight: 650;
}
.icon-button { width: 36px; padding: 0; background: transparent; color: var(--muted); }
.icon-button:hover { background: var(--surface-soft); color: var(--text); }
.icon-button.inverse { color: #cbd5cf; }
.icon-button.inverse:hover { background: #2b3a32; color: #fff; }
.primary-button { background: var(--brand); color: #fff; }
.primary-button:hover { background: var(--brand-strong); }
.secondary-button { background: var(--surface); color: var(--text); border: 1px solid var(--line-strong); }
.secondary-button:hover { background: var(--surface-soft); }
.danger-button { background: var(--red); color: #fff; }
.danger-button:hover { background: #963333; }
button:disabled { opacity: 0.48; cursor: not-allowed; }
button svg { width: 17px; height: 17px; }
.login-button { width: 100%; height: 44px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric {
  min-width: 0;
  min-height: 116px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.metric-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); }
.metric-icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 6px; background: var(--brand-soft); color: var(--brand); }
.metric-icon.amber { background: var(--amber-soft); color: var(--amber); }
.metric-icon.blue { background: var(--blue-soft); color: var(--blue); }
.metric-icon.red { background: var(--red-soft); color: var(--red); }
.metric strong { display: block; margin-top: 15px; font-size: 25px; line-height: 1; font-variant-numeric: tabular-nums; }
.metric small { display: block; margin-top: 7px; color: var(--muted); }

.content-band { margin-top: 14px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 10px; }
.section-heading h2 { margin: 0; font-size: 16px; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th { height: 42px; padding: 0 14px; background: #f0f3f0; color: #566159; text-align: left; font-size: 12px; font-weight: 750; white-space: nowrap; }
td { height: 50px; padding: 8px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: #f8faf8; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.primary-cell { min-width: 240px; }
.primary-cell strong, .primary-cell span { display: block; }
.primary-cell span { margin-top: 3px; color: var(--muted); font-size: 12px; max-width: 420px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.status-pill { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 8px; border-radius: 999px; background: var(--surface-soft); color: #4a554e; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-pill.working { background: var(--brand-soft); color: var(--brand-strong); }
.status-pill.paused { background: var(--blue-soft); color: var(--blue); }
.status-pill.warning { background: var(--amber-soft); color: #8b510f; }
.status-pill.error { background: var(--red-soft); color: var(--red); }

.selection-bar {
  position: sticky;
  bottom: 16px;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  max-width: 100%;
  margin: 16px auto 0;
  padding: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}
.selection-bar > span { padding: 0 8px; white-space: nowrap; }

.project-list { display: grid; gap: 10px; }
.project-row {
  display: grid;
  grid-template-columns: 24px minmax(220px, 1.5fr) minmax(160px, 0.8fr) minmax(150px, 0.7fr) 120px;
  align-items: center;
  gap: 14px;
  min-height: 84px;
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.project-row.selected { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(22,115,84,.1); }
.project-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }
.project-name { min-width: 0; }
.project-name strong { display: block; font-size: 15px; overflow-wrap: anywhere; }
.project-name p { margin: 5px 0 0; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.project-detail { color: var(--muted); }
.project-detail strong { display: block; margin-top: 4px; color: var(--text); font-weight: 650; }
.project-base { text-align: right; }
.open-badge { margin-left: 7px; color: var(--brand); font-size: 12px; }

.session-list { display: grid; gap: 8px; }
.session-row { display: flex; align-items: center; gap: 12px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.session-row .pulse { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.session-row > div { flex: 1; min-width: 0; }
.session-row strong { display: block; }
.session-row span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }

.empty-state { padding: 34px; text-align: center; border: 1px dashed var(--line-strong); border-radius: 8px; color: var(--muted); background: rgba(255,255,255,.55); }
.empty-state svg { width: 30px; height: 30px; margin-bottom: 10px; color: #89958d; }
.empty-state strong { display: block; color: var(--text); margin-bottom: 5px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; min-width: 160px; }
.search-field { position: relative; }
.search-field input { padding-left: 38px; min-width: 260px; }
.search-field svg { position: absolute; left: 12px; top: 12px; width: 17px; height: 17px; color: var(--muted); }

.circle-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.circle-item { padding: 14px; border-left: 3px solid var(--brand); background: var(--surface); border-top: 1px solid var(--line); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); border-radius: 6px; }
.circle-item:nth-child(2) { border-left-color: #3e9d9a; }
.circle-item:nth-child(3) { border-left-color: #77817b; }
.circle-item:nth-child(4) { border-left-color: #86a836; }
.circle-item span { display: block; color: var(--muted); }
.circle-item strong { display: block; margin-top: 8px; font-size: 20px; font-variant-numeric: tabular-nums; }
.circle-item small { display: block; margin-top: 5px; color: var(--muted); }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(15, 25, 19, 0.48); }
.modal { width: min(720px, 100%); max-height: calc(100vh - 40px); overflow: hidden; background: #fff; border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,.22); }
.modal > header { height: 58px; display: flex; align-items: center; padding: 0 18px; border-bottom: 1px solid var(--line); }
.modal h2 { margin: 0; font-size: 18px; flex: 1; }
.modal-content { padding: 18px; max-height: calc(100vh - 170px); overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.modal-copy { margin: 0 0 16px; color: var(--muted); line-height: 1.5; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice-button { min-height: 100px; display: grid; place-items: start; align-content: center; gap: 6px; padding: 15px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--text); text-align: left; }
.choice-button:hover { border-color: var(--brand); background: var(--brand-soft); }
.choice-button strong { font-size: 15px; }
.choice-button span { color: var(--muted); line-height: 1.4; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }

.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 120; display: grid; gap: 8px; width: min(380px, calc(100vw - 36px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 13px 14px; border-radius: 8px; background: #1c2a22; color: #fff; box-shadow: var(--shadow); }
.toast.error { background: #762e2e; }
.toast svg { flex: 0 0 18px; width: 18px; height: 18px; margin-top: 1px; }
.toast div { line-height: 1.4; }

.skeleton { min-height: 110px; border-radius: 8px; background: #e8ece8; animation: pulse 1.2s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .65; } to { opacity: 1; } }
.mobile-only { display: none; }

@media (max-width: 1120px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .project-row { grid-template-columns: 24px minmax(220px, 1.5fr) minmax(160px, 1fr) 100px; }
  .project-row .hide-medium { display: none; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; left: -244px; width: 232px; transition: left .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { left: 0; }
  .mobile-only { display: inline-flex; }
  .topbar { height: 64px; padding: 0 12px; }
  .topbar h1 { font-size: 17px; }
  .topbar p, .connection-state { display: none; }
  .page-content { padding: 16px 12px 132px; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric { min-height: 104px; padding: 13px; }
  .metric strong { font-size: 21px; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .project-row { grid-template-columns: 24px minmax(0, 1fr) 82px; gap: 9px; }
  .project-row .project-detail, .project-row .hide-medium { display: none; }
  .project-base { font-size: 12px; }
  .selection-bar {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: 8px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: auto;
  }
  .selection-bar > span { display: none; }
  .selection-bar button { width: 100%; min-width: 0; }
  .circle-grid { grid-template-columns: 1fr 1fr; }
  .form-grid, .choice-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .compensation-box { grid-template-columns: 1fr; }
  .service-rate-row { grid-template-columns: minmax(0, 1fr) 100px 36px; }
  .earnings-strip { grid-template-columns: 1fr; }
  .search-field, .search-field input { width: 100%; min-width: 0; }
}

@media (max-width: 420px) {
  .metric-grid, .circle-grid { grid-template-columns: 1fr; }
}
