:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: #2f5fda;
  --primary-dark: #2447ad;
  --danger: #d1453b;
  --danger-bg: #fdecea;
  --ok: #1e8e5a;
  --ok-bg: #e7f6ee;
  --warn: #b5760a;
  --warn-bg: #fdf1de;
  --info: #2f5fda;
  --info-bg: #e9eefc;
  --muted-bg: #eef0f3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  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 0 0.75rem 0; font-weight: 700; }
h2 { font-size: 1.15rem; margin: 2rem 0 0.75rem 0; font-weight: 600; }

.container { max-width: 1080px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.05rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-logo { height: 30px; width: auto; display: block; }
.nav { display: flex; gap: 0.25rem; flex: 1; }
.nav-link {
  color: var(--text-muted);
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.92rem;
}
.nav-link:hover { background: var(--muted-bg); text-decoration: none; }
.nav-link.active { color: var(--primary); background: var(--info-bg); }
.user-menu { display: flex; align-items: center; gap: 0.75rem; }
.user-name { color: var(--text-muted); font-size: 0.9rem; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.barchart { display: flex; flex-direction: column; gap: 0.6rem; margin: 1rem 0 1.5rem; }
.bar-row {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  align-items: center;
  gap: 0.75rem;
}
.bar-label {
  font-size: 0.85rem;
  color: var(--text);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-track {
  background: var(--muted-bg);
  border-radius: 0 4px 4px 0;
  height: 20px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 0 4px 4px 0;
  transition: filter 0.1s ease;
}
.bar-row:hover .bar-fill { filter: brightness(0.92); }
.bar-value {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  min-width: 100px;
  font-variant-numeric: tabular-nums;
}
.bar-empty { color: var(--text-muted); font-size: 0.9rem; }

.update-badge { text-align: right; white-space: nowrap; }
.update-badge .label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.update-badge .value { font-size: 0.95rem; font-weight: 600; color: var(--text); }
.update-badge .value.muted { font-weight: 500; color: var(--text-muted); }

.btn {
  display: inline-block;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { background: var(--muted-bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.9); }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; padding: 0; font-size: 0.9rem; }
.btn-link.danger { color: var(--danger); }
.btn:disabled, .btn-link:disabled { opacity: 0.4; cursor: not-allowed; }

.inline-form { display: inline; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.stat-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  min-width: 180px;
  flex: 1;
  box-shadow: var(--shadow);
}
.stat-label { color: var(--text-muted); font-size: 0.82rem; margin-bottom: 0.35rem; text-transform: uppercase; letter-spacing: 0.02em; }
.stat-value { font-size: 1.5rem; font-weight: 700; }
.text-danger { color: var(--danger); }
.text-ok { color: var(--ok); }

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td {
  padding: 0.65rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.table th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.02em; background: #fafbfc; }
.table tr:last-child td { border-bottom: none; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-link { cursor: pointer; }
.row-link:hover { background: var(--muted-bg); }

.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: var(--muted-bg); color: var(--text-muted); }

.chips { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
}
.chip:hover { background: var(--muted-bg); text-decoration: none; }
.chip-active { background: var(--primary); border-color: var(--primary); color: #fff; }

.pagination { display: flex; align-items: center; gap: 0.75rem; margin-top: 1rem; }

.form { display: flex; flex-direction: column; gap: 0.9rem; max-width: 480px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.88rem; font-weight: 600; color: var(--text-muted); }
.form label.checkbox { flex-direction: row; align-items: center; gap: 0.5rem; }
.form input, .form select, .form textarea {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
}
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.form-inline { max-width: none; flex-direction: row; flex-wrap: wrap; align-items: center; }
.form-inline input, .form-inline select { width: auto; }

.search-form { display: flex; gap: 0.5rem; margin-bottom: 1rem; max-width: 680px; flex-wrap: wrap; }
.search-form input { flex: 1; min-width: 220px; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: 8px; font-size: 0.92rem; }
.search-form select { padding: 0.5rem 0.65rem; border: 1px solid var(--border); border-radius: 8px; font-size: 0.92rem; background: #fff; }

.auth-box {
  max-width: 400px;
  margin: 4rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}
.auth-logo { display: block; max-width: 260px; width: 100%; height: auto; margin: 0 auto 1.5rem; }

.alert { padding: 0.65rem 0.9rem; border-radius: 8px; margin-bottom: 0.75rem; font-size: 0.9rem; }
.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-info { background: var(--info-bg); color: var(--info); }

.muted { color: var(--text-muted); }
.small { font-size: 0.82rem; }

.timeline { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 1rem; }
.timeline-item { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem 1rem; }
.timeline-meta { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.25rem; text-transform: capitalize; }

.receipt { max-width: 480px; margin: 2rem auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; }
.receipt-table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.receipt-table th { text-align: left; color: var(--text-muted); font-weight: 600; padding: 0.4rem 0; width: 40%; vertical-align: top; }
.receipt-table td { padding: 0.4rem 0; }
.receipt-total { font-size: 1.3rem; font-weight: 700; text-align: right; }

@media print {
  .app-header, .no-print { display: none !important; }
  body { background: #fff; }
}

@media (max-width: 720px) {
  .app-header-inner { flex-wrap: wrap; }
  .nav { order: 3; width: 100%; }
  .stat-row { flex-direction: column; }
}
