:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --soft: #f8fafc;
  --line: #dfe5ec;
  --text: #17202a;
  --muted: #6b7785;
  --blue: #1168d8;
  --blue-dark: #0d4fa6;
  --nav: #10243b;
  --green: #1e9d68;
  --amber: #b7791f;
  --red: #d73a49;
  --shadow: 0 16px 42px rgba(25, 38, 55, .08);
  --radius: 8px;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

.loginShell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.loginBox {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.loginBox h1 {
  margin: 0;
  color: #13253a;
  font-size: 26px;
}

.loginBox p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.loginLogo {
  max-width: 180px;
  max-height: 72px;
  object-fit: contain;
  justify-self: center;
}

.loginBox label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.loginBox input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--soft);
  color: var(--text);
}

.app {
  min-height: 100vh;
  display: block;
}

.sidebar {
  display: none;
  background: var(--nav);
  color: #dce8f5;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brandMark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2d89ef, #24b47e);
  color: white;
  font-weight: 800;
}

.brandTitle {
  font-size: 15px;
  font-weight: 760;
  line-height: 1.2;
}

.brandSub,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.sidebar .muted,
.brandSub {
  color: #a8bbcf;
}

.nav {
  display: grid;
  gap: 6px;
}

.navItem {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  color: #ccdae8;
  text-align: left;
  cursor: pointer;
}

.navItem.active {
  background: rgba(255, 255, 255, .12);
  color: white;
}

.icon {
  width: 18px;
  display: inline-grid;
  place-items: center;
}

.managerCard {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .08);
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e2eefb;
  color: #15395e;
  font-weight: 800;
}

.avatar.small {
  width: 34px;
  height: 34px;
  font-size: 13px;
  background: #eaf6f0;
  color: #176544;
}

.managerName {
  margin-top: 10px;
  color: #fff;
  font-weight: 760;
}

.main {
  min-width: 0;
  padding: 22px 26px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
  color: #13253a;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.userMenu {
  position: relative;
}

.userChip {
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(25, 38, 55, .04);
  cursor: pointer;
}

.userDropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 5;
  width: 220px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.userDropdown button {
  width: 100%;
  min-height: 34px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--text);
  cursor: pointer;
}

.clientGrid,
.topInfoGrid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  margin-bottom: 18px;
}

.contentGrid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
}

.contentGrid.tableOnly {
  grid-template-columns: minmax(0, 1fr);
}

.summaryInline {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  gap: 8px;
  align-self: start;
}

.summaryInline .metric {
  min-height: 58px;
  padding: 8px 10px;
}

.summaryInline .metric strong {
  font-size: 18px;
}

.clientPanel,
.notifications,
.panel,
.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.clientHead {
  min-height: 60px;
  padding: 12px 16px;
  border-radius: 8px 8px 0 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: linear-gradient(135deg, #126bd8, #0d8fa6);
  color: white;
}

.clientHead span {
  color: #dceeff;
  font-size: 12px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
  padding: 10px 16px 12px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  min-height: 80px;
  padding: 12px;
  display: grid;
  gap: 5px;
  box-shadow: none;
}

.metric strong {
  font-size: 21px;
  color: #13253a;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.danger {
  color: var(--red) !important;
}

.notifications {
  padding: 16px;
}

.notifications h3 {
  margin: 0 0 12px;
}

.notifications p {
  margin: 0;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.panel {
  overflow: hidden;
}

.panelHead {
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}

.panelHead h2,
.calc h2,
.history h2 {
  margin: 0;
  font-size: 18px;
  color: #13253a;
}

.panelHead p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.search,
.tools select,
.field input,
.field select,
.field textarea {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--text);
}

.comboField {
  position: relative;
}

.comboButton {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--soft);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.comboButton:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.comboButton.invalid {
  border-color: #d96a78;
  background: #fff7f8;
}

.comboButton span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comboChevron {
  color: var(--muted);
  flex: 0 0 auto;
}

.comboDropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.comboDropdown input {
  width: 100%;
  min-height: 34px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 9px;
  background: var(--soft);
}

.comboList {
  max-height: 240px;
  overflow-y: auto;
  display: grid;
  gap: 4px;
}

.comboOption {
  border: 0;
  border-radius: 6px;
  padding: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  line-height: 1.3;
  cursor: pointer;
}

.comboOption:hover,
.comboOption.selected {
  background: #eaf3ff;
  color: #0c5cb8;
}

.comboEmpty {
  padding: 12px 8px;
  color: var(--muted);
  font-size: 12px;
}

.search {
  width: 260px;
  padding: 0 12px;
}

.tools select {
  padding: 0 10px;
}

.primary {
  min-height: 38px;
  border: 1px solid var(--blue);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--blue);
  color: white;
  font-weight: 720;
}

.primary:hover {
  background: var(--blue-dark);
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 12px 18px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}

.tabs button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #31445a;
  padding: 0 12px;
  font-weight: 700;
  white-space: nowrap;
}

.tabs button.active {
  border-color: #b8d7ff;
  background: #eaf3ff;
  color: #0c5cb8;
}

.tableWrap {
  overflow-x: visible;
}

table {
  width: 100%;
  min-width: 0;
  table-layout: auto;
  border-collapse: collapse;
}

th,
td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 12px;
}

th {
  background: #fbfcfe;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
}

tbody tr:hover {
  background: #f7fbff;
}

.clickableRow {
  cursor: pointer;
}

.draftRow {
  background: #fbfcfe;
}

.amount {
  white-space: nowrap;
  font-weight: 760;
}

.statusSelect {
  width: 120px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--text);
  font-size: 12px;
}

.statusSelect.wideStatus {
  width: 190px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 6px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.badge.new {
  background: #e8f2ff;
  color: #0d61be;
}

.badge.draft {
  background: #eef2f7;
  color: #536274;
}

.badge.done {
  background: #e6f6ef;
  color: #137b50;
}

.notice {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #f2d096;
  border-radius: 8px;
  background: #fff8ec;
  color: #8a5b13;
}

.notice.success {
  border-color: #b9e5cf;
  background: #e9f8f0;
  color: #176544;
}

.formLayout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: 18px;
  align-items: start;
  max-width: 1320px;
}

.formTopActions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.ghostButton {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--surface);
  color: #31445a;
  font-weight: 720;
}

.formMainPanel {
  min-width: 0;
}

.formGrid {
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 12px;
}

.field {
  grid-column: span 4;
  display: grid;
  gap: 6px;
  align-content: start;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.field.wide {
  grid-column: span 6;
}

.field.full {
  grid-column: span 12;
}

.field input,
.field select {
  width: 100%;
  padding: 0 10px;
  color: var(--text);
}

.field textarea {
  width: 100%;
  min-height: 88px;
  padding: 10px;
  resize: vertical;
  color: var(--text);
}

.field.invalid input,
.field.invalid select,
.field.invalid textarea {
  border-color: #d96a78;
  background: #fff7f8;
}

.error {
  color: var(--red);
  font-size: 11px;
}

.hint {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.marketRow {
  grid-column: span 12;
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 12px;
  align-items: start;
}

.marketRow .field {
  grid-column: auto;
}

.sideStack {
  display: grid;
  gap: 18px;
}

.formActions {
  grid-column: span 12;
  display: flex;
  justify-content: flex-end;
}

.emptyCell {
  text-align: center;
  color: var(--muted);
  padding: 24px;
}

.appFooter {
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.calc,
.history {
  padding: 18px;
}

.calcLine {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.calcLine span,
.history p {
  color: var(--muted);
  font-size: 13px;
}

.calcLine small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.calcLine strong {
  white-space: nowrap;
  color: #13253a;
}

.history {
  display: grid;
  gap: 14px;
}

.historyItem {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.historyItem > span {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e8f2ff;
  color: #0d61be;
  font-size: 12px;
  font-weight: 800;
}

.historyItem strong {
  display: block;
  color: #13253a;
  font-size: 13px;
}

.historyItem p {
  margin: 4px 0 0;
}

@media (max-width: 1180px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .clientGrid,
  .topInfoGrid,
  .formLayout,
  .contentGrid {
    grid-template-columns: 1fr;
  }

  .summary,
  .metrics {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }
}

@media (max-width: 720px) {
  .main {
    padding: 16px;
  }

  .topbar,
  .panelHead {
    flex-direction: column;
  }

  .tools,
  .search,
  .tools select,
  .primary {
    width: 100%;
  }

  .summary,
  .metrics,
  .marketRow {
    grid-template-columns: 1fr;
  }

  .field,
  .field.wide,
  .field.full {
    grid-column: span 12;
  }
}
