:root {
  --bg: #f7f3ef;
  --ink: #1d1b16;
  --accent: #b64b2e;
  --muted: #6b655c;
  --card: #ffffff;
  --border: #e6ddd3;
  --header-bg: #fff7f0;
  --stat-bg: #fffdfb;
  --table-head-bg: #fff7f0;
  --shadow: rgba(0,0,0,0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --ink: #f1ece6;
    --accent: #e07052;
    --muted: #b4aca2;
    --card: #1d1916;
    --border: #2c2622;
    --header-bg: #1b1714;
    --stat-bg: #1a1613;
    --table-head-bg: #1b1714;
    --shadow: rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Geist", "Space Grotesk", "IBM Plex Sans", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px;
}

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.site-header h1 {
  margin: 0;
  font-size: 18px;
}

.site-header nav {
  display: flex;
  gap: 12px;
  align-items: center;
}

.user { color: var(--muted); }

h2, h3 { margin-top: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  margin: 10px 0;
  box-shadow: 0 8px 20px var(--shadow);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.engine-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.engine-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 6px;
  margin: 10px 0;
}

.stat {
  background: var(--stat-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 8px;
}

.stat .label { color: var(--muted); font-size: 11px; }
.stat .value { font-size: 16px; font-weight: 600; }

.progress {
  position: relative;
  height: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
}

.progress-steps {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
}

.progress-steps span {
  border-left: 1px solid var(--border);
}

.progress-steps span:first-child {
  border-left: none;
}

label { display: block; margin-bottom: 8px; }
input, textarea {
  width: 100%;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 12px;
}

button, .btn {
  border: none;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
}

button.danger, .danger button {
  background: #7a1f10;
}

.inline {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.inline input,
.inline textarea {
  width: auto;
  flex: 1 1 auto;
  min-width: 0;
}

.inline button {
  flex: 0 0 auto;
}

.parts {
  list-style: none;
  padding: 0;
}

.parts li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.actions { display: flex; gap: 8px; }

.card table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--border);
  margin-top: 8px;
}

.card th,
.card td {
  text-align: left;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
}

.card thead th {
  background: var(--table-head-bg);
}

.card tbody td {
  border-right: 1px solid var(--border);
}

.card tbody td:last-child {
  border-right: none;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.table-wrap table {
  min-width: 620px;
}

.flashes {
  list-style: none;
  padding: 0;
  margin: 0 0 12px 0;
}

.flash {
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 8px;
}

.flash.error { background: #ffe1db; color: #7a1f10; }

@media (max-width: 640px) {
  .container { padding: 8px; }
  .site-header .container { gap: 6px; }
  .site-header nav { gap: 6px; font-size: 12px; }
  .inline { flex-direction: row; align-items: center; gap: 6px; }
  .inline input { flex: 1 1 auto; min-width: 0; }
  .inline textarea { flex: 1 1 auto; min-width: 0; }
  .inline button { flex: 0 0 auto; }
  .header-row { flex-direction: column; align-items: flex-start; }
  .parts li { flex-direction: column; align-items: flex-start; }
  .actions { width: 100%; }
  .actions form { flex: 1; }
  .actions button { width: 100%; }
  .table-wrap { overflow-x: visible; }
  .table-wrap table { min-width: 0; border: none; }
  .table-wrap thead { display: none; }
  .table-wrap tbody tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 5px 8px;
    margin-bottom: 6px;
    background: var(--stat-bg);
  }
  .table-wrap tbody td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border: none;
    padding: 3px 0;
  }
  .table-wrap tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
  }
}
