:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #172033;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --green: #047857;
  --red: #dc2626;
  --yellow: #a16207;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #dbeafe, transparent 32rem), var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  background: rgba(255,255,255,0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  font-weight: 800;
  box-shadow: var(--shadow);
}
.brand small { display: block; color: var(--muted); font-size: .75rem; }
nav { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
nav a {
  color: var(--text);
  padding: .55rem .8rem;
  border-radius: 999px;
}
nav a.primary {
  background: var(--primary);
  color: white;
}

.container {
  width: min(1180px, calc(100% - 2rem));
  margin: 2rem auto 4rem;
}
.hero, .page-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1.5rem;
  margin-bottom: 1.3rem;
}
.hero {
  padding: 2rem;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 28px;
  background: linear-gradient(135deg, rgba(255,255,255,.92), rgba(239,246,255,.92));
  box-shadow: var(--shadow);
}
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 5vw, 3.3rem); margin-bottom: .45rem; letter-spacing: -.04em; }
h2 { font-size: 1.15rem; margin-bottom: .25rem; }
p { color: var(--muted); line-height: 1.7; }
.eyebrow { color: var(--primary); font-weight: 700; margin-bottom: .25rem; }
.hero-actions, .form-actions { display: flex; gap: .75rem; flex-wrap: wrap; }
.button, button {
  border: 0;
  border-radius: 14px;
  background: var(--primary);
  color: white;
  padding: .75rem 1rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: .4rem;
}
.button:hover, button:hover { background: var(--primary-strong); text-decoration: none; }
.button.secondary, .filters .secondary {
  background: #e2e8f0;
  color: var(--text);
}
.button.secondary:hover, .filters .secondary:hover { background: #cbd5e1; }

.cards { display: grid; gap: 1rem; margin-bottom: 1rem; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.card, .panel {
  background: rgba(255,255,255,.94);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.card { padding: 1.25rem; }
.metric span { color: var(--muted); font-size: .9rem; }
.metric strong { display: block; font-size: 1.8rem; margin: .35rem 0; letter-spacing: -.035em; }
.metric small { color: var(--muted); }
.panel { padding: 1.25rem; margin-bottom: 1rem; }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
.compact table { min-width: 520px; }
th, td { padding: .85rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: .82rem; font-weight: 700; background: var(--panel-2); }
td small { color: var(--muted); }
.right { text-align: right; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.badge {
  display: inline-flex;
  align-items: center;
  padding: .28rem .55rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-yellow { background: #fef3c7; color: var(--yellow); }
.badge-green { background: #dcfce7; color: var(--green); }
.badge-gray { background: #e2e8f0; color: #475569; }
.empty { text-align: center; padding: 2rem 1rem; }

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px 110px 110px auto auto;
  gap: .75rem;
  align-items: center;
  margin-bottom: 1rem;
  background: rgba(255,255,255,.9);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: .8rem;
  box-shadow: var(--shadow);
}
input, select, textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  padding: .72rem .8rem;
  font: inherit;
  background: white;
  color: var(--text);
}
textarea { resize: vertical; }
label { display: grid; gap: .35rem; font-weight: 700; color: #334155; }
.form-grid { display: grid; gap: 1rem; }
.form-section h2 { margin-bottom: 1rem; }
.alert {
  border: 1px solid #fecaca;
  background: #fff1f2;
  color: #be123c;
  border-radius: 18px;
  padding: 1rem;
  margin-bottom: 1rem;
  font-weight: 700;
}
.inline-calc { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
.profit-preview {
  margin-top: 1rem;
  padding: .9rem;
  border-radius: 16px;
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 800;
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.detail-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: .7rem 1rem;
}
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; font-weight: 700; }
.memo { white-space: pre-wrap; color: var(--text); }
.danger-zone { margin-top: 1.2rem; display: flex; justify-content: flex-end; }
.danger-zone button { background: #fee2e2; color: #991b1b; }
.danger-zone button:hover { background: #fecaca; }

@media (max-width: 900px) {
  .topbar, .hero, .page-title { align-items: flex-start; flex-direction: column; }
  .grid-4, .grid-2, .detail-grid { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .container { width: min(100% - 1rem, 1180px); margin-top: 1rem; }
  .hero, .panel, .card { border-radius: 18px; padding: 1rem; }
  .filters { grid-template-columns: 1fr; }
  nav a { padding: .45rem .65rem; }
}
