:root {
  --primary: #0b4f8a;
  --primary-dark: #083b68;
  --primary-light: #e6f0fa;
  --bg: #eef2f6;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #dde3ea;
  --danger: #c0392b;
  --success: #047857;
  --warning: #b45309;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
small, .small { font-size: .85em; }
.muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.pre { white-space: pre-line; margin: 0; }
.inline { display: inline; }

/* Topbar */
.topbar {
  background: var(--primary); color: #fff; display: flex; align-items: center; gap: 1.5rem;
  padding: 0 1.5rem; min-height: 58px; box-shadow: 0 2px 6px rgba(0, 0, 0, .12); position: sticky; top: 0; z-index: 10;
}
.brand { color: #fff; font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: .5rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.login-brand .brand-mark { color: var(--primary); }
.nav { display: flex; align-items: center; gap: .25rem; flex: 1; }
.nav > a { color: rgba(255, 255, 255, .85); padding: .45rem .8rem; border-radius: 6px; }
.nav > a:hover, .nav > a.active { background: rgba(255, 255, 255, .15); color: #fff; text-decoration: none; }
.nav-user { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.nav-user a, .nav-user .btn-link { color: rgba(255, 255, 255, .9); }
.nav-toggle { display: none; margin-left: auto; background: none; border: 0; color: #fff; font-size: 1.5rem; cursor: pointer; }

.container { max-width: 1280px; margin: 0 auto; padding: 1.5rem; }
.page-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-header h1 small { font-weight: 400; font-size: 1rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem 1.5rem; margin-bottom: 1.25rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.grid-2 > .card { margin-bottom: 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .5rem 1rem;
  border: 1px solid var(--border); border-radius: 7px; background: #fff; color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s;
}
.btn:hover { background: #f3f6f9; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f1c4bf; }
.btn-danger:hover { background: #fdecea; }
.btn-sm { padding: .25rem .6rem; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.btn-link:hover { text-decoration: underline; }

/* Forms */
input, select, textarea {
  font: inherit; color: inherit; width: 100%; padding: .55rem .7rem; border: 1px solid var(--border);
  border-radius: 7px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-light); border-color: var(--primary); }
textarea { resize: vertical; }
.form label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; margin-bottom: 1rem; }
.form label.checkbox, label.checkbox { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
label.checkbox input { width: auto; }
.form.narrow { max-width: 560px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1.25rem; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: .5rem; margin-top: .5rem; }
.input-sm { padding: .25rem .5rem; font-size: .85rem; width: auto; }
.searchbar { display: flex; gap: .5rem; padding: 1rem; align-items: center; }
.searchbar input { flex: 1; }
.searchbar select { width: auto; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: .6rem .75rem; border-bottom: 2px solid var(--border); }
.table td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #f7fafc; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 1rem 0; text-align: center; margin: 0; }

/* Badges & tags */
.badge { display: inline-block; padding: .2rem .65rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #e5e7eb; color: #374151; white-space: nowrap; vertical-align: middle; }
.status-new { background: #e0ecff; color: #1d4ed8; }
.status-active { background: #fef3c7; color: #92400e; }
.status-waiting { background: #fde2e1; color: #b91c1c; }
.status-done { background: #d1fae5; color: #065f46; }
.tag { display: inline-block; padding: .05rem .45rem; border-radius: 4px; font-size: .75rem; font-weight: 600; background: var(--primary-light); color: var(--primary); }
.tag-labour { background: #e0ecff; color: #1d4ed8; }
.tag-material { background: #ede9fe; color: #6d28d9; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.25rem; display: flex; flex-direction: column; color: var(--muted); border-left: 5px solid var(--primary); }
.stat:hover { text-decoration: none; transform: translateY(-1px); }
.stat-num { font-size: 2rem; font-weight: 700; color: var(--text); line-height: 1.1; }
.stat-new { border-color: #1d4ed8; }
.stat-active { border-color: #d97706; }
.stat-waiting { border-color: #dc2626; }
.stat-today { border-color: var(--success); }

/* Definition list */
.dl { display: grid; grid-template-columns: 170px 1fr; gap: .4rem 1rem; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }

/* Order rows */
.add-row { display: grid; grid-template-columns: 130px 1fr 90px 130px 130px auto; gap: .5rem; align-items: center; margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--border); }
.row-sum { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.totals { display: flex; justify-content: flex-end; margin-top: 1.25rem; }
.totals table { border-collapse: collapse; min-width: 380px; }
.totals td { padding: .3rem .5rem; }
.totals td.num { white-space: nowrap; }
.totals td:first-child { color: var(--muted); }
.totals tr.sep td { border-top: 1px solid var(--border); color: var(--text); font-weight: 500; }
.totals tr.rot td { color: var(--success); }
.totals tr.grand td { border-top: 2px solid var(--primary); font-size: 1.2rem; font-weight: 700; color: var(--text); padding-top: .5rem; }

.email-actions { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.email-action { display: flex; align-items: center; gap: .75rem; }

/* Flash */
.flashes { margin-bottom: 1rem; }
.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: .5rem; display: flex; justify-content: space-between; align-items: center; border: 1px solid transparent; }
.flash-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash-danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flash-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.flash-info, .flash-message { background: var(--primary-light); border-color: #bfdbfe; color: var(--primary-dark); }
.flash-close { background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: inherit; opacity: .6; }

/* Login */
.login-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 400px; padding: 2rem; }
.login-card h1 { margin-bottom: 1.25rem; font-size: 1.3rem; }
.login-card label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; margin-bottom: 1rem; }
.login-card label.checkbox { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
.login-brand { color: var(--primary); font-weight: 700; font-size: 1.2rem; margin-bottom: 1rem; display: flex; gap: .5rem; align-items: center; }
.error-card { text-align: center; max-width: 480px; margin: 4rem auto; }
.error-card h1 { font-size: 3rem; color: var(--primary); }

@media (max-width: 900px) {
  .grid-2, .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
  .add-row { grid-template-columns: 1fr 1fr; }
  .add-row input[name="description"] { grid-column: span 2; }
  .topbar { flex-wrap: wrap; padding: .5rem 1rem; }
  .nav-toggle { display: block; }
  .nav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; padding-bottom: .5rem; }
  .nav.open { display: flex; }
  .nav-user { margin-left: 0; padding: .5rem .8rem; justify-content: space-between; }
}
@media (max-width: 600px) {
  .container { padding: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .dl { grid-template-columns: 1fr; }
  .dl dt { font-size: .85rem; margin-top: .4rem; }
  .totals table { min-width: 0; width: 100%; }
  .searchbar { flex-wrap: wrap; }
}
@media print {
  .topbar, .no-print, .flashes, .actions { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid var(--border); break-inside: avoid; }
  .container { max-width: none; padding: 0; }
}
