:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --panel-strong: #fdfdfd;
  --line: #d9dee4;
  --line-soft: #e8ebef;
  --text: #111827;
  --muted: #667085;
  --muted-strong: #475467;
  --green: #087443;
  --green-bg: #e7f6ee;
  --red: #b42318;
  --red-bg: #fae9e7;
  --blue: #1f98ad;
  --blue-bg: rgba(31, 152, 173, 0.12);
  --amber: #a15c07;
  --amber-bg: #fff4df;
  --drawer-table-min: 860px;
  --drawer-table-padding-x: 40px;
  --drawer-row-height: 64px;
  --drawer-col-account: 16%;
  --drawer-col-contragent: 18%;
  --drawer-col-category: 25%;
  --drawer-col-project: 13%;
  --drawer-col-deal: 13%;
  --drawer-col-amount: 15%;
  --shadow: 0 14px 36px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", Arial, sans-serif;
  font-size: 13px;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 262px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 20px 15px 22px;
}

.brand-row {
  display: grid;
  gap: 10px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line-soft);
}

.product-name {
  font-size: 17px;
  font-weight: 750;
  line-height: 1.2;
}

.api-key-button {
  justify-self: start;
  height: 28px;
  border: 1px solid rgba(31, 152, 173, 0.32);
  border-radius: 8px;
  background: var(--blue-bg);
  color: var(--blue);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 650;
}

.api-key-button.has-key {
  border-color: var(--blue);
  background: rgba(31, 152, 173, 0.18);
}

.filter-section {
  padding: 22px 0 0;
}

.section-title {
  margin-bottom: 10px;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
}

.filter-list {
  display: grid;
  gap: 2px;
}

.sidebar-message {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
}

.check-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 28px;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
}

.check-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--blue);
}

.check-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lookup {
  position: relative;
}

.lookup-input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 400;
  outline: 0;
}

.lookup-input:focus {
  border-color: rgba(31, 152, 173, 0.48);
  box-shadow: 0 0 0 3px rgba(31, 152, 173, 0.14);
}

.lookup-menu {
  position: absolute;
  z-index: 20;
  display: none;
  width: 100%;
  max-height: 264px;
  overflow: auto;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 6px;
}

.lookup.open .lookup-menu {
  display: grid;
  gap: 4px;
}

.lookup-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  padding: 7px 8px;
  text-align: left;
}

.lookup-option span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 400;
}

.lookup-option small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.lookup-option:hover,
.lookup-option.selected {
  border-color: rgba(31, 152, 173, 0.32);
  background: var(--blue-bg);
}

.lookup-message {
  padding: 10px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.lookup-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.filter-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 24px;
  border: 1px solid rgba(31, 152, 173, 0.32);
  border-radius: 999px;
  background: var(--blue-bg);
  color: var(--blue);
  padding: 0 9px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 400;
}

.filter-chip-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-chip-close {
  position: absolute;
  top: 50%;
  right: 1px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  background: #d9f1f5;
  box-shadow: -10px 0 10px #d9f1f5;
  color: var(--blue);
  cursor: pointer;
  font-size: 0;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%);
}

.filter-chip-close::before {
  content: "×";
  font-size: 18px;
  line-height: 1;
}

.filter-chip:hover .filter-chip-close,
.filter-chip:focus-within .filter-chip-close {
  opacity: 1;
  pointer-events: auto;
}

.period-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}

.period-year {
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
}

.period-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
}

.icon-button:hover,
.text-button:hover,
.month-button:hover {
  border-color: #b9c2cf;
  background: #f7f8fa;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.month-button {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 400;
}

.month-button.active {
  border-color: var(--blue);
  background: var(--blue-bg);
  color: var(--blue);
}

.calendar-area {
  min-width: 0;
  padding: 20px 24px 32px;
}

.calendar-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: -20px -24px 0;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 248, 0.94);
  backdrop-filter: blur(12px);
}

.toolbar-left,
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 750;
  line-height: 1.2;
}

.toolbar-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.text-button {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  font-size: 12px;
  font-weight: 650;
}

.text-button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.text-button.danger {
  color: var(--red);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.data-state {
  min-height: 22px;
  margin: -6px 0 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.data-state.error {
  color: var(--red);
}

.summary-item {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px 14px;
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.summary-item strong {
  display: block;
  margin-top: 8px;
  font-size: 20px;
  line-height: 1.1;
  font-weight: 750;
}

#periodIncome {
  color: var(--green);
}

#periodOutcome {
  color: var(--red);
}

#periodNet {
  color: var(--green);
}

.calendar-grid-wrap {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.weekday-row,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(112px, 1fr));
}

.weekday-row {
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.weekday-row span {
  min-height: 36px;
  border-right: 1px solid var(--line-soft);
  color: var(--muted);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.weekday-row span:last-child {
  border-right: 0;
}

.day-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 194px;
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  background: #fff;
  padding: 10px 12px;
}

.day-cell:nth-child(7n) {
  border-right: 0;
}

.day-cell.muted {
  background: #fafafa;
  color: #98a2b3;
}

.day-cell.muted .day-operation-count,
.day-cell.muted .operation-title,
.day-cell.muted .operation-amount,
.day-cell.muted .more-line,
.day-cell.muted .day-total .in,
.day-cell.muted .day-total .out {
  color: #98a2b3;
}

.day-cell:hover {
  background: rgba(31, 152, 173, 0.045);
}

.day-cell.today {
  box-shadow: inset 0 0 0 2px var(--blue);
}

.day-top {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  align-items: center;
  column-gap: 6px;
  min-height: 24px;
}

.date-number {
  display: inline-grid;
  place-items: center;
  min-width: 0;
  max-width: 100%;
  height: 24px;
  padding: 0;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 650;
  line-height: 24px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.today .date-number {
  padding: 0 7px;
  background: #111827;
  color: #fff;
}

.day-operation-count {
  justify-self: end;
  min-width: 0;
  max-width: 100%;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  line-height: 24px;
  text-align: right;
  text-decoration: none;
}

.day-operation-count:not(.disabled):hover {
  color: var(--blue);
  text-decoration: none;
}

.day-operation-count.disabled {
  cursor: default;
  color: #98a2b3;
}

.day-total {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  column-gap: 6px;
  min-height: 26px;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
}

.day-total.both {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.day-total .in {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--green);
}

.day-total.income-only .out,
.day-total.outcome-only .in {
  display: none;
}

.day-total .out {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
  color: var(--red);
}

.operations-list {
  display: grid;
  align-content: start;
  gap: 4px;
  margin-top: 8px;
  padding-bottom: 8px;
}

.operation {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: baseline;
  column-gap: 6px;
  min-height: 22px;
  padding: 1px 0;
  font-size: 12px;
  line-height: 1.35;
}

.operation-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 400;
}

.operation.planned .operation-title {
  color: #175cd3;
}

.operation-amount {
  justify-self: end;
  white-space: nowrap;
  font-weight: 400;
}

.operation.income .operation-amount {
  color: var(--green);
}

.operation.outcome .operation-amount {
  color: var(--red);
}

.operation.planned.income .operation-amount {
  color: var(--green);
}

.operation.planned.outcome .operation-amount {
  color: var(--red);
}

.more-line {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  padding-left: 2px;
}

.empty-state {
  color: #98a2b3;
  font-size: 12px;
  font-weight: 400;
  min-height: 22px;
  padding: 1px 0;
  line-height: 1.35;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(17, 24, 39, 0.18);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.drawer-backdrop.open {
  opacity: 1;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(17, 24, 39, 0.2);
}

.api-key-modal {
  position: fixed;
  top: 72px;
  left: 16px;
  z-index: 41;
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 48px rgba(16, 24, 40, 0.18);
  padding: 16px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.current-key {
  margin-bottom: 12px;
  border: 1px solid rgba(31, 152, 173, 0.24);
  border-radius: 8px;
  background: rgba(31, 152, 173, 0.08);
  color: var(--muted-strong);
  padding: 9px 10px;
  font-size: 12px;
  font-weight: 500;
}

.api-key-field {
  display: grid;
  gap: 6px;
}

.api-key-field span {
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 650;
}

.api-key-field input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  padding: 0 10px;
  font-size: 13px;
}

.api-key-field input:focus {
  border-color: rgba(31, 152, 173, 0.48);
  box-shadow: 0 0 0 3px rgba(31, 152, 173, 0.14);
}

.api-key-message {
  margin-top: 10px;
  color: var(--red);
  font-size: 12px;
  line-height: 1.35;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions .danger {
  margin-right: auto;
}

.day-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 31;
  display: flex;
  flex-direction: column;
  width: min(100vw, max(64vw, calc(var(--drawer-table-min) + var(--drawer-table-padding-x))));
  min-width: min(100vw, calc(var(--drawer-table-min) + var(--drawer-table-padding-x)));
  height: 100vh;
  border-left: 1px solid var(--line);
  background: #fff;
  box-shadow: -18px 0 42px rgba(16, 24, 40, 0.16);
  transform: translateX(100%);
  transition: transform 0.18s ease;
}

.day-drawer.open {
  transform: translateX(0);
}

.drawer-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 32px;
  align-items: center;
  gap: 14px;
  padding: 20px;
}

.drawer-kicker {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.drawer-head h2 {
  margin: 5px 0 0;
  font-size: 24px;
  line-height: 1.2;
}

.drawer-totals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  min-width: 280px;
}

.drawer-totals div {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
}

.drawer-totals span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.drawer-totals strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
  line-height: 1.2;
}

#drawerIncome {
  color: var(--green);
}

#drawerOutcome {
  color: var(--red);
}

.drawer-table-wrap {
  min-height: 0;
  overflow: auto;
  padding: 10px 20px 20px;
}

.operations-table {
  width: 100%;
  min-width: var(--drawer-table-min);
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}

.operations-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  padding: 13px 10px;
  text-align: left;
  font-weight: 700;
}

.operations-table th:first-child,
.operations-table td:first-child {
  padding-left: 0;
}

.operations-table tbody tr {
  height: var(--drawer-row-height);
}

.operations-table td {
  max-width: 260px;
  height: var(--drawer-row-height);
  border-bottom: 1px solid var(--line-soft);
  padding: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  vertical-align: middle;
}

.table-account-head,
.table-account {
  width: var(--drawer-col-account);
}

.table-contragent-head,
.table-contragent {
  width: var(--drawer-col-contragent);
}

.table-category-head,
.table-category {
  width: var(--drawer-col-category);
}

.table-project-head,
.table-project {
  width: var(--drawer-col-project);
}

.table-deal-head,
.table-deal {
  width: var(--drawer-col-deal);
}

.table-amount-head,
.table-amount {
  width: var(--drawer-col-amount);
}

.table-category-title,
.table-comment {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.35;
}

.table-comment {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.operations-table tr.planned td:not(.table-amount),
.operations-table tr.planned .table-comment {
  color: #175cd3;
}

.operations-table tr.income .table-amount {
  color: var(--green);
}

.operations-table tr.outcome .table-amount {
  color: var(--red);
}

.table-amount {
  text-align: right;
  white-space: nowrap;
}

.operations-table th.table-amount-head {
  text-align: right;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 236px minmax(0, 1fr);
  }

  .calendar-area {
    padding-inline: 18px;
  }

  .calendar-toolbar {
    margin-inline: -18px;
    padding-inline: 18px;
  }

  .weekday-row,
  .calendar-grid {
    grid-template-columns: repeat(7, minmax(104px, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .calendar-toolbar {
    top: 0;
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-left,
  .toolbar-actions {
    justify-content: space-between;
  }

  .summary-strip {
    grid-template-columns: 1fr;
  }

  .calendar-grid-wrap {
    overflow-x: auto;
  }

  .weekday-row,
  .calendar-grid {
    min-width: 784px;
  }

  .day-drawer {
    width: 100vw;
    min-width: 0;
  }
}
