:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --text: #152033;
  --muted: #65738a;
  --border: #d9e0ea;
  --primary: #1f6feb;
  --primary-dark: #1557bd;
  --danger: #c62828;
  --shadow: 0 10px 30px rgba(21, 32, 51, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

h1, h2 { margin: 0 0 8px; }
.muted { color: var(--muted); margin: 0; }
.hidden { display: none !important; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.not-found-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(31, 111, 235, .12), transparent 38%),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
}
.not-found-card {
  width: min(560px, 100%);
  display: grid;
  gap: 18px;
  text-align: center;
  background: rgba(255, 255, 255, .92);
  border: 1px solid rgba(217, 224, 234, .9);
  border-radius: 28px;
  padding: 40px 32px;
  box-shadow: 0 24px 60px rgba(21, 32, 51, .12);
  backdrop-filter: blur(10px);
}
.not-found-card h1 {
  margin: 0;
  font-size: clamp(32px, 5vw, 48px);
}
.not-found-code {
  margin: 0;
  font-size: clamp(68px, 14vw, 132px);
  line-height: .9;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -.06em;
}
.not-found-path {
  margin: 0;
  padding: 10px 14px;
  border-radius: 999px;
  background: #f3f7fd;
  color: var(--muted);
  font-size: 14px;
  word-break: break-all;
}
.not-found-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.stack { display: grid; gap: 16px; margin-top: 20px; }
.small-stack { gap: 10px; }

label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input, textarea, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
}
textarea { min-height: 82px; resize: vertical; }
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-weight: 650;
  text-decoration: none;
}
button:hover, .button:hover { text-decoration: none; }
.primary { background: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-dark); }
.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.danger { background: #fff; color: var(--danger); border-color: #efb5b5; }
.alert { padding: 12px 14px; background: #ffe8e8; color: #8b0000; border-radius: 12px; margin: 16px 0; }
.notice { padding: 10px 12px; background: #eef6ff; border: 1px solid #cfe5ff; border-radius: 12px; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  padding: 24px clamp(16px, 4vw, 44px);
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: grid; gap: 4px; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar-actions form { margin: 0; }
.container { padding: 24px clamp(16px, 4vw, 44px); display: grid; gap: 20px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 20px;
}
.toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.search-box { flex: 1 1 360px; }
.filters-wrap { margin-bottom: 16px; }
.filters-wrap summary { cursor: pointer; color: var(--muted); margin-bottom: 10px; }
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: #f8fafc; z-index: 1; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f2f7ff; }
td { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.pagination-summary {
  color: var(--muted);
  font-size: 14px;
}
.pagination-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.page-link,
.page-gap {
  min-width: 42px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
}
.page-link {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.page-link:hover:not(:disabled) {
  border-color: #b9c5d6;
  background: #f8fafc;
}
.page-link:disabled {
  cursor: default;
  opacity: .55;
}
.page-link.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.page-gap {
  color: var(--muted);
}

.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin: 14px 0; }
.inline-form input { max-width: 260px; }
.temp-users { display: grid; gap: 8px; }
.temp-user-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}

.back-link { display: inline-block; margin-bottom: 10px; }
.detail-grid {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr minmax(240px, 310px);
  gap: 22px;
  align-items: start;
}
.photo-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 18px;
  margin-bottom: 14px;
}
.detail-title-row {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 18px;
}
.fields-list {
  display: grid;
  grid-template-columns: minmax(120px, 220px) 1fr;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}
.fields-list dt, .fields-list dd { margin: 0; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.fields-list dt { background: #f8fafc; color: var(--muted); }
.fields-list dd { white-space: pre-wrap; }
.fields-list dt:last-of-type, .fields-list dd:last-of-type { border-bottom: none; }
.qr-card {
  display: grid;
  gap: 12px;
  justify-items: center;
  text-align: center;
}
.qr-card img { width: min(100%, 260px); border: 1px solid var(--border); border-radius: 16px; background: white; }
.pm-id-under-qr { font-weight: 800; font-size: 18px; }
#machineUrl { font-size: 12px; }

.dialog-form { min-width: min(880px, 92vw); }
dialog {
  border: none;
  border-radius: 22px;
  box-shadow: 0 24px 80px rgba(21, 32, 51, .25);
  padding: 24px;
}
dialog::backdrop { background: rgba(21, 32, 51, .45); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 14px; margin-top: 16px; }
.form-grid .wide { grid-column: 1 / -1; }
menu { display: flex; justify-content: flex-end; gap: 10px; margin: 18px 0 0; padding: 0; }

@media (max-width: 1050px) {
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .topbar { flex-direction: column; }
  .topbar-actions { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .fields-list { grid-template-columns: 1fr; }
  .fields-list dt { border-bottom: none; padding-bottom: 2px; }
  .fields-list dd { padding-top: 4px; }
  .pagination {
    align-items: stretch;
  }
  .pagination-controls {
    width: 100%;
  }
}
