/* ============ Base ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --blue: #1428a0;
  --blue-dark: #0c1a6e;
  --blue-light: #eef1fb;
  --bg: #f4f6fa;
  --text: #1b2340;
  --muted: #6b7390;
  --border: #e2e6f0;
  --green: #0e9f6e;
  --green-bg: #e6f7f0;
  --orange: #c27803;
  --orange-bg: #fdf3e0;
  --red: #d13438;
  --red-bg: #fdeaea;
  --gray: #64748b;
  --gray-bg: #eef1f5;
  --purple: #7048d6;
  --purple-bg: #f0eafd;
  --radius: 14px;
  --shadow: 0 4px 18px rgba(20, 40, 160, 0.08);
}

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ============ Buttons ============ */
.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  padding: 11px 20px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }
.btn-block { width: 100%; }
.btn-ghost {
  background: transparent;
  color: var(--blue);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--blue-light); }

/* ============ Login ============ */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
}

.login-card {
  background: #fff;
  width: 100%;
  max-width: 400px;
  border-radius: 18px;
  padding: 36px 32px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.logo-mark {
  width: 52px;
  height: 52px;
  border-radius: 13px;
  background: var(--blue);
  color: #fff;
  font-size: 28px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.logo-mark.small { width: 34px; height: 34px; font-size: 18px; border-radius: 9px; }

.login-logo h1 { font-size: 24px; letter-spacing: 1px; }
.login-logo p { font-size: 13px; color: var(--muted); }

.login-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 14px 0 6px;
}

.login-card input {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-card input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(20, 40, 160, 0.12);
}

.login-error {
  margin-top: 14px;
  background: var(--red-bg);
  color: var(--red);
  font-size: 13.5px;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: 9px;
}

#login-btn { margin-top: 22px; }

.login-footnote {
  margin-top: 18px;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
}

/* ============ Top bar ============ */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left { display: flex; align-items: center; gap: 10px; }
.app-title { font-weight: 800; letter-spacing: 1px; font-size: 17px; }

.topbar-right { display: flex; align-items: center; gap: 12px; }

/* Connection status indicator */
.conn-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: #999; flex-shrink: 0; }
.conn-status.online .conn-dot { background: #22c55e; }
.conn-status.offline .conn-dot { background: #f59e0b; }
.conn-status.error .conn-dot { background: #ef4444; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
@media (max-width: 720px) { .conn-status .conn-text { display: none; } }

/* Return button */
.return-btn {
  background: var(--blue-light); color: var(--blue); border: 1px solid var(--blue);
  border-radius: 6px; padding: 4px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.return-btn:hover { background: var(--blue); color: #fff; }

/* Action badges for logsheet */
.badge-borrowed { background: #dbeafe; color: #2563eb; }
.badge-returned { background: #dcfce7; color: #16a34a; }
.col-action { white-space: nowrap; }

.user-chip {
  background: var(--blue-light);
  color: var(--blue);
  font-size: 13.5px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============ Layout ============ */
.container { max-width: 1080px; margin: 0 auto; padding: 28px 24px 60px; }

.greeting { font-size: 24px; font-weight: 700; }
.subtitle { color: var(--muted); font-size: 14.5px; margin-top: 4px; }

/* ============ Stat card ============ */
.stat-card {
  margin-top: 24px;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 28px;
  display: flex;
  align-items: center;
  gap: 20px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 26px rgba(20, 40, 160, 0.22); }
.stat-card:focus-visible { outline: 3px solid #9db2ff; outline-offset: 2px; }

.stat-icon { font-size: 34px; }
.stat-number { font-size: 42px; font-weight: 800; line-height: 1.1; display: block; }
.stat-label { font-size: 14px; opacity: 0.85; }
.stat-body { flex: 1; }
.stat-cta { font-size: 13.5px; font-weight: 600; background: rgba(255, 255, 255, 0.16); padding: 9px 16px; border-radius: 999px; white-space: nowrap; }

/* ============ Dashboard search ============ */
.dash-search { margin-top: 22px; }
.dash-search .search-input { width: 100%; min-width: 0; }

.dash-results { margin-top: 16px; }
.dash-results-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ============ Borrow ============ */
.borrow-btn {
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: #fff;
  background: var(--blue);
  border: none;
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.borrow-btn:hover { background: var(--blue-dark); }
.borrow-btn:focus-visible { outline: 3px solid #9db2ff; outline-offset: 2px; }

.device-card-actions { margin-top: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  background: #1f2430;
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 50;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============ Device list ============ */
.list-header {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.list-header h2 { font-size: 21px; }
.back-btn { padding: 8px 14px; }

.badge-soft {
  background: var(--blue-light);
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 12px;
  vertical-align: middle;
}

.toolbar { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

/* Search box + QR-scan icon (the icon opens the camera; the scanned value
   is put into the input and the search runs immediately). */
.search-wrap { position: relative; flex: 1; min-width: 220px; }
.search-wrap .search-input { width: 100%; min-width: 0; padding-right: 84px; }

.search-input {
  flex: 1;
  min-width: 220px;
  font: inherit;
  padding: 11px 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(20, 40, 160, 0.12); }

.qr-btn {
  position: absolute;
  top: 50%;
  right: 38px; /* leaves room for the native clear (✕) button of type=search */
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.qr-btn:hover { background: var(--blue-light); color: var(--blue); }
.qr-btn:focus-visible { outline: 3px solid #9db2ff; outline-offset: 1px; }

.status-select {
  font: inherit;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  outline: none;
  cursor: pointer;
}

/* Table (desktop) */
.table-wrap {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden; /* table-layout:fixed keeps the table inside the container — the Action column is never clipped and no horizontal scrollbar appears */
  -webkit-overflow-scrolling: touch;
}

.device-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  table-layout: fixed; /* columns follow the .col-* widths below; the table never overflows its container */
}
.device-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  background: #fafbfe;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.device-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
/* Keep short cells on one line so the table stays compact and rows stay even */
.td-mono, .td-nowrap { white-space: nowrap; }
/* Action cell: allow buttons to wrap so "Return Now" + "Cancel" always fit
   inside the column without clipping or horizontal scrollbar. */
.td-action { display: flex; flex-wrap: wrap; gap: 4px; }
.td-action .btn { padding: 7px 12px; font-size: 13px; }
.device-table tbody tr:last-child td { border-bottom: none; }
.device-table tbody tr:hover { background: #f7f9ff; }
.td-mono { font-family: Consolas, Menlo, monospace; font-size: 13px; }
.td-name { font-weight: 600; }
.td-muted { color: var(--muted); }
.td-sub { font-size: 11px; opacity: 0.75; margin-left: 4px; }

/* Fixed-layout column widths (set on the <th> of every table; the matching
   class on each <td> is only used to hide low-priority columns on narrow
   screens). */
.col-mn { width: 18%; }
.col-mc { width: 12%; }
.col-imei { width: 13%; }
.col-hw { width: 7%; }
.col-year { width: 5.5%; }
.col-dr { width: 11%; }
.col-status { width: 10%; }
.col-owner { width: 10%; }
.col-remarks { width: 10%; }
.col-borrowed { width: 13.5%; }
.col-ts { width: 15%; }
.col-from, .col-to { width: 12%; }
/* Action column: fixed pixel width so the Borrow button always fits fully */
.col-action { width: 96px; }

/* Long text cells: single line, clipped with an ellipsis.
   The full value is shown on hover via the cell's title attribute. */
.td-clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Narrower viewports: drop low-priority columns and tighten the padding so
   the remaining ones (especially Action/Borrow) always keep enough room —
   no scrollbar needed. */
@media (max-width: 1020px) {
  .col-hw { display: none; }
  .device-table th, .device-table td { padding: 10px 10px; }
}
@media (max-width: 880px) {
  .col-year, .col-remarks { display: none; }
  .device-table th, .device-table td { padding: 9px 8px; }
  .col-action { width: 88px; }
}

/* Status badges */
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 11px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-available { background: var(--green-bg); color: var(--green); }
.badge-borrowed { background: var(--orange-bg); color: var(--orange); }
.badge-in-use { background: var(--blue-light); color: var(--blue); }
.badge-defective { background: var(--red-bg); color: var(--red); }
.badge-disposed, .badge-deleted { background: var(--gray-bg); color: var(--gray); }
.badge-duplicated { background: var(--purple-bg); color: var(--purple); }

/* Mobile cards */
.card-list { display: none; }

.device-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.device-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.device-card-name { font-weight: 700; font-size: 15.5px; }
.device-card-model { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.device-card-imei {
  font-family: Consolas, Menlo, monospace;
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 10px;
}
.device-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--muted);
}
.device-card-remarks {
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 10px;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-icon { font-size: 34px; display: block; margin-bottom: 8px; }

/* ============ Master logsheet ============ */
.logsheet { margin-top: 28px; }
.logsheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.logsheet-header h3 { font-size: 17px; cursor: pointer; user-select: none; }
.logsheet-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.log-toggle-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); }
#log-csv-mode { font-size: 13px; padding: 8px 10px; }
.log-empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 12px;
  font-size: 14px;
}

.log-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.log-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-weight: 700;
  font-size: 14.5px;
}
.log-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--muted);
}
.log-card-owner {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
}

/* ============ QR scanner modal ============ */
.qr-modal {
  position: fixed;
  inset: 0;
  background: rgba(13, 18, 43, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.qr-panel {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 420px;
  padding: 18px 18px 16px;
}
.qr-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.qr-head h3 { font-size: 17px; }
.qr-head .btn { padding: 7px 14px; font-size: 13px; }
.qr-video-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #0b0e1a;
  aspect-ratio: 4 / 3;
}
.qr-video-wrap video { display: block; width: 100%; height: 100%; object-fit: cover; }
.qr-frame {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 60%;
  max-width: 230px;
  aspect-ratio: 1 / 1;
  border: 3px solid rgba(255, 255, 255, 0.92);
  border-radius: 16px;
  box-shadow: 0 0 0 9999px rgba(8, 10, 25, 0.35); /* dims everything outside the frame */
  pointer-events: none;
}
.qr-hint {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.qr-hint-error { color: var(--red); font-weight: 600; }
.qr-actions {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}

/* ============ Return sections ============ */
.return-section { margin-top: 24px; }
.return-section-header { margin-bottom: 12px; }
.return-section-header h3 { font-size: 17px; margin-bottom: 4px; }
.return-section-sub { font-size: 13px; color: var(--muted); }

.return-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.return-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-weight: 700;
  font-size: 14.5px;
}
.return-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--muted);
}
.return-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn-accept { background: var(--green); color: #fff; }
.btn-accept:hover { filter: brightness(1.1); }
.btn-reject { background: var(--red); color: #fff; }
.btn-reject:hover { filter: brightness(1.1); }
.btn-return-now { background: var(--purple); color: #fff; }
.btn-return-now:hover { filter: brightness(1.1); }
.btn-return-now:disabled { opacity: 0.6; cursor: default; }
.btn-cancel-return { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-cancel-return:hover { background: var(--gray-bg); }

.email-sent-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--green);
  background: var(--green-bg);
  padding: 2px 8px;
  border-radius: 6px;
  margin-left: 6px;
}

/* ============ Responsive ============ */
@media (max-width: 720px) {
  .container { padding: 20px 16px 50px; }
  .topbar { padding: 10px 16px; }
  .user-chip { max-width: 110px; }

  .greeting { font-size: 20px; }

  .stat-card { padding: 20px; gap: 14px; flex-wrap: wrap; }
  .stat-number { font-size: 34px; }
  .stat-cta { display: none; }

  .table-wrap { display: none; }
  .card-list { display: block; }

  .toolbar { flex-direction: column; }
  .search-wrap, .search-input, .status-select { width: 100%; }
  .list-header h2 { font-size: 18px; }
}

