:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e6e8ec;
  --text: #16181d;
  --muted: #8a9099;
  --accent: #2f6df6;
  --accent-soft: #eef3fe;
  --weekend: #fbfbfc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать display из правил ниже. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.01em;
}

.controls { display: flex; gap: 10px; }

input[type="month"] {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  color: inherit;
}

input[type="month"]:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}

button.primary:hover { background: #2559d8; }
button.primary:disabled { opacity: .6; cursor: default; }

button.ghost {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  padding: 4px 8px;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px;
  display: grid;
  gap: 20px;
}

.summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 26px;
  box-shadow: var(--shadow);
}

.summary-label {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.summary-value {
  font-size: 38px;
  font-weight: 650;
  letter-spacing: -.02em;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.summary-meta { margin-top: 6px; font-size: 13px; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.status {
  padding: 12px 20px;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.status:empty { display: none; }
.status.error { color: #b42318; background: #fef3f2; }

.table-wrap { overflow: auto; max-height: calc(100vh - 300px); }

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

th, td {
  padding: 9px 14px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

th.day-col, td.day-col {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  text-align: left;
  font-weight: 500;
  min-width: 92px;
}

thead th.day-col { z-index: 4; }

tbody tr:hover td { background: var(--accent-soft); }
tbody tr.weekend td.day-col,
tbody tr.weekend td { background: var(--weekend); }
tbody tr.weekend:hover td { background: var(--accent-soft); }

td .wd { color: var(--muted); font-weight: 400; margin-left: 6px; font-size: 13px; }

td.zero { color: #cfd3d9; }

td.value { cursor: pointer; }
td.value:hover { text-decoration: underline; text-decoration-color: var(--accent); }

td.row-total, th.row-total { font-weight: 600; background: #fafbfc; }

tfoot td {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  font-weight: 650;
  border-top: 1px solid var(--border);
  border-bottom: none;
  z-index: 3;
}

tfoot td.day-col { z-index: 4; }

.diagnostics { padding: 18px 22px; font-size: 13px; color: var(--muted); }
.diagnostics b { color: var(--text); font-weight: 600; }
.diagnostics ul { margin: 8px 0 0; padding-left: 18px; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  max-width: 92vw;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 32px rgba(16, 24, 40, .1);
  z-index: 40;
  display: flex;
  flex-direction: column;
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.drawer-title { font-weight: 600; }
.drawer-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.drawer-body { overflow: auto; padding: 8px 20px 24px; }

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

.deal:last-child { border-bottom: none; }
.deal-title { font-size: 14px; }
.deal-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.deal-amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.deal a { color: var(--accent); text-decoration: none; }
.deal a:hover { text-decoration: underline; }

@media (max-width: 720px) {
  main { padding: 16px; }
  .topbar { flex-direction: column; align-items: stretch; }
  .summary-value { font-size: 30px; }
}
