:root {
  color-scheme: light;
  --bg: var(--tg-theme-bg-color, #f4f6f8);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --surface-soft: #eef3f2;
  --text: var(--tg-theme-text-color, #17211f);
  --muted: var(--tg-theme-hint-color, #657370);
  --border: #dce5e2;
  --accent: var(--tg-theme-button-color, #16866f);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --warning: #b06a00;
  --danger: #bc3f3f;
  --shadow: 0 10px 28px rgba(17, 24, 39, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  flex: 0 0 auto;
}

.app-shell {
  min-height: 100vh;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 auto 14px;
  max-width: 1280px;
}

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

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
  margin-bottom: 0;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
  margin-bottom: 0;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  display: inline-flex;
  gap: 8px;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
  white-space: nowrap;
}

.primary-button {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

.secondary-button {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.danger-button {
  background: #fff7f6;
  border-color: #f0c6c2;
  color: var(--danger);
  font-weight: 700;
}

.icon-button {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  min-width: 40px;
  padding: 0;
}

.primary-button:focus-visible,
.secondary-button:focus-visible,
.danger-button:focus-visible,
.icon-button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  box-shadow: 0 0 0 3px rgba(22, 134, 111, 0.18);
  outline: none;
}

.primary-button:active,
.secondary-button:active,
.danger-button:active,
.icon-button:active {
  transform: translateY(1px);
}

.summary {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0 auto 12px;
  max-width: 1280px;
}

.summary > div {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 0;
  padding: 12px;
}

.summary span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 4px;
}

.summary strong {
  display: block;
  font-size: 20px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  margin: 0 auto 14px;
  max-width: 1280px;
}

.search {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
}

.search svg {
  color: var(--muted);
}

.search input {
  background: transparent;
  border: 0;
  color: var(--text);
  min-width: 0;
  outline: 0;
  width: 100%;
}

.board {
  align-items: stretch;
  display: grid;
  gap: 12px;
  grid-auto-columns: minmax(280px, 310px);
  grid-auto-flow: column;
  margin: 0 auto;
  max-width: 1280px;
  min-height: 58vh;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x proximity;
}

.column {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  min-height: 420px;
  min-width: 0;
  scroll-snap-align: start;
}

.column.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 134, 111, 0.14);
}

.column-header {
  border-bottom: 1px solid var(--border);
  padding: 12px;
}

.column-title-row {
  align-items: start;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.column h3 {
  font-size: 14px;
  line-height: 1.25;
  margin: 0;
}

.count-pill {
  background: var(--surface-soft);
  border-radius: 999px;
  color: var(--muted);
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  min-width: 28px;
  padding: 3px 8px;
  text-align: center;
}

.column-total {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

.deal-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  padding: 14px;
  text-align: center;
}

.deal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 3px 10px rgba(17, 24, 39, 0.04);
  color: inherit;
  display: grid;
  gap: 10px;
  grid-template-columns: 44px minmax(0, 1fr);
  padding: 10px;
  text-align: left;
  width: 100%;
}

.deal-card:hover {
  border-color: rgba(22, 134, 111, 0.42);
}

.deal-card.dragging {
  opacity: 0.54;
}

.avatar,
.preview {
  align-items: center;
  background: #dbe9e5;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #1b5d50;
  display: flex;
  font-weight: 800;
  justify-content: center;
  overflow: hidden;
  text-transform: uppercase;
}

.avatar {
  height: 44px;
  width: 44px;
}

.avatar img,
.preview img {
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.deal-main {
  min-width: 0;
}

.deal-name {
  display: block;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deal-meta {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 12px;
  gap: 4px 8px;
  margin-top: 4px;
}

.money-row {
  display: grid;
  gap: 6px;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.money-row span {
  background: #f7faf9;
  border-radius: 8px;
  color: var(--muted);
  font-size: 11px;
  min-width: 0;
  padding: 7px 8px;
}

.money-row strong {
  color: var(--text);
  display: block;
  font-size: 13px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-preview {
  color: var(--muted);
  display: -webkit-box;
  font-size: 12px;
  grid-column: 1 / -1;
  line-height: 1.35;
  margin: 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.deal-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--text);
  max-width: 720px;
  padding: 0;
  width: min(720px, calc(100vw - 24px));
}

.deal-dialog::backdrop {
  background: rgba(16, 24, 22, 0.42);
}

.deal-dialog form {
  padding: 18px;
}

.dialog-header,
.dialog-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.dialog-header {
  justify-content: space-between;
  margin-bottom: 16px;
}

.image-field {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 76px minmax(0, 1fr);
  margin-bottom: 14px;
}

.preview {
  height: 76px;
  width: 76px;
}

.image-field label,
.form-grid label {
  color: var(--text);
  display: grid;
  gap: 6px;
}

.image-field span,
.form-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.wide {
  grid-column: 1 / -1;
}

input,
select,
textarea {
  background: #fbfdfc;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  min-height: 40px;
  padding: 9px 10px;
  width: 100%;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

.dialog-actions {
  border-top: 1px solid var(--border);
  margin-top: 16px;
  padding-top: 14px;
}

.action-spacer {
  flex: 1;
}

.toast {
  background: #162522;
  border-radius: 8px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  color: #ffffff;
  left: 50%;
  max-width: min(420px, calc(100vw - 24px));
  opacity: 0;
  padding: 10px 14px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 16px);
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 10;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 760px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar {
    align-items: flex-start;
  }

  h1 {
    font-size: 24px;
  }

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

  .summary strong {
    font-size: 18px;
  }

  .board {
    grid-auto-columns: minmax(270px, 86vw);
  }

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

  .dialog-actions {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .dialog-actions .primary-button,
  .dialog-actions .secondary-button,
  .dialog-actions .danger-button {
    flex: 1 1 auto;
  }

  .action-spacer {
    display: none;
  }
}
