:root {
  --bg-page: #f5f6f8;
  --bg-surface: #ffffff;
  --bg-sidebar: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d0d5dd;
  --text-primary: #101828;
  --text-secondary: #667085;
  --text-muted: #98a2b3;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-bg: #eef2ff;
  --accent-text: #4338ca;
  --success: #067647;
  --success-bg: #ecfdf3;
  --warning: #b54708;
  --warning-bg: #fffaeb;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --radius: 8px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 10px -2px rgba(16, 24, 40, 0.08), 0 2px 4px -2px rgba(16, 24, 40, 0.05);
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg-page);
  color: var(--text-primary);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 21px; }
h3 { font-size: 15px; }

a { color: inherit; text-decoration: none; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 216px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  padding: 4px 8px 22px;
}
.sidebar-logo { width: 100%; height: auto; display: block; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}
.sidebar-link i { font-size: 17px; width: 17px; text-align: center; }
.sidebar-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
}
.sidebar-link:hover { background: var(--bg-page); color: var(--text-primary); }
.sidebar-link.is-active {
  background: var(--accent-bg);
  color: var(--accent-text);
  font-weight: 600;
}

.sidebar-footer { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.sidebar-copyright { font-size: 11px; color: var(--text-muted); text-align: center; margin: 14px 0 0; }

.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-bg); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center;
  font-size: 11.5px; font-weight: 600;
  flex-shrink: 0;
}
.user-chip-info { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11.5px; color: var(--text-muted); }
.logout-form { margin: 0; }
.link-btn {
  background: none; border: none; padding: 0; cursor: pointer;
  font-size: 12px; color: var(--text-muted);
}
.link-btn:hover { color: var(--danger); text-decoration: underline; }

.app-main {
  flex: 1;
  padding: 30px 36px;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

@media (min-width: 1600px) {
  .app-main { max-width: 1600px; padding: 36px 48px; }
}

@media (min-width: 2000px) {
  .app-main { max-width: 1800px; padding: 40px 56px; }
}

@media (max-width: 900px) {
  .app-main { padding: 20px; }
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}
.header-actions { display: flex; gap: 8px; }
.muted-inline { color: var(--text-muted); font-weight: 400; font-size: 16px; }

.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 15px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  cursor: pointer;
  background: var(--bg-surface);
  transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease, transform 0.05s ease;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary:hover { background: var(--bg-page); border-color: var(--border-strong); }
.btn-primary:active, .btn-secondary:active { transform: scale(0.98); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 14px;
}
.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-bg);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  flex-shrink: 0;
}
.stat-icon.tone-success { background: var(--success-bg); color: var(--success); }
.stat-icon.tone-warning { background: var(--warning-bg); color: var(--warning); }
.stat-icon.tone-danger { background: var(--danger-bg); color: var(--danger); }
.stat-body { min-width: 0; }
.stat-label { font-size: 12.5px; color: var(--text-muted); margin: 0 0 4px; }
.stat-value { font-size: 23px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.stat-warning { color: var(--warning); }

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.panel.span-2 { grid-column: span 2; }
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
}
.panel-header .link { font-size: 13px; color: var(--accent); font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.panel-header .link:hover { color: var(--accent-hover); }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}
.type-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.type-chip-name { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.type-chip-count { font-size: 15px; font-weight: 700; color: var(--text-primary); }

.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.nowrap { white-space: nowrap; }
.data-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background 0.1s ease; }
.data-table tbody tr:hover { background: var(--accent-bg); cursor: pointer; }
.data-table.compact td, .data-table.compact th { padding: 7px 8px; }

.kv-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.kv-table td { padding: 9px 4px; border-bottom: 1px solid var(--border); vertical-align: top; }
.kv-table tr td:first-child { color: var(--text-muted); width: 40%; font-weight: 500; }
.kv-table tr:last-child td { border-bottom: none; }

.muted { color: var(--text-muted); }
.empty-state { text-align: center; color: var(--text-muted); padding: 32px 0 !important; cursor: default; }

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  text-transform: capitalize;
}
.badge-available { background: var(--accent-bg); color: var(--accent-text); }
.badge-assigned { background: var(--success-bg); color: var(--success); }
.badge-in_repair { background: var(--warning-bg); color: var(--warning); }
.badge-retired { background: #f2f4f7; color: var(--text-secondary); }
.badge-lost { background: var(--danger-bg); color: var(--danger); }

.badge-tone-success { background: var(--success-bg); color: var(--success); }
.badge-tone-warning { background: var(--warning-bg); color: var(--warning); }
.badge-tone-danger { background: var(--danger-bg); color: var(--danger); }
.badge-tone-muted { background: #f2f4f7; color: var(--text-secondary); }
.badge-tone-info { background: var(--accent-bg); color: var(--accent-text); }

.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-bar input[type="text"] { flex: 1; min-width: 200px; }

.filter-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.filter-checkbox input[type="checkbox"] { width: auto; }

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  font-size: 13px;
}
.pagination-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: 13px;
}
input[type="text"], input[type="date"], input[type="number"], input[type="password"], select, textarea {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px 11px;
  background: var(--bg-surface);
  color: var(--text-primary);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-bg);
  border-color: var(--accent);
}

.form-panel { max-width: 740px; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 12.5px; color: var(--text-secondary); font-weight: 500; }
.form-field textarea { resize: vertical; }
.form-actions { display: flex; gap: 8px; margin-top: 18px; }

.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.inline-form input { flex: 1; min-width: 140px; }

.flash {
  padding: 11px 15px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  font-weight: 500;
}
.flash-danger { background: var(--danger-bg); color: var(--danger); }
.flash-info { background: var(--accent-bg); color: var(--accent-text); }

.login-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-page);
  font-family: var(--font-sans);
}
.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 36px 32px;
  width: 420px;
  text-align: center;
}
.login-logo { width: 100%; max-width: 300px; height: auto; margin: 0 auto 14px; display: block; }
.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 8px;
}
.login-brand i {
  font-size: 18px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-sub { font-size: 13px; color: var(--text-secondary); margin: 0 0 24px; }
.login-form { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.login-form label { font-size: 12.5px; color: var(--text-secondary); margin-top: 8px; font-weight: 500; }
.login-form .btn-primary { justify-content: center; margin-top: 18px; padding: 10px 15px; }
.login-hint { font-size: 12px; color: var(--text-muted); margin-top: 20px; }
.login-hint code { background: var(--bg-page); padding: 1px 5px; border-radius: 4px; }

.login-copyright { font-size: 11px; color: var(--text-muted); text-align: center; margin: 18px 0 0; }
.login-version { font-size: 11px; color: var(--text-muted); text-align: center; margin: 10px 0 0; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.settings-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.12s ease, border-color 0.12s ease;
}
.settings-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.settings-card i {
  font-size: 18px;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent-bg);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.settings-card h3 { margin: 0 0 4px; }
.settings-card p { margin: 0; font-size: 13px; }

.permissions-label { font-size: 12.5px; color: var(--text-secondary); font-weight: 500; display: block; margin-bottom: 8px; }
.permissions-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
}
.permission-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 5px 0;
}
.permission-row input[type="checkbox"] { width: auto; }

.inline-form-tight {
  display: flex;
  gap: 6px;
  margin: 0;
}
.inline-form-tight input { flex: 1; }

.thumb-cell { width: 48px; }
.photo-thumb {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  object-fit: cover;
  border: 1px solid var(--border);
  display: block;
}
.photo-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  background: var(--bg-page);
  font-size: 16px;
}

.photo-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.photo-gallery-item {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 1;
}
.photo-gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(16, 24, 40, 0.6);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  font-size: 13px;
  transition: background 0.12s ease;
}
.photo-delete-btn:hover { background: var(--danger); }

.photo-placeholder {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 100px;
  border-radius: var(--radius);
  border: 1px dashed var(--border-strong);
  color: var(--text-muted);
  font-size: 13px;
  justify-content: center;
  margin-bottom: 14px;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.lightbox-overlay.is-open { display: flex; }
.lightbox-image {
  max-width: 88vw;
  max-height: 88vh;
  object-fit: contain;
  cursor: zoom-in;
  transition: transform 0.15s ease;
  border-radius: 4px;
  user-select: none;
}
.lightbox-image.is-zoomed {
  cursor: zoom-out;
  transform: scale(1.9);
  max-width: none;
  max-height: none;
}
.lightbox-close,
.lightbox-nav {
  position: absolute;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.12s ease;
}
.lightbox-close:hover,
.lightbox-nav:hover { background: rgba(255, 255, 255, 0.28); }
.lightbox-close {
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  font-size: 18px;
}
.lightbox-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  font-size: 20px;
}
.lightbox-prev { left: 20px; }
.lightbox-next { right: 20px; }
.lightbox-counter {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.12);
  padding: 5px 14px;
  border-radius: 999px;
}
.lightbox-hint {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.6);
  font-size: 12px;
}

.tag-sheet { display: flex; flex-wrap: wrap; gap: 10px; }
.tag-sticker {
  width: 288px;
  padding: 14px 16px;
  background: #fff;
  border: 1.5px solid #101828;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.tag-sticker-info { flex: 1; min-width: 0; }
.tag-brand { font-size: 10px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); margin: 0 0 4px; }
.tag-asset-tag { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 4px; }
.tag-asset-name { font-size: 12px; color: var(--text-secondary); margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-qr { width: 72px; height: 72px; flex-shrink: 0; }
.tags-toolbar { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 16px; }

@media print {
  .sidebar { display: none !important; }
  .app-main { padding: 0 !important; max-width: none !important; margin: 0 !important; }
}
