* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; background: #f5f6f8; color: #111; }
body { min-height: 100vh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

header#topbar {
  display: flex; align-items: center; gap: 1.5rem; padding: 0.75rem 1.5rem;
  background: #1f2937; color: #f9fafb; box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
header .brand { font-weight: 600; font-size: 1.05rem; }
header nav { display: flex; gap: 0.25rem; flex: 1; }
header nav .tab {
  background: transparent; border: 0; color: #d1d5db; padding: 0.5rem 0.9rem;
  cursor: pointer; border-radius: 6px; font-size: 0.92rem;
}
header nav .tab.active { background: #374151; color: #fff; }
header nav .tab:hover:not(.active) { background: rgba(255,255,255,0.07); color: #fff; }
header .user { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; }
header .user button { background: #374151; color: #f3f4f6; border: 0; padding: 0.45rem 0.8rem; border-radius: 6px; cursor: pointer; }
header .user button:hover { background: #4b5563; }

main { flex: 1; padding: 1.5rem; max-width: 1280px; margin: 0 auto; width: 100%; }

.view { display: block; }
.view[hidden] { display: none; }

.card {
  background: #fff; border-radius: 10px; padding: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  max-width: 540px; margin: 0 auto 1.25rem;
}
.card h1, .card h2 { margin-top: 0; }
.card label { display: block; margin-bottom: 0.85rem; font-size: 0.88rem; color: #374151; }
.card label input, .card label select, .card label textarea {
  display: block; width: 100%; padding: 0.55rem 0.7rem; margin-top: 0.25rem;
  border: 1px solid #d1d5db; border-radius: 6px; font-size: 0.95rem; font-family: inherit;
}
.card label textarea { font-family: ui-monospace, SFMono-Regular, monospace; }
.card button[type="submit"] {
  background: #2563eb; color: #fff; border: 0; padding: 0.6rem 1.1rem;
  border-radius: 6px; cursor: pointer; font-size: 0.95rem;
}
.card button[type="submit"]:hover { background: #1d4ed8; }

#login-view { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 3rem); }

.toolbar { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar input, .toolbar select { padding: 0.5rem 0.75rem; border: 1px solid #d1d5db; border-radius: 6px; background: #fff; }
.toolbar input { flex: 1; min-width: 200px; }
.toolbar button { background: #fff; border: 1px solid #d1d5db; border-radius: 6px; padding: 0.5rem 1rem; cursor: pointer; }
.toolbar button:hover { background: #f3f4f6; }

table.devices {
  width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px;
  overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
table.devices th, table.devices td { padding: 0.65rem 0.85rem; text-align: left; font-size: 0.91rem; }
table.devices thead { background: #f9fafb; color: #374151; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; }
table.devices tbody tr { border-top: 1px solid #f3f4f6; }
table.devices tbody tr:hover { background: #f9fafb; }
.device-id { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 0.85rem; }
.action-btn { background: #f3f4f6; border: 1px solid #d1d5db; border-radius: 5px; padding: 0.3rem 0.6rem; cursor: pointer; font-size: 0.85rem; }
.action-btn:hover { background: #e5e7eb; }

.status-pill { padding: 0.18rem 0.55rem; border-radius: 999px; font-size: 0.78rem; font-weight: 500; }
.status-in_office { background: #dbeafe; color: #1d4ed8; }
.status-assigned { background: #dcfce7; color: #166534; }
.status-returned { background: #fef3c7; color: #92400e; }
.status-broken { background: #fee2e2; color: #b91c1c; }
.status-lost { background: #f3e8ff; color: #6b21a8; }

.empty { text-align: center; padding: 2rem; color: #6b7280; }

.error { color: #b91c1c; font-size: 0.88rem; min-height: 1.2em; margin-top: 0.5rem; }
.success { color: #166534; font-size: 0.88rem; margin-top: 0.5rem; }

#admins-list { list-style: none; padding: 0; margin: 0; }
#admins-list li { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid #f3f4f6; }
#admins-list li:last-child { border-bottom: 0; }
#admins-list .delete-admin { background: #fee2e2; color: #b91c1c; border: 0; padding: 0.3rem 0.6rem; border-radius: 5px; cursor: pointer; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal[hidden] { display: none; }
.modal-content { background: #fff; border-radius: 12px; padding: 1.5rem; max-width: 720px; width: 95%; max-height: 90vh; overflow-y: auto; position: relative; }
.modal-close { position: absolute; top: 0.5rem; right: 0.75rem; background: transparent; border: 0; font-size: 1.6rem; cursor: pointer; color: #6b7280; }
.modal h2 { margin-top: 0; }
.modal .actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.75rem 0 1.25rem; }
.modal .actions button { background: #2563eb; color: #fff; border: 0; padding: 0.45rem 0.85rem; border-radius: 6px; cursor: pointer; }
.modal .actions button.secondary { background: #f3f4f6; color: #111; border: 1px solid #d1d5db; }
.modal .actions button.danger { background: #b91c1c; color: #fff; }
.modal .field { display: block; margin-bottom: 0.85rem; font-size: 0.9rem; }
.modal .field input, .modal .field select { width: 100%; padding: 0.5rem 0.7rem; border: 1px solid #d1d5db; border-radius: 6px; margin-top: 0.25rem; }
.modal .field label { display: block; font-size: 0.88rem; color: #374151; }

.events-table { font-size: 0.85rem; overflow-x: auto; }
.events-table table { width: 100%; border-collapse: collapse; }
.events-table th, .events-table td { padding: 0.4rem 0.6rem; text-align: left; vertical-align: top; }
.events-table thead { background: #f9fafb; font-size: 0.78rem; text-transform: uppercase; color: #374151; }
.events-table tr { border-top: 1px solid #f3f4f6; }
.events-table a { color: #2563eb; text-decoration: none; }
.events-table a:hover { text-decoration: underline; }

.dev-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; background: #f9fafb; border-radius: 8px; padding: 0.85rem 1rem; margin-bottom: 1rem; }
.dev-summary > div div { font-weight: 500; }

.muted { color: #6b7280; font-size: 0.82rem; font-weight: 400; }
.hint { color: #6b7280; font-size: 0.88rem; margin-top: -0.25rem; }

.action-form { background: #f3f4f6; border-radius: 8px; padding: 0.85rem 1rem; margin-bottom: 1rem; }
.action-form h4 { margin: 0 0 0.5rem; }

.user-results { display: grid; gap: 0.35rem; margin-top: 0.4rem; }
.user-results button {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  width: 100%; padding: 0.45rem 0.6rem; border: 1px solid #d1d5db; border-radius: 6px;
  background: #fff; color: #111; cursor: pointer; text-align: left;
}
.user-results button:hover { background: #f9fafb; }
.user-results small { color: #6b7280; font-family: ui-monospace, SFMono-Regular, monospace; }
.user-result-empty, .selected-user { color: #6b7280; font-size: 0.86rem; margin-top: 0.35rem; }
.selected-user { color: #166534; }
