/* mecherp – Werkstatt-UI */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #1a2332;
  --muted: #5b6b7f;
  --line: #e2e8f0;
  --brand: #1e5ab4;
  --brand-dark: #16448a;
  --accent: #e8f0fb;
  --ok: #1a7f4e;
  --ok-bg: #e6f6ee;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fde8e8;
  --info: #1e5ab4;
  --info-bg: #e8f0fb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 32, 64, .08), 0 4px 14px rgba(16, 32, 64, .05);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  display: grid;
  grid-template-columns: 230px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: #132238;
  color: #d7e2f2;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 0 1.25rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  margin-bottom: 1rem;
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2f7de1, #1e5ab4);
  display: grid; place-items: center;
  font-weight: 700; color: #fff; font-size: 1.05rem;
}
.brand-name { font-weight: 700; color: #fff; letter-spacing: .2px; }
.brand-sub { font-size: .72rem; color: #8fa6c4; text-transform: uppercase; letter-spacing: .08em; }

.nav { display: flex; flex-direction: column; gap: .25rem; padding: 0 .75rem; }
.nav a {
  display: flex; align-items: center; gap: .7rem;
  padding: .65rem .85rem;
  border-radius: 8px;
  color: #c3d3ea;
  text-decoration: none;
  font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; }
.nav .icon { width: 1.25rem; text-align: center; opacity: .9; }

.sidebar-foot {
  margin-top: auto;
  padding: 1rem 1.25rem 0;
  font-size: .78rem;
  color: #7d94b4;
  border-top: 1px solid rgba(255,255,255,.08);
}

/* Main */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: .95rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { margin: 0; font-size: 1.25rem; font-weight: 700; }
.topbar .actions { display: flex; gap: .6rem; align-items: center; }

.content { padding: 1.75rem; max-width: 1200px; width: 100%; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card + .card { margin-top: 1.25rem; }
.card-h {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.card-h h2 { margin: 0; font-size: 1.02rem; }
.card-b { padding: 1.25rem; }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 1.75rem; font-weight: 700; margin-top: .25rem; }
.stat .hint { color: var(--muted); font-size: .82rem; margin-top: .25rem; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .93rem;
}
table.data th {
  text-align: left;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
  white-space: nowrap;
}
table.data td {
  padding: .85rem 1.25rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: #f8fafc; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data .empty {
  text-align: center;
  color: var(--muted);
  padding: 2.25rem 1rem !important;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.form-grid .full { grid-column: 1 / -1; }
label.field {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-size: .86rem;
  font-weight: 600;
  color: var(--muted);
}
label.field input,
label.field select,
label.field textarea {
  font: inherit;
  color: var(--ink);
  padding: .65rem .8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  width: 100%;
}
label.field input:focus,
label.field select:focus,
label.field textarea:focus {
  outline: 2px solid rgba(30, 90, 180, .35);
  border-color: var(--brand);
}
label.field textarea { min-height: 96px; resize: vertical; }
.form-actions {
  display: flex;
  gap: .65rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
  align-items: center;
}
.form-actions .spacer { margin-left: auto; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .62rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: .92rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); color: #fff; }
.btn-secondary {
  background: #fff; color: var(--ink); border-color: var(--line);
}
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: #f2c4c4; }
.btn-danger:hover { background: #f9d4d4; }
.btn-sm { padding: .38rem .7rem; font-size: .82rem; }
.btn-link {
  background: none; border: none; color: var(--brand);
  cursor: pointer; font: inherit; font-weight: 600; padding: 0;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .22rem .62rem;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.badge-open { background: var(--warn-bg); color: var(--warn); }
.badge-progress { background: var(--info-bg); color: var(--info); }
.badge-done { background: var(--ok-bg); color: var(--ok); }
.badge-cancel { background: #eef1f5; color: var(--muted); }
.badge-draft { background: #eef1f5; color: var(--muted); }
.badge-sent { background: var(--info-bg); color: var(--info); }
.badge-paid { background: var(--ok-bg); color: var(--ok); }
.badge-overdue { background: var(--danger-bg); color: var(--danger); }
.badge-material { background: #f3e8ff; color: #6b21a8; }
.badge-labor { background: #e8f0fb; color: var(--brand); }

/* Toolbar / search */
.toolbar {
  display: flex;
  gap: .75rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
.toolbar .search {
  flex: 1;
  min-width: 200px;
  max-width: 360px;
  position: relative;
}
.toolbar .search input {
  width: 100%;
  padding: .6rem .9rem .6rem 2.3rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}
.toolbar .search::before {
  content: "⌕";
  position: absolute;
  left: .85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 1.1rem;
}

/* Detail rows */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}
.detail-item .k {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: .15rem;
}
.detail-item .v { font-weight: 600; }

/* Totals box */
.totals-box {
  background: var(--accent);
  border: 1px solid #c9dcf5;
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
}
.totals-box .row {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  padding: .35rem 0;
}
.totals-box .row.total {
  border-top: 2px solid var(--brand);
  margin-top: .55rem;
  padding-top: .75rem;
  font-size: 1.25rem;
  font-weight: 800;
}

/* Alerts */
.alert {
  padding: .85rem 1.15rem;
  border-radius: 8px;
  margin-bottom: 1.15rem;
  font-weight: 600;
  font-size: .92rem;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f2c4c4; }
.alert-ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #bfe8d3; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--muted);
}
.empty-state h3 { margin: .5rem 0; color: var(--ink); }
.empty-state p { margin: 0 0 1.15rem; }

/* Item form inline */
.item-form {
  display: grid;
  grid-template-columns: 130px 1fr 90px 100px 120px auto;
  gap: .65rem;
  align-items: end;
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { display: none; }
  .item-form { grid-template-columns: 1fr 1fr; }
}

/* Print-friendly */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .app { grid-template-columns: 1fr; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 0; }
}

/* Two column layout */
.cols {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.25rem;
}
@media (max-width: 900px) {
  .cols { grid-template-columns: 1fr; }
}

.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }
.text-right { text-align: right; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-2 { margin-bottom: 1rem; }

/* HTMX progress */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
