@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@700;800&display=swap");

:root {
  color-scheme: light;
  font-family: "DM Sans", ui-sans-serif, system-ui, sans-serif;
  color: #172033;
  background: #f5f7fb;
  font-synthesis: none;
  --primary: #635bff;
  --primary-dark: #4f46e5;
  --primary-soft: #eeedff;
  --green: #087f5b;
  --red: #c43b4d;
  --text-soft: #657089;
  --border: #e2e7f0;
  --surface: rgba(255, 255, 255, .92);
  --shadow: 0 24px 70px rgba(40, 50, 85, .11);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 8% 2%, rgba(99, 91, 255, .16), transparent 28rem),
    radial-gradient(circle at 95% 95%, rgba(30, 187, 154, .12), transparent 25rem),
    #f5f7fb;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  opacity: .38;
  background-image: linear-gradient(rgba(99, 91, 255, .035) 1px, transparent 1px), linear-gradient(90deg, rgba(99, 91, 255, .035) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(to bottom, black, transparent 80%);
}

.container {
  width: min(1100px, calc(100% - 48px));
  margin: 56px auto;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr);
  gap: 28px;
  align-items: start;
}

.card {
  position: relative;
  padding: 38px;
  overflow: hidden;
  border: 1px solid rgba(226, 231, 240, .9);
  border-radius: 26px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.card:first-child::after {
  position: absolute;
  top: -80px;
  right: -80px;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  background: rgba(99, 91, 255, .08);
  content: "";
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--primary);
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .15em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1, h2 { font-family: Manrope, "DM Sans", sans-serif; letter-spacing: -.035em; }
h1 { max-width: 520px; margin-bottom: 10px; font-size: clamp(2rem, 4vw, 3rem); line-height: 1.06; }
h2 { margin-bottom: 0; font-size: 1.3rem; }
.subtitle { margin-bottom: 32px; color: var(--text-soft); font-size: 1rem; line-height: 1.6; }

label {
  display: block;
  margin: 20px 0 9px;
  color: #35405a;
  font-size: .87rem;
  font-weight: 700;
}

input {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 12px 15px;
  border: 1px solid #d9dfeb;
  border-radius: 12px;
  color: #172033;
  background: #fbfcfe;
  font: inherit;
  outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
}

input:hover { border-color: #bdc6d8; background: #fff; }
input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 4px rgba(99, 91, 255, .12); }
input::placeholder { color: #a0a8ba; }

.cost-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.money-input, .percent-input {
  display: flex;
  align-items: center;
  min-height: 48px;
  overflow: hidden;
  border: 1px solid #d9dfeb;
  border-radius: 12px;
  background: #fbfcfe;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.money-input:hover, .percent-input:hover { border-color: #bdc6d8; background: #fff; }
.money-input:focus-within, .percent-input:focus-within { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 4px rgba(99, 91, 255, .12); }
.money-input span, .percent-input span { padding-left: 14px; color: #778198; font-size: .85rem; font-weight: 700; white-space: nowrap; }
.money-input input, .percent-input input { min-height: 46px; border: 0; background: transparent; box-shadow: none; }
.percent-input { width: 200px; }
.percent-input span { order: 2; padding: 0 15px 0 0; }

.summary {
  margin: 32px 0 22px;
  padding: 22px;
  border: 1px solid #dcddff;
  border-radius: 17px;
  background: linear-gradient(135deg, #f4f3ff, #f8fbff);
}
.summary div { display: flex; align-items: center; justify-content: space-between; gap: 18px; color: var(--text-soft); }
.summary strong { color: #35405a; font-size: 1.05rem; }
.summary .final { margin-top: 15px; padding-top: 15px; border-top: 1px solid #dadcff; color: #172033; font-weight: 600; }
.final strong { color: var(--green); font-family: Manrope, sans-serif; font-size: clamp(1.45rem, 3vw, 1.8rem); }

button {
  width: 100%;
  min-height: 48px;
  padding: 12px 18px;
  border: 0;
  border-radius: 12px;
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  box-shadow: 0 9px 20px rgba(99, 91, 255, .22);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform .18s, box-shadow .18s, background .18s;
}
button:hover { transform: translateY(-1px); box-shadow: 0 12px 25px rgba(99, 91, 255, .3); }
button:active { transform: translateY(0); }
button:focus-visible { outline: 3px solid rgba(99, 91, 255, .3); outline-offset: 3px; }
button:disabled { opacity: .6; cursor: wait; transform: none; }

.secondary { width: auto; min-height: 38px; padding: 8px 13px; color: var(--primary); background: var(--primary-soft); box-shadow: none; font-size: .8rem; }
.secondary:hover { background: #dfddff; box-shadow: none; }
.form-actions { display: flex; gap: 11px; }
.form-actions .cancel { color: #5f6b81; background: #edf0f5; box-shadow: none; }
.form-actions .cancel:hover { background: #e2e6ed; box-shadow: none; }
.form-actions [hidden] { display: none; }
.message { min-height: 22px; margin: 13px 0 0; text-align: center; font-size: .88rem; font-weight: 600; }
.message.error { color: var(--red); }
.message.success { color: var(--green); }

.history { padding: 28px; }
.history-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.history-list { display: grid; gap: 12px; }
.history-item {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(40, 50, 85, .045);
  transition: transform .2s, border-color .2s, box-shadow .2s;
}
.history-item:hover { transform: translateY(-2px); border-color: #cac7ff; box-shadow: 0 10px 25px rgba(40, 50, 85, .08); }
.history-item div { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.history-item strong { overflow-wrap: anywhere; }
.history-item div > strong:last-child { flex-shrink: 0; color: var(--green); }
.history-item small { display: block; margin-top: 7px; color: #7d879b; }
.item-actions { margin-top: 14px; justify-content: flex-end !important; }
.item-actions button { width: auto; min-height: 34px; padding: 7px 12px; box-shadow: none; font-size: .78rem; }
.item-actions .edit { color: var(--primary); background: var(--primary-soft); }
.item-actions .delete { color: var(--red); background: #fff0f2; }
.item-actions .edit:hover { background: #dfddff; box-shadow: none; }
.item-actions .delete:hover { background: #ffe0e5; box-shadow: none; }
.empty { margin: 0; padding: 26px 12px; color: #8791a5; text-align: center; }

@media (max-width: 860px) {
  .container { width: min(680px, calc(100% - 36px)); margin: 34px auto; grid-template-columns: 1fr; }
  .history { max-height: none; }
}

@media (max-width: 560px) {
  body { background: linear-gradient(160deg, #f1f0ff 0, #f7f9fc 38%, #f2fbf8 100%); }
  body::before { display: none; }
  .container { width: 100%; margin: 0; padding: 14px; gap: 14px; }
  .card { padding: 24px 18px; border-radius: 20px; box-shadow: 0 12px 35px rgba(40, 50, 85, .09); }
  .history { padding: 21px 18px; }
  h1 { font-size: 2rem; }
  h2 { font-size: 1.2rem; }
  .subtitle { margin-bottom: 24px; font-size: .94rem; }
  label { margin-top: 17px; }
  .cost-grid { grid-template-columns: 1fr; gap: 0; }
  .percent-input { width: 100%; }
  .summary { margin-top: 25px; padding: 18px; }
  .summary div { align-items: flex-start; flex-direction: column; gap: 4px; }
  .summary .final { align-items: flex-start; }
  .form-actions { flex-direction: column; }
  button { min-height: 50px; }
  .history-header .secondary { min-height: 38px; }
  .history-item { padding: 15px; }
  .history-item > div:first-child { flex-direction: column; gap: 5px; }
  .item-actions { flex-direction: row !important; }
  .item-actions button { flex: 1; min-height: 40px; }
}

@media (max-width: 360px) {
  .container { padding: 8px; }
  .card { padding: 21px 15px; border-radius: 17px; }
  .history-header { align-items: flex-start; flex-direction: column; }
  .history-header .secondary { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
