:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --ink: #1c2328;
  --muted: #687076;
  --line: #dfe4df;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --green: #0f8a68;
  --red: #d53f3f;
  --amber: #b7791f;
  --blue: #2b6cb0;
  --shadow: 0 14px 34px rgba(29, 38, 44, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar,
.controls,
.summary,
.panel {
  width: 100%;
}

[hidden] {
  display: none !important;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.05;
}

.status {
  min-width: 190px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.view-tabs {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: 14px;
}

.tab-button {
  min-height: 38px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.tab-button.active {
  background: var(--green);
  color: #fff;
}

.controls {
  display: grid;
  grid-template-columns: 140px 150px 160px 1fr 44px;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

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

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
input,
button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

select,
input {
  width: 100%;
  padding: 0 12px;
}

.icon-button {
  display: grid;
  place-items: center;
  color: var(--green);
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--green);
}

.primary-button,
.ghost-button {
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 800;
}

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

.ghost-button {
  background: var(--surface);
  color: var(--muted);
}

.ghost-button:hover {
  border-color: var(--red);
  color: var(--red);
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary article {
  display: grid;
  gap: 2px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 13px;
}

.metric {
  color: var(--green);
  font-size: 28px;
  font-weight: 850;
  line-height: 1;
}

.metric.red {
  color: var(--red);
}

.metric.amber {
  color: var(--amber);
}

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  font-size: 18px;
}

.panel-header p,
.notes {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 940px;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: #495057;
  font-size: 12px;
  font-weight: 800;
}

td {
  font-size: 14px;
}

tbody tr:hover {
  background: #f8faf8;
}

.date-cell {
  min-width: 120px;
  color: var(--muted);
  font-weight: 700;
}

.time-cell {
  min-width: 92px;
  font-size: 18px;
  font-weight: 850;
}

.country {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  font-weight: 800;
}

.badge {
  display: inline-flex;
  min-width: 54px;
  justify-content: center;
  padding: 5px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  font-weight: 850;
}

.badge.high {
  background: var(--red);
}

.badge.medium {
  background: var(--amber);
}

.badge.low {
  background: var(--blue);
}

.source {
  color: var(--muted);
  font-weight: 650;
}

.previous {
  min-width: 90px;
  color: var(--green);
  font-weight: 850;
  white-space: nowrap;
}

.content strong {
  display: block;
  margin-bottom: 3px;
}

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

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

.notes {
  margin-top: 12px;
  padding: 0 4px;
}

.pnl-toolbar {
  display: grid;
  grid-template-columns: minmax(280px, 1.4fr) minmax(180px, 0.8fr) 220px;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

#pnlView {
  display: flex;
  flex-direction: column;
}

#pnlView[hidden] {
  display: none !important;
}

.pnl-toolbar {
  order: 1;
}

.pnl-layout {
  order: 2;
}

.pnl-summary {
  order: 3;
  margin-top: 14px;
}

.add-user {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.month-switcher {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  gap: 8px;
  align-items: end;
}

.month-switcher strong {
  display: grid;
  min-height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 16px;
}

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

.pnl-weekdays,
.pnl-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.pnl-weekdays {
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.pnl-weekdays span {
  padding: 10px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-align: center;
}

.pnl-calendar {
  min-height: 0;
}

.pnl-calendar .empty {
  grid-column: 1 / -1;
}

.pnl-day {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 4px;
  min-height: 72px;
  padding: 8px;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

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

.pnl-day:hover,
.pnl-day.selected {
  outline: 2px solid var(--green);
  outline-offset: -2px;
}

.pnl-day.outside {
  background: #f9faf8;
  color: #9aa1a6;
}

.pnl-day-number {
  font-size: 12px;
  font-weight: 850;
}

.pnl-day-amount {
  align-self: center;
  font-size: 14px;
  font-weight: 900;
  word-break: break-word;
}

.pnl-day-amount.profit,
.profit {
  color: var(--green);
}

.pnl-day-amount.loss,
.loss {
  color: var(--red);
}

.pnl-day-memo {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pnl-editor {
  position: sticky;
  top: 14px;
}

.entry-form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.calculator-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 14px;
  align-items: start;
}

.calculator-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
}

.calculator-result {
  position: sticky;
  top: 14px;
}

.result-grid {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.result-grid article {
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.result-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.result-grid strong {
  color: var(--ink);
  font-size: 20px;
  line-height: 1.1;
  word-break: break-word;
}

.result-grid .result-main {
  border-color: rgba(15, 138, 104, 0.35);
  background: #eff8f4;
}

.result-grid .result-main strong {
  color: var(--green);
  font-size: 30px;
}

.calculator-note {
  padding: 0 16px 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

@media (max-width: 760px) {
  .app {
    width: min(100% - 18px, 1180px);
    padding-top: 18px;
  }

  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .status {
    text-align: left;
  }

  .controls {
    grid-template-columns: 1fr 1fr;
  }

  .search-field {
    grid-column: 1 / -1;
  }

  .icon-button {
    width: 100%;
  }

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

  .view-tabs {
    width: 100%;
  }

  .pnl-toolbar,
  .add-user,
  .pnl-layout,
  .calculator-layout,
  .calculator-form {
    grid-template-columns: 1fr;
  }

  .pnl-weekdays span {
    padding: 8px 2px;
  }

  .pnl-day {
    min-height: 50px;
    padding: 6px 4px;
  }

  .pnl-day-amount {
    font-size: 11px;
  }

  .pnl-day-memo {
    display: none;
  }

  .pnl-editor,
  .calculator-result {
    position: static;
  }
}
