:root {
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-border: #e1e5ea;
  --color-text: #1f2933;
  --color-muted: #6b7280;
  --color-accent: #2563eb;
  --color-accent-dark: #1d4ed8;
  --color-danger: #dc2626;
  --color-success-bg: #ecfdf5;
  --color-success-text: #047857;
  --color-error-bg: #fef2f2;
  --color-error-text: #b91c1c;
  --color-warn-bg: #fffbeb;
  --color-warn-text: #b45309;
  --sidebar-width: 200px;
  --topbar-height: 56px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Sarabun", Tahoma, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

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

a:hover {
  text-decoration: underline;
}

h1 {
  font-size: 1.5rem;
  margin: 0 0 1rem;
}

h2 {
  font-size: 1.1rem;
  margin: 1.5rem 0 0.75rem;
}

.layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 1rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 600;
}

.nav-toggle {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 1.1rem;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 1.25rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
}

.sidebar a {
  display: block;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  color: var(--color-text);
  font-size: 0.95rem;
}

.sidebar a:hover {
  background: var(--color-bg);
  text-decoration: none;
}

.sidebar a.active {
  background: var(--color-accent);
  color: #fff;
}

.content {
  margin-left: var(--sidebar-width);
  padding: 1.5rem;
  flex: 1;
  width: calc(100% - var(--sidebar-width));
}

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--color-bg);
}

.auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}

.auth-card h1 {
  font-size: 1.25rem;
}

form label {
  display: block;
  margin-bottom: 0.9rem;
  font-size: 0.9rem;
  color: var(--color-muted);
}

form label.checkbox {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--color-text);
}

form label.checkbox input {
  width: auto;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="file"],
select,
textarea {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.95rem;
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
}

button {
  cursor: pointer;
  font-family: inherit;
}

button[type="submit"],
.btn-secondary,
.btn-danger {
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
}

button[type="submit"] {
  background: var(--color-accent);
  color: #fff;
  width: 100%;
}

button[type="submit"]:hover {
  background: var(--color-accent-dark);
}

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-danger {
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border: 1px solid #fca5a5;
}

.card-form {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 1.25rem;
  max-width: 480px;
}

.dropzone {
  position: relative;
  border: 2px dashed var(--color-border);
  border-radius: 10px;
  padding: 1.75rem 1rem;
  text-align: center;
  margin-bottom: 0.9rem;
  background: var(--color-bg);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.dragover {
  border-color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 8%, var(--color-bg));
}

.dropzone-text {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.9rem;
}

.dropzone-link {
  color: var(--color-accent);
  text-decoration: underline;
}

.dropzone-filename {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  margin: 0;
}

.filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 0.85rem;
}

.filter-form input,
.filter-form select {
  width: auto;
  flex: 1 1 140px;
  margin-top: 0;
}

.filter-form button {
  flex: 0 0 auto;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1.1rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.stat-label {
  color: var(--color-muted);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
}

.plain-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.9rem;
}

.plain-list li {
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--color-bg);
}

.plain-list li:last-child {
  border-bottom: none;
}

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

.hint {
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--color-muted);
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.alert-error {
  background: var(--color-error-bg);
  color: var(--color-error-text);
}

.table-wrap {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-ok {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.badge-warn {
  background: var(--color-warn-bg);
  color: var(--color-warn-text);
}

.badge-muted {
  background: var(--color-bg);
  color: var(--color-muted);
}

.share-box {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  max-width: 560px;
}

.share-box input {
  margin-top: 0;
  background: var(--color-bg);
}

.copy-btn {
  flex: 0 0 auto;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0 1rem;
  font-weight: 600;
}

.qr-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 1.1rem;
  margin-bottom: 1.25rem;
  max-width: 280px;
  text-align: center;
}

.qr-label {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
  color: var(--color-muted);
}

.qr-code {
  display: flex;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.qr-code svg {
  max-width: 100%;
  height: auto;
  background: #fff;
  border-radius: 6px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.9rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 1.1rem;
  margin-bottom: 1.25rem;
}

.detail-grid .label {
  display: block;
  color: var(--color-muted);
  font-size: 0.78rem;
  margin-bottom: 0.2rem;
}

.actions {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.actions form {
  margin: 0;
}

.row-actions {
  display: flex;
  gap: 0.5rem;
}

.row-actions form {
  margin: 0;
}

.row-actions button {
  white-space: nowrap;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #14181f;
    --color-surface: #1c222c;
    --color-border: #2c3542;
    --color-text: #e5e9ef;
    --color-muted: #8b96a5;
    --color-success-bg: #062f24;
    --color-success-text: #34d399;
    --color-error-bg: #33131a;
    --color-error-text: #f87171;
    --color-warn-bg: #332409;
    --color-warn-text: #fbbf24;
  }
}

@media (max-width: 768px) {
  .topbar {
    display: flex;
  }

  .sidebar {
    top: var(--topbar-height);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.08);
    z-index: 20;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .content {
    margin-left: 0;
    width: 100%;
  }
}
