* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f4f5f7;
  color: #1a1a2e;
}

/* Login */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: #1a1a2e;
}
.login-card {
  background: #fff;
  padding: 32px;
  border-radius: 12px;
  width: 320px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.login-card h1 { font-size: 20px; margin: 0 0 20px; text-align: center; }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.login-card input {
  width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 8px; font-size: 15px;
}
.login-card button {
  margin-top: 20px; width: 100%; padding: 12px; border: none; border-radius: 8px;
  background: #1a1a2e; color: #fff; font-weight: 600; font-size: 15px; cursor: pointer;
}
.login-card button:hover { background: #2a2a4a; }

.install-buttons { display: flex; gap: 10px; margin-top: 16px; width: 320px; }
.install-btn {
  flex: 1; padding: 10px; border: 1px solid rgba(255,255,255,0.3); border-radius: 8px;
  background: transparent; color: #fff; font-weight: 600; font-size: 13px; cursor: pointer;
}
.install-btn:hover { background: rgba(255,255,255,0.1); }
.install-note { margin-top: 10px; width: 320px; color: #c9c9d8; font-size: 12px; text-align: center; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: #1a1a2e; color: #fff;
  display: flex; flex-direction: column; padding: 20px 0; flex-shrink: 0;
}
.brand { font-size: 18px; font-weight: 700; padding: 0 20px 20px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  color: #c9c9d8; text-decoration: none; padding: 12px 20px; font-size: 14px; font-weight: 500;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,0.12); color: #fff; border-left: 3px solid #4caf50; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.1); }
.user-name { font-size: 13px; color: #c9c9d8; margin-bottom: 8px; }
.link-button {
  background: none; border: none; color: #ff8080; padding: 0; font-size: 13px;
  font-weight: 600; cursor: pointer;
}

.content { flex: 1; padding: 32px 40px; max-width: 900px; }
.content h1 { margin-top: 0; font-size: 22px; }

/* Flash */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash-success { background: #e6f6ea; color: #0a7d32; }
.flash-error { background: #fdeaea; color: #c62828; }

/* Dashboard cards */
.cards { display: flex; gap: 16px; margin-top: 20px; }
.stat-card {
  background: #fff; border-radius: 12px; padding: 20px 28px; text-decoration: none;
  color: inherit; box-shadow: 0 1px 3px rgba(0,0,0,0.08); min-width: 140px;
}
.stat-number { font-size: 28px; font-weight: 700; }
.stat-label { font-size: 13px; color: #666; margin-top: 4px; }

/* Forms */
.panel-form {
  background: #fff; padding: 20px; border-radius: 12px; margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.form-row { display: flex; gap: 16px; margin-bottom: 4px; }
.form-row > div { flex: 1; }
.panel-form label { display: block; font-size: 13px; font-weight: 600; margin: 8px 0 4px; }
.panel-form input, .panel-form select {
  width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 8px; font-size: 14px;
}
.panel-form button {
  margin-top: 16px; padding: 10px 20px; border: none; border-radius: 8px;
  background: #1a1a2e; color: #fff; font-weight: 600; cursor: pointer;
}
.panel-form button:hover { background: #2a2a4a; }

/* Table */
.data-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.data-table th, .data-table td { text-align: left; padding: 12px 16px; font-size: 14px; border-bottom: 1px solid #eee; }
.data-table th { background: #fafafa; font-weight: 600; color: #555; }
.data-table .empty { text-align: center; color: #999; padding: 24px; }
.data-table form { margin: 0; }
.link-button-danger { color: #c62828; }
.link-button-danger:hover { text-decoration: underline; }
.transfer-form { display: flex; gap: 6px; align-items: center; }
.transfer-form select { padding: 6px 8px; border: 1px solid #ccc; border-radius: 6px; font-size: 13px; }
.transfer-form input[type="number"] { width: 60px; padding: 6px 8px; border: 1px solid #ccc; border-radius: 6px; font-size: 13px; }
.transfer-form button {
  padding: 6px 12px; border: none; border-radius: 6px; background: #1a1a2e; color: #fff;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.transfer-form button:hover { background: #2a2a4a; }
.empty-inline { font-size: 12px; color: #999; }
.row-actions { display: flex; gap: 12px; align-items: center; }
.row-actions a.link-button { color: #1a1a2e; text-decoration: none; font-weight: 600; font-size: 13px; }
.row-actions a.link-button:hover { text-decoration: underline; }
.cancel-link { margin-left: 12px; font-size: 13px; color: #666; text-decoration: none; }
.cancel-link:hover { text-decoration: underline; }

/* Reports */
.report-tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.report-tab {
  padding: 8px 16px; border-radius: 100px; font-size: 13px; font-weight: 600;
  background: #fff; color: #555; text-decoration: none; border: 1px solid #ddd;
}
.report-tab:hover { border-color: #1a1a2e; color: #1a1a2e; }
.report-tab.active { background: #1a1a2e; color: #fff; border-color: #1a1a2e; }
.filter-form { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; }
.filter-form label { font-size: 13px; font-weight: 600; color: #555; }
.filter-form select { padding: 8px 12px; border: 1px solid #ccc; border-radius: 8px; font-size: 13px; }
.chart-card {
  background: #fcfcfb; border-radius: 12px; padding: 20px; margin: 16px 0 28px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.chart-title { font-size: 14px; font-weight: 700; color: #0b0b0b; margin: 0 0 16px; }
.chart-wrap { position: relative; height: 260px; }

/* Search */
.search-result-card {
  background: #fff; border-radius: 12px; padding: 20px; margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.search-result-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.search-result-name { font-size: 17px; font-weight: 700; }
.search-result-sub { font-size: 13px; color: #666; margin-top: 2px; }
.search-result-price { font-size: 18px; font-weight: 700; color: #0a7d32; }

/* Notifications */
.notification-unread { background: #f0f6ff; font-weight: 600; }

/* Worker panel (mobile-first, no sidebar) */
.worker-body { max-width: 480px; margin: 0 auto; }
.worker-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; background: #1a1a2e; color: #fff; position: sticky; top: 0; z-index: 10;
}
.worker-brand { font-weight: 700; font-size: 16px; }
.worker-header-right { display: flex; align-items: center; gap: 12px; }
.worker-name { font-size: 13px; color: #c9c9d8; }
.worker-header .link-button { color: #ff8080; font-size: 13px; font-weight: 600; }
.worker-tabs { display: flex; background: #fff; border-bottom: 1px solid #eee; position: sticky; top: 49px; z-index: 9; }
.worker-tab { flex: 1; text-align: center; padding: 12px; font-size: 13px; font-weight: 600; color: #666; text-decoration: none; }
.worker-tab.active { color: #1a1a2e; border-bottom: 2px solid #1a1a2e; }
.worker-content { padding: 16px; }
.worker-content h1 { font-size: 19px; margin-top: 0; }

.scan-card {
  background: #fff; border-radius: 12px; padding: 16px; margin-bottom: 16px;
  text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.scan-card button { width: 100%; padding: 12px; background: #1a1a2e; color: #fff; border: none; border-radius: 8px; font-weight: 600; }
#scan-video { width: 100%; border-radius: 8px; margin-bottom: 10px; display: none; background: #000; }
#scan-canvas { display: none; }
#scan-status { margin-top: 8px; word-break: break-all; }
.report-tab.export-tab { margin-left: auto; background: #0a7d32; color: #fff; border-color: #0a7d32; }
.report-tab.export-tab:hover { background: #086024; color: #fff; }

/* Exact-day calendar filter (worker reports) */
.date-filter { display: flex; align-items: center; gap: 10px; margin: 0 0 20px; flex-wrap: wrap; }
.date-filter-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
  font-weight: 600; color: #555; cursor: pointer; }
.date-filter-label.active { color: #0a7d32; }
.date-filter-icon { flex: none; }
.date-filter input[type="date"] { padding: 8px 12px; border: 1px solid #ccc; border-radius: 8px;
  font-size: 13px; color: #1a1a2e; background: #fff; cursor: pointer; }
.date-filter input[type="date"]:focus { outline: none; border-color: #0a7d32; }
.date-filter-clear { font-size: 13px; color: #b0203a; text-decoration: none; }
.date-filter-clear:hover { text-decoration: underline; }
.section-title { font-size: 16px; margin: 28px 0 12px; }

/* QR Code Generator */
.form-note { font-size: 12px; color: #888; margin: 10px 0 0; }
.qr-print-area { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin: 20px 0; }
.qr-box {
  background: #fff; border: 1px solid #eee; border-radius: 12px; padding: 20px 28px;
  text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.qr-canvas { display: inline-block; }
.qr-label-id { font-family: monospace; font-size: 13px; font-weight: 700; letter-spacing: 1px; color: #1a1a2e; margin-bottom: 6px; }
.qr-label-name { font-weight: 700; font-size: 15px; margin-top: 10px; }
.qr-label-sub { font-size: 13px; color: #666; margin-top: 2px; }

/* Quick templates */
.templates-box { margin-bottom: 16px; }
.templates-hint { font-size: 12px; color: #888; margin-bottom: 8px; }
.templates-empty { font-size: 13px; color: #999; }
.templates-list { display: flex; flex-wrap: wrap; gap: 8px; }
.template-chip {
  display: inline-flex; align-items: stretch; background: #fff; border: 1px solid #ddd;
  border-radius: 100px; overflow: hidden;
}
.template-fill {
  border: none; background: none; padding: 8px 14px; font-size: 13px; font-weight: 600;
  color: #1a1a2e; cursor: pointer;
}
.template-fill:hover { background: #f2f2f7; }
.template-delete-form { margin: 0; display: flex; }
.template-delete {
  border: none; border-left: 1px solid #eee; background: none; padding: 8px 12px;
  color: #c62828; font-weight: 700; cursor: pointer; font-size: 14px; line-height: 1;
}
.template-delete:hover { background: #fdeaea; }

/* Responsive: this system runs mostly on phones, so treat the phone layout as the
   primary target (wide breakpoint) rather than a narrow fallback for desktop. */
@media (max-width: 900px) {
  .login-card, .install-buttons, .install-note { width: 90vw; max-width: 320px; }

  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; flex-direction: row; align-items: center;
    padding: 8px 12px; overflow-x: auto; white-space: nowrap;
  }
  .brand { padding: 0 12px 0 0; }
  .sidebar nav { flex-direction: row; flex: none; gap: 2px; }
  .sidebar nav a { padding: 10px 12px; white-space: nowrap; border-radius: 8px; }
  .sidebar-footer { margin-left: auto; padding: 0 0 0 12px; border: none; display: flex; align-items: center; gap: 10px; }
  .user-name { margin-bottom: 0; }

  .content { padding: 14px; max-width: 100%; }
  .content h1 { font-size: 19px; }
  .cards { flex-wrap: wrap; gap: 10px; }
  .stat-card { flex: 1 1 calc(50% - 5px); min-width: 0; padding: 16px; }

  .form-row { flex-direction: column; gap: 0; }

  /* Inputs/selects at 16px prevent iOS Safari's auto-zoom-on-focus */
  .panel-form input, .panel-form select, .login-card input,
  .transfer-form select, .transfer-form input[type="number"],
  .date-filter input[type="date"],
  .filter-form select { font-size: 16px; }

  /* Comfortable tap targets (Apple HIG / Material minimum ~44px) */
  .panel-form button, .login-card button, .report-tab, .data-table .link-button,
  .row-actions a.link-button, .transfer-form button { min-height: 40px; }

  .data-table { display: block; overflow-x: auto; white-space: nowrap; }
  .data-table thead, .data-table tbody, .data-table tr { display: table; width: 100%; table-layout: fixed; }

  .search-result-head { flex-direction: column; gap: 6px; }
  .transfer-form { flex-wrap: wrap; }
}

@media (max-width: 420px) {
  .stat-card { flex-basis: 100%; }
  .content { padding: 12px; }
  .qr-box { padding: 14px 18px; }
}

@media print {
  .sidebar, .panel-form, .data-table, .section-title, h1, .flash, .no-print, .templates-box { display: none !important; }
  .content { padding: 0; margin: 0; }
  .qr-print-area {
    display: flex; flex-wrap: wrap; justify-content: flex-start; align-items: flex-start;
    gap: 6px; margin: 0; padding: 0;
  }
  .qr-box {
    border: none; box-shadow: none; border-radius: 0; padding: 6px 10px;
    page-break-inside: avoid;
  }
}
