:root {
  color-scheme: light;
  --ink: #20201e;
  --muted: #73736e;
  --line: #e4e4e0;
  --surface: #ffffff;
  --surface-soft: #f8f8f6;
  --sidebar: #f4f4f1;
  --background: #fafaf9;
  --success: #0d8a62;
  --danger: #a03430;
  --warning: #765a28;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--background);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; min-height: 100%; overflow-x: hidden; }
body { min-width: 320px; min-height: 100vh; margin: 0; overflow-x: hidden; background: var(--background); }
button, input, select, textarea { font: inherit; }
button, [role="button"], input, select, textarea { outline-offset: 2px; }
:focus-visible { outline: 2px solid #4d84c4; }
h1, h2, h3, h4, p { margin: 0; }
.hidden { display: none !important; }

.app-shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: 228px;
  padding: 18px 12px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 8px; font-size: 15px; font-weight: 600; letter-spacing: -.02em; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; flex: none; border-radius: 8px; color: #fff; background: var(--ink); font-size: 11px; font-weight: 700; letter-spacing: .02em; }
.brand-mark.login-mark { width: 44px; height: 44px; margin-bottom: 20px; border-radius: 10px; font-size: 13px; }
.sidebar nav { display: grid; gap: 3px; margin-top: 24px; }
.nav-item {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 10px;
  border: 0;
  border-radius: 7px;
  color: #62625d;
  background: transparent;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
}
.nav-item:hover { color: var(--ink); background: #eaeae6; }
.nav-item.active { color: var(--ink); background: #e5e5e1; font-weight: 600; }
.nav-icon { display: grid; place-items: center; width: 20px; height: 20px; color: #7c7c76; font-size: 11px; font-weight: 700; }
.docs-link, .logout {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
}
.docs-link { margin-top: auto; }
.docs-link:hover, .logout:hover { color: var(--ink); background: #eaeae6; }

main { grid-column: 2; min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  height: 82px;
  padding: 18px 34px;
  border-bottom: 1px solid var(--line);
  background: rgb(250 250 249 / 94%);
  backdrop-filter: blur(12px);
}
.topbar h1 { margin-top: 2px; font-size: 22px; font-weight: 600; line-height: 1.4; letter-spacing: -.02em; }
.eyebrow { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .11em; }
.connection { display: inline-flex; align-items: center; gap: 7px; min-height: 34px; padding: 0 11px; border: 1px solid #dcdcd7; border-radius: 7px; color: #5f5f59; background: #fff; font-size: 12px; font-weight: 500; white-space: nowrap; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px #d8efe7; }

.panel {
  width: calc(100% - 68px);
  max-width: 1420px;
  margin: 30px auto 60px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.section-head h2 { font-size: 19px; font-weight: 600; }
.section-head h3 { font-size: 16px; font-weight: 600; }
.section-head p { margin-top: 6px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.section-head.compact { margin-bottom: 14px; }

.button { min-height: 42px; padding: 0 16px; border: 1px solid #d3d3ce; border-radius: 8px; color: #54544f; background: #fff; font-size: 14px; font-weight: 600; cursor: pointer; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 22px 0 12px; color: var(--muted); font-size: 14px; }
input, select, textarea { min-height: 44px; padding: 9px 12px; border: 1px solid #cfcfca; border-radius: 8px; color: var(--ink); background: #fff; font-size: 15px; }
input:hover, select:hover, textarea:hover { border-color: #a9a9a3; }
input[type="search"] { width: 270px; }
.check { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 14px; }
.check input { width: 17px; height: 17px; min-height: auto; accent-color: var(--ink); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
#panel-roles table { table-layout: fixed; }
#panel-roles th:first-child, #panel-roles td:first-child { width: 240px; overflow-wrap: anywhere; }
table { width: 100%; min-width: 680px; border-collapse: collapse; font-size: 14px; }
th { padding: 12px 16px; border-bottom: 1px solid var(--line); color: #6f6f69; background: var(--surface-soft); font-size: 12px; font-weight: 600; text-align: left; text-transform: uppercase; letter-spacing: .05em; }
td { padding: 14px 16px; border-bottom: 1px solid #ededeb; vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .15s; }
tbody tr:hover { background: #fafaf8; }
tbody tr:last-child td { border-bottom: 0; }
td strong { font-size: 14px; font-weight: 600; }
.badge { display: inline-flex; align-items: center; min-height: 27px; padding: 0 10px; border-radius: 99px; font-size: 12px; font-weight: 500; }
.badge.active { color: #087653; background: #e7f4ef; }
.badge.archived { color: #6d6d67; background: #efefec; }
.empty { min-height: 140px; padding: 40px; color: #73736e; text-align: center; font-size: 14px; }

.contract-block { margin-top: 22px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.contract-switcher { display: flex; align-items: end; gap: 12px; padding: 16px 18px; background: var(--surface-soft); border-bottom: 1px solid var(--line); }
.contract-switcher label { display: grid; flex: 1; gap: 7px; color: #555550; font-size: 13px; font-weight: 600; }
.contract-switcher select { width: 100%; }
.contract-form { padding: 20px 18px 18px; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; }
.form-grid label { display: grid; align-content: start; gap: 7px; color: #555550; font-size: 13px; font-weight: 600; }
.form-grid .wide-field { grid-column: span 2; }
.money-fields { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.contract-actions { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 18px; }
.contract-actions span { max-width: 720px; color: var(--muted); font-size: 13px; line-height: 1.45; }
input[readonly] { color: #777771; background: #f4f4f1; }
.cards-section-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-top: 28px; }
.cards-section-head h3 { font-size: 17px; font-weight: 600; }
.cards-section-head p { margin-top: 5px; color: var(--muted); font-size: 13px; }
.bonus-cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 14px; margin-top: 14px; }
.bonus-card { min-width: 0; padding: 18px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s; }
.bonus-card:hover { border-color: #bdbdb7; box-shadow: 0 7px 24px rgb(32 32 30 / 7%); transform: translateY(-1px); }
.bonus-card.archived-card { background: #fff1f2; border-color: #fecdd3; }
.bonus-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.bonus-card-head h4 { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.bonus-card-head div > span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.card-role { margin-top: 16px; padding-bottom: 13px; border-bottom: 1px solid var(--line); color: #595954; font-size: 14px; }
.card-role strong { float: right; color: var(--ink); font-weight: 650; }
.card-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 18px; margin-top: 15px; }
.card-metrics div { display: grid; gap: 4px; }
.card-metrics span { color: var(--muted); font-size: 12px; }
.card-metrics strong { font-size: 15px; font-weight: 650; }
.card-metrics .available-metric strong { color: var(--success); }
.bonus-card-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 17px; padding-top: 13px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.bonus-card-foot span:last-child { color: #4f4f4b; font-weight: 600; white-space: nowrap; }
.card-error { margin-top: 14px; padding: 11px; border-radius: 7px; color: var(--danger); background: #fcecea; font-size: 13px; }
.cards-empty { margin-top: 14px; border: 1px dashed #d8d8d3; border-radius: 10px; background: #fafaf8; }

.card-dialog { width: min(760px, calc(100vw - 32px)); }
.card-person-fields { grid-template-columns: 1fr 1.5fr; }
.card-person-fields label:last-child { grid-column: 1 / -1; }
.factor-fieldset { margin: 20px 0 0; padding: 0; border: 0; }
.factor-fieldset legend { margin-bottom: 11px; color: #555550; font-size: 14px; font-weight: 600; }
.factor-list { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.factor-option { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; align-items: start; gap: 9px; min-height: 46px; margin: 0; padding: 11px; border: 1px solid var(--line); border-radius: 8px; color: #484844; background: #fff; font-size: 13px; font-weight: 500; cursor: pointer; }
.factor-option:hover { background: #fafaf8; }
.factor-option input { width: 17px; height: 17px; min-height: auto; margin: 1px 0 0; accent-color: var(--ink); }
.factor-option span { line-height: 1.35; }
.factor-option strong { color: var(--success); font-size: 12px; }
.factor-option strong.negative { color: var(--danger); }
.ktu-preview { margin-top: 11px; padding: 11px 13px; border-radius: 8px; color: #555550; background: #f3f3f0; font-size: 14px; }
.ktu-preview strong { margin-left: 4px; color: var(--ink); font-size: 16px; }
.dialog-spacer { flex: 1; }

.schedule-note { margin-top: 20px; padding: 13px 15px; border-radius: 8px; color: #555550; background: #f3f3f0; font-size: 14px; line-height: 1.5; }
.quarter-grid { display: grid; grid-template-columns: repeat(2, minmax(320px, 1fr)); gap: 16px; margin-top: 18px; }
.quarter-card { min-width: 0; padding: 22px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.quarter-head { display: flex; align-items: center; gap: 11px; margin-bottom: 20px; }
.quarter-head > span { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid #deded9; border-radius: 8px; color: #65655f; background: #f4f4f1; font-size: 12px; font-weight: 600; }
.quarter-card h3 { font-size: 16px; font-weight: 600; }
.schedule-fields { display: grid; gap: 18px; }
.schedule-payment-date { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 8px; }
.schedule-payment-date input { width: 100%; min-width: 0; appearance: textfield; -moz-appearance: textfield; }
.schedule-payment-date input::-webkit-inner-spin-button, .schedule-payment-date input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.schedule-field { display: grid; gap: 8px; min-width: 0; }
.schedule-field-label, dialog label { color: #555550; font-size: 14px; font-weight: 600; }
.datetime-picker { position: relative; min-width: 0; }
.datetime-picker.open { z-index: 40; }
.datetime-input-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 46px; align-items: stretch; min-height: 46px; border: 1px solid #cfcfca; border-radius: 8px; background: #fff; }
.datetime-input-wrap:hover { border-color: #a9a9a3; }
.datetime-input-wrap:focus-within { border-color: #4d84c4; box-shadow: 0 0 0 1px #4d84c4; }
.datetime-display { width: 100%; min-width: 0; min-height: 44px; border: 0; border-radius: 8px 0 0 8px; font-size: 16px; font-weight: 500; }
.datetime-display:hover { border-color: transparent; }
.datetime-display:focus { outline: 0; }
.picker-toggle { display: grid; place-items: center; width: 46px; min-height: 44px; padding: 0; border: 0; border-left: 1px solid #e4e4e0; border-radius: 0 8px 8px 0; color: #555550; background: #fafaf8; cursor: pointer; }
.picker-toggle:hover { color: var(--ink); background: #f0f0ed; }
.picker-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.picker-popover { position: absolute; top: calc(100% + 8px); left: 0; z-index: 50; width: min(360px, calc(100vw - 48px)); padding: 16px; border: 1px solid #d8d8d3; border-radius: 12px; background: #fff; box-shadow: 0 18px 48px rgb(32 32 30 / 18%); }
.picker-calendar-head { display: grid; grid-template-columns: 38px 1fr 38px; align-items: center; gap: 8px; margin-bottom: 12px; }
.picker-calendar-head strong { font-size: 15px; font-weight: 600; text-align: center; }
.picker-nav { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 0; border-radius: 8px; color: #555550; background: transparent; font-size: 27px; line-height: 1; cursor: pointer; }
.picker-nav:hover { color: var(--ink); background: #f0f0ed; }
.calendar-weekdays, .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar-weekdays { margin-bottom: 5px; }
.calendar-weekdays span { color: #85857f; font-size: 11px; font-weight: 600; text-align: center; text-transform: uppercase; }
.calendar-day, .calendar-spacer { min-width: 0; aspect-ratio: 1; }
.calendar-day { display: grid; place-items: center; padding: 0; border: 0; border-radius: 8px; color: #40403c; background: transparent; font-size: 13px; font-weight: 500; cursor: pointer; }
.calendar-day:hover { background: #efefec; }
.calendar-day.today { box-shadow: inset 0 0 0 1px #b7b7b1; }
.calendar-day.selected { color: #fff; background: var(--ink); box-shadow: none; }
.picker-time { display: grid; grid-template-columns: auto minmax(130px, 1fr); align-items: center; gap: 14px; margin-top: 14px; color: #555550; font-size: 13px; font-weight: 600; }
.picker-time input { width: 100%; min-height: 42px; font-size: 15px; font-weight: 500; }
.picker-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }

.banner, .notice, .warning { padding: 13px 15px; border-radius: 8px; font-size: 14px; line-height: 1.5; }
.banner { width: calc(100% - 68px); max-width: 1420px; margin: 18px auto 0; color: var(--danger); background: #fcecea; border: 1px solid #f2d3d0; }
.notice { margin-top: 18px; color: #5f5f59; background: #f3f3f0; }
.warning { margin-bottom: 14px; color: var(--warning); background: #fffaf0; border: 1px solid #e7d9bf; }
.dirty { color: var(--warning); font-size: 12px; }

.login-screen { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: #f7f7f5; }
.login-card { width: min(390px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: 0 18px 50px rgb(32 32 30 / 8%); }
.login-card h1 { font-size: 24px; font-weight: 600; letter-spacing: -.03em; }
.login-card p { margin-top: 8px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.login-card small { display: block; margin-top: 14px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.login-card label { display: grid; gap: 8px; margin: 22px 0 12px; color: #565651; font-size: 13px; font-weight: 600; }
.login-card .button { width: 100%; }
.form-error { min-height: 20px; margin-top: 9px; color: var(--danger); font-size: 13px; }

dialog { width: min(500px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 11px; color: var(--ink); background: #fff; box-shadow: 0 24px 70px rgb(32 32 30 / 24%); }
dialog::backdrop { background: rgb(32 32 30 / 32%); backdrop-filter: blur(2px); }
dialog form { padding: 24px; }
dialog label { display: grid; gap: 8px; }
.dialog-head, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dialog-head h2 { margin-bottom: 20px; font-size: 19px; font-weight: 600; }
dialog label { margin-bottom: 12px; }
.icon-button { display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; font-size: 20px; cursor: pointer; }
.icon-button:hover { background: #efefec; }
.dialog-actions { justify-content: flex-start; margin-top: 22px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 30; padding: 13px 17px; border-radius: 8px; color: #fff; background: var(--ink); box-shadow: 0 8px 26px rgb(0 0 0 / 16%); font-size: 14px; }

@media (max-width: 760px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; width: 100%; height: auto; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { height: 34px; }
  .sidebar nav { display: flex; overflow-x: auto; margin-top: 8px; }
  .nav-item { flex: none; }
  .docs-link, .logout { display: inline-flex; margin-top: 4px; }
  main { grid-column: 1; }
  .topbar { position: static; height: auto; min-height: 72px; padding: 14px 16px; }
  .panel { width: calc(100% - 32px); margin: 20px auto 40px; padding: 18px; }
  .banner { width: calc(100% - 32px); }
  .section-head { align-items: flex-start; flex-direction: column; }
  .toolbar { align-items: flex-start; flex-direction: column; }
  input[type="search"] { width: 100%; }
  .quarter-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .contract-main-fields .wide-field { grid-column: span 2; }
  .contract-actions { align-items: stretch; flex-direction: column; }
  .contract-actions .button { width: 100%; }
  .factor-list { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .connection { display: none; }
  .contract-switcher, .cards-section-head { align-items: stretch; flex-direction: column; }
  .form-grid, .card-person-fields { grid-template-columns: 1fr; }
  .contract-main-fields .wide-field, .card-person-fields label:last-child { grid-column: auto; }
  .bonus-cards-grid { grid-template-columns: 1fr; }
  .bonus-card-foot { align-items: flex-start; flex-direction: column; }
  .dialog-actions { flex-wrap: wrap; }
  .picker-popover { position: fixed; top: 50%; left: 50%; width: min(360px, calc(100vw - 28px)); max-height: calc(100vh - 28px); overflow-y: auto; transform: translate(-50%, -50%); }
}
/* Shared activity layout for existing Web-panel cards. */
.activity-tabs { display: flex; gap: 2px; width: fit-content; padding: 3px; margin: 0 0 12px; border-radius: 10px; background: #e7e7eb; }
.activity-tabs button { border: 0; padding: 7px 12px; border-radius: 7px; background: transparent; color: #6e6e73; font: inherit; cursor: pointer; }
.activity-tabs button[aria-selected="true"] { color: #1d1d1f; background: #fff; box-shadow: 0 1px 3px #0002; }
.activity-feed { max-height: min(52vh, 520px); min-height: 100px; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; font-size: 13px; }
.activity-event { padding: 12px 0; border-bottom: 1px solid #e1e5ea; }
.activity-event:first-child { padding-top: 0; }
.activity-event__meta { color: #6b7e8d; font-size: 12px; margin-bottom: 5px; }
.activity-event__description { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 5px; }
.activity-event__object { display: inline; padding: 0; border: 0; background: transparent; color: #006580; font: inherit; font-weight: 600; cursor: pointer; text-align: left; }
.activity-event__object:hover { text-decoration: underline; }
.activity-event__object:focus-visible { outline: 2px solid #0071e3; outline-offset: 3px; }
#register-details-dialog > .dialog-body { padding: 18px; }
.quarter-card .activity-feed { max-height: 300px; }
