:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --line: #dce3e8;
  --line-strong: #c6d1d8;
  --text: #17212b;
  --muted: #697986;
  --accent: #176b5b;
  --accent-strong: #0f5146;
  --accent-soft: #e7f3ef;
  --blue: #215f9a;
  --blue-soft: #e8f1fa;
  --danger: #b42318;
  --danger-soft: #fde8e5;
  --shadow: 0 16px 48px rgba(22, 34, 44, 0.08);
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background:
    linear-gradient(180deg, #ffffff 0, var(--bg) 260px),
    var(--bg);
  color: var(--text);
}

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

button, .button {
  border: 1px solid transparent;
  border-radius: 7px;
  min-height: 38px;
  padding: 9px 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

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

.primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.secondary {
  background: var(--surface);
  color: var(--accent-strong);
  border-color: var(--line-strong);
}

.secondary:hover, .quiet:hover {
  background: var(--accent-soft);
  border-color: #b9d8cf;
}

.quiet {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #f5beb8;
}

.danger:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.compact {
  min-height: 32px;
  padding: 6px 10px;
}

.full { width: 100%; }

.shell { min-height: 100vh; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(390px, 100%);
  display: grid;
  gap: 16px;
  padding: 30px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark.small {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
}

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

h1 {
  margin-bottom: 4px;
  font-size: 25px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 21px;
  line-height: 1.2;
  letter-spacing: 0;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

input, select, textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 11px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 91, 0.13);
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
}

.title-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
}

.title-block p {
  margin-bottom: 0;
  font-size: 13px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
  max-width: 1500px;
  margin: 0 auto;
}

.sidebar, .editor-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 26px rgba(22, 34, 44, 0.05);
}

.sidebar {
  align-self: start;
  overflow: hidden;
}

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.list-head strong {
  display: block;
  font-size: 16px;
}

.list-head span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.list-filter {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.coupon-list {
  max-height: calc(100vh - 190px);
  overflow: auto;
}

.coupon-item {
  width: 100%;
  display: grid;
  gap: 8px;
  text-align: left;
  border: 0;
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 0;
  padding: 13px 14px 13px 11px;
}

.coupon-item:hover {
  background: var(--surface-soft);
}

.coupon-item.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.coupon-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.coupon-main strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.coupon-meta {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--blue);
  background: var(--blue-soft);
}

.badge.off {
  color: var(--muted);
  background: #eef1f3;
}

.editor-panel {
  padding: 18px;
}

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

.form-head p {
  margin-bottom: 0;
  font-size: 13px;
}

.switch {
  display: inline-flex;
  align-items: center;
  grid-template-columns: auto auto;
  gap: 8px;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  white-space: nowrap;
}

.switch input {
  width: 16px;
  height: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.field-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1.4fr) 150px 130px 160px;
  gap: 12px;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-top: 12px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 15px 0 12px;
  flex-wrap: wrap;
}

.spacer { flex: 1; }

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
}

.pill.ok {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.pill.muted {
  color: var(--muted);
  background: #eef1f3;
}

.offers-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}

.offers-head, .offer-row {
  display: grid;
  grid-template-columns: 44px minmax(260px, 1fr) minmax(100px, 140px) minmax(130px, 190px);
  gap: 10px;
  align-items: center;
}

.offers-head {
  min-height: 38px;
  padding: 0 12px;
  color: var(--muted);
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
}

.offers {
  min-height: 230px;
  max-height: 440px;
  overflow: auto;
}

.offer-row {
  min-height: 62px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.offer-row:last-child { border-bottom: 0; }

.offer-row input {
  width: 17px;
  height: 17px;
  min-height: 17px;
  accent-color: var(--accent);
}

.offer-row small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.offer-name {
  min-width: 0;
}

.offer-name strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

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

.manual {
  margin-top: 14px;
  color: var(--muted);
}

.manual summary {
  cursor: pointer;
  font-weight: 700;
}

.manual textarea {
  margin-top: 10px;
}

.save-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

.message {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.message.error {
  color: var(--danger);
}

@media (max-width: 980px) {
  .topbar {
    display: block;
  }

  .actions {
    justify-content: flex-start;
    margin-top: 14px;
  }

  .layout {
    display: block;
  }

  .sidebar {
    margin-bottom: 16px;
  }

  .coupon-list {
    max-height: 270px;
  }

  .field-grid, .search-row {
    grid-template-columns: 1fr;
  }

  .offers-head {
    display: none;
  }

  .offer-row {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .offer-row small {
    grid-column: 2;
  }
}

@media (max-width: 560px) {
  .topbar, .layout {
    padding-left: 12px;
    padding-right: 12px;
  }

  .title-block {
    min-width: 0;
  }

  .actions > * {
    width: 100%;
  }

  .form-head {
    display: grid;
  }

  .save-row > button {
    width: 100%;
  }
}
