*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', system-ui, sans-serif;
  color: #1f2937;
  background: #f3f4f6;
  font-size: 14px;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* Layout */
aside.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: 240px; background: #ffffff; border-right: 1px solid #e5e7eb;
  display: flex; flex-direction: column; padding: 20px 14px;
  z-index: 10;
}
main.main { margin-left: 240px; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; background: #ffffff; border-bottom: 1px solid #e5e7eb;
  position: sticky; top: 0; z-index: 5;
}
.page-title { margin: 0; font-size: 20px; font-weight: 700; }
.content { padding: 24px 28px; flex: 1; }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 10px;
  object-fit: cover; background: #fff;
  display: block;
}
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; color: #6b7280; }

/* Nav */
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; color: #4b5563;
  cursor: pointer; transition: all .15s ease;
}
.nav-item:hover { background: #f3f4f6; }
.nav-item.active {
  background: #eff6ff; color: #1d4ed8; font-weight: 600;
  position: relative;
}
.nav-item.active::after { content: '›'; position: absolute; right: 12px; }
.nav-icon {
  width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center;
  color: #2563eb; flex-shrink: 0;
}
.nav-icon svg { width: 20px; height: 20px; display: block; }
.nav-item.active .nav-icon { color: #1d4ed8; }
.nav-sep { height: 1px; background: #e5e7eb; margin: 10px 4px; }

.sidebar-footer { border-top: 1px solid #e5e7eb; padding-top: 12px; }
.user-chip { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 10px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #dbeafe; color: #1d4ed8; display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.user-name { font-weight: 600; font-size: 13px; }
.user-logout { font-size: 12px; color: #ef4444; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 10px; border: 1px solid transparent;
  background: #fff; color: #111827; cursor: pointer; font-size: 13px;
  transition: all .15s ease;
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: #f3f4f6; }
.btn-danger { background: #fff; color: #dc2626; border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-block { width: 100%; justify-content: center; }
.icon-btn { background: transparent; border: 0; font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: #f3f4f6; }

/* Panels */
.panel {
  background: #fff; border-radius: 14px; border: 1px solid #e5e7eb;
  padding: 18px; box-shadow: 0 1px 2px rgba(0,0,0,.02);
}
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-title { margin: 0; font-size: 15px; font-weight: 700; }

/* Cards */
.card-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px; margin-bottom: 18px;
}
.stat-card {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 14px; padding: 16px;
}
.stat-label { color: #6b7280; font-size: 12px; }
.stat-value { font-size: 28px; font-weight: 800; margin: 6px 0; }
.stat-sub { font-size: 12px; color: #6b7280; }

/* Search */
.search-bar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.input {
  flex: 1; min-width: 180px; padding: 9px 14px; border: 1px solid #e5e7eb; border-radius: 10px;
  font-size: 13px; outline: none; background: #fff;
}
.input:focus { border-color: #93c5fd; box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.input-sm { max-width: 140px; flex: 0 0 auto; }

/* Tables */
.table-wrap {
  overflow-x: auto; border-radius: 10px; border: 1px solid #f1f5f9;
}
.data-table, .simple-table {
  width: 100%; border-collapse: collapse; table-layout: fixed;
}
.data-table th, .data-table td, .simple-table th, .simple-table td {
  padding: 12px 14px; text-align: left;
  border-bottom: 1px solid #f1f5f9;
  border-right: 1px solid #e5e7eb;
  vertical-align: middle; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.data-table th:last-child, .data-table td:last-child,
.simple-table th:last-child, .simple-table td:last-child {
  border-right: 0;
}
.data-table thead th, .simple-table thead th {
  background: #fafafa; color: #6b7280; font-weight: 600; font-size: 12px;
  position: sticky; top: 0; user-select: none;
}
.data-table thead th { position: relative; cursor: pointer; }
.th-label { margin-right: 6px; }
.th-sort { color: #cbd5e1; font-size: 11px; }
.data-table thead th.sort-asc .th-sort::before { content: '↑'; color: #2563eb; }
.data-table thead th.sort-desc .th-sort::before { content: '↓'; color: #2563eb; }
.data-table thead th.sort-asc .th-sort, .data-table thead th.sort-desc .th-sort { color: #2563eb; }
.th-resizer {
  position: absolute; top: 0; right: 0; width: 6px; height: 100%;
  cursor: col-resize; user-select: none;
}
.th-resizer:hover { background: #dbeafe; }
.data-table tbody tr:hover { background: #fafbff; }
.data-table td[data-editable] { cursor: text; }
.data-table td.inline-editing { padding: 4px 6px; background: #fff8e1; overflow: visible; }
.inline-input {
  width: 100%; padding: 6px 8px; font-size: 13px; font-family: inherit;
  border: 1px solid #fbbf24; border-radius: 6px; outline: none; background: #fff;
}
.inline-input:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
textarea.inline-input { resize: vertical; min-height: 48px; }

.empty { color: #9ca3af; text-align: center; padding: 24px 0; }
.muted { color: #6b7280; font-size: 12px; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: #e0e7ff; color: #3730a3;
}
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-ok { background: #dcfce7; color: #166534; }

.low-stock { color: #dc2626; font-weight: 700; }
.text-danger { color: #dc2626; }

/* Actions column buttons */
.row-actions { display: flex; gap: 6px; }
.row-actions .icon-btn { font-size: 14px; color: #6b7280; }
.row-actions .icon-btn:hover { color: #2563eb; background: #eff6ff; }
.row-actions .icon-btn.del:hover { color: #dc2626; background: #fef2f2; }

/* Pagination */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 14px; padding-top: 6px;
}
.pager { display: flex; align-items: center; gap: 10px; }

/* Modal */
.modal {
  position: fixed; inset: 0; background: rgba(17,24,39,.4); display: flex;
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: #fff; border-radius: 14px; width: 520px; max-width: 100%;
  max-height: 90vh; display: flex; flex-direction: column;
}
.modal-header {
  padding: 16px 18px; border-bottom: 1px solid #f1f5f9;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.modal-footer { padding: 12px 18px; border-top: 1px solid #f1f5f9; display: flex; justify-content: flex-end; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 12px; color: #6b7280; }
.field input, .field textarea, .field select {
  padding: 9px 12px; border: 1px solid #e5e7eb; border-radius: 10px; font-family: inherit; font-size: 13px; outline: none;
}
.field input:focus, .field textarea:focus { border-color: #93c5fd; box-shadow: 0 0 0 3px rgba(59,130,246,.15); }

/* Login */
.login-page {
  min-height: 100vh; background: linear-gradient(135deg,#eff6ff,#dbeafe);
  display: flex; align-items: center; justify-content: center;
}
.login-wrap { width: 100%; display: flex; justify-content: center; padding: 20px; }
.login-card {
  background: #fff; border-radius: 16px; padding: 32px;
  width: 380px; box-shadow: 0 10px 40px rgba(15,23,42,.1);
  text-align: center;
}
.login-logo {
  width: 96px; height: 96px; border-radius: 18px; margin: 0 auto 14px;
  object-fit: cover; background: #fff;
  display: block;
  box-shadow: 0 4px 12px rgba(15,23,42,.08);
}
.login-title { margin: 0; font-size: 22px; }
.login-sub { color: #6b7280; margin: 4px 0 22px; }
.login-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.login-form label { display: flex; flex-direction: column; font-size: 12px; color: #6b7280; gap: 6px; }
.login-form input {
  padding: 10px 14px; border: 1px solid #e5e7eb; border-radius: 10px; font-size: 14px; outline: none;
}
.login-form input:focus { border-color: #93c5fd; box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.login-hint { margin-top: 16px; font-size: 12px; color: #6b7280; }
.login-hint code { background: #f3f4f6; padding: 2px 6px; border-radius: 6px; color: #1d4ed8; }
.alert { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 13px; }
.alert.error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

/* Action log badges */
.action-create { background: #dcfce7; color: #166534; }
.action-update { background: #dbeafe; color: #1d4ed8; }
.action-delete { background: #fef3c7; color: #92400e; }
.action-restore { background: #e0f2fe; color: #075985; }
.action-purge { background: #fee2e2; color: #b91c1c; }
.action-login { background: #f5f3ff; color: #6d28d9; }
.action-logout { background: #f3f4f6; color: #374151; }

/* Location pills (for position-like values e.g. 前輪/後輪 may repurpose) */
.loc-front { background: #dbeafe; color: #1d4ed8; }
.loc-rear { background: #f5f3ff; color: #6d28d9; }
