:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #059669;
  --warning: #d97706;
  --info: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

.startup-update {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(17, 24, 39, 0.45);
  backdrop-filter: blur(1px);
}

.startup-update-card {
  min-width: min(420px, 92vw);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 8px 12px;
  align-items: center;
}

.startup-update-spinner {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid rgba(37, 99, 235, 0.25);
  border-top-color: var(--primary);
  animation: startup-spin 0.8s linear infinite;
}

.startup-update-sub {
  grid-column: 2;
  font-size: 13px;
  color: var(--muted);
}

@keyframes startup-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.small {
  font-size: 12px;
}

/* ===== Topbar ===== */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1024px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
}
.brand-mark {
  font-size: 22px;
}
.user-box {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-email {
  color: var(--muted);
  font-size: 14px;
}

.pwa-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  margin-right: 16px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pwa-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--muted);
  display: inline-block;
  box-shadow: 0 0 0 4px rgba(107, 114, 128, 0.08);
}
.pwa-status.is-online {
  color: var(--success);
}
.pwa-status.is-online .pwa-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.12);
}
.pwa-status.is-offline {
  color: var(--danger);
}
.pwa-status.is-offline .pwa-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.12);
}

.offline-banner {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  background: #fef2f2;
  color: #991b1b;
  font-size: 14px;
  font-weight: 600;
}

/* ===== Layout ===== */
.container {
  max-width: 1024px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 780px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-title {
  margin: 0 0 4px;
  font-size: 18px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-head-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dashboard-cache-meta {
  margin: 0 0 10px;
}

.dashboard-cache-meta,
.admin-cache-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  width: fit-content;
  border: 1px solid var(--border);
  background: #f9fafb;
}

.dashboard-cache-meta::before,
.admin-cache-meta::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--muted);
  box-shadow: 0 0 0 4px rgba(107, 114, 128, 0.08);
}

.dashboard-cache-meta.is-live,
.admin-cache-meta.is-live {
  color: var(--success);
  border-color: rgba(5, 150, 105, 0.2);
  background: #ecfdf5;
}

.dashboard-cache-meta.is-live::before,
.admin-cache-meta.is-live::before {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.12);
}

.dashboard-cache-meta.is-cache,
.admin-cache-meta.is-cache {
  color: #b45309;
  border-color: rgba(217, 119, 6, 0.22);
  background: #fffbeb;
}

.dashboard-cache-meta.is-cache::before,
.admin-cache-meta.is-cache::before {
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(217, 119, 6, 0.12);
}

.dashboard-cache-meta.is-empty,
.admin-cache-meta.is-empty {
  color: var(--muted);
}

/* ===== Auth ===== */
.auth-view {
  display: flex;
  justify-content: center;
  padding-top: 24px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 420px;
}
.auth-title {
  margin: 0 0 4px;
  font-size: 22px;
}
.tabs {
  display: flex;
  gap: 4px;
  margin: 16px 0;
  background: #f3f4f6;
  padding: 4px;
  border-radius: 8px;
}
.tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  font-size: 14px;
}
.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ===== Form ===== */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 14px;
}
.field > span {
  font-weight: 600;
  color: var(--text);
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  font-family: inherit;
}
input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
input:disabled,
select:disabled {
  background: #f9fafb;
  color: var(--muted);
}
.inline {
  display: flex;
  gap: 8px;
}
.inline input {
  flex: 1;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: #f3f4f6;
}
.btn-sm {
  padding: 6px 10px;
  font-size: 13px;
}
.btn-block {
  width: 100%;
}
.btn.is-loading {
  opacity: 0.7;
  pointer-events: none;
}

/* ===== Alerts ===== */
.alert {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  border: 1px solid var(--border);
  background: #f9fafb;
}
.alert.is-error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}
.alert.is-success {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
}
.alert.is-info {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

/* ===== Dropzone ===== */
.dropzone {
  display: block;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 12px;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--primary);
  background: #eff6ff;
}
.dropzone-icon {
  font-size: 28px;
  margin-bottom: 6px;
}
.dropzone-inner {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

/* ===== Jobs list ===== */
.jobs-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.job-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}
.job-info {
  min-width: 0;
  flex: 1;
}
.job-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.job-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}
.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
  font-size: 14px;
}

/* ===== Status badge ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge.queued {
  background: #f3f4f6;
  color: #4b5563;
}
.badge.printing {
  background: #dbeafe;
  color: #1d4ed8;
}
.badge.done {
  background: #d1fae5;
  color: #065f46;
}
.badge.failed {
  background: #fee2e2;
  color: #991b1b;
}

/* ===== Poll indicator ===== */
.poll-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ===== Settings ===== */
.settings summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}
.settings[open] summary {
  margin-bottom: 12px;
  color: var(--text);
}

/* ===== Role badge ===== */
.role-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
  text-transform: uppercase;
}

/* ===== Admin view ===== */
.admin-view {
  margin-top: 4px;
}
.admin-cache-meta {
  margin: 0 0 10px;
}
.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
}
.admin-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  transition: color 0.15s;
  font-family: inherit;
}
.admin-tab:hover { color: var(--text); background: #f9fafb; }
.admin-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: transparent;
}
.admin-panel { display: block; }
.admin-panel.hidden { display: none; }

/* ===== Stats grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 780px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.1;
}
.stat-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* Status bar */
.status-bar-wrap {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
}

/* ===== Admin tables ===== */
.admin-table-wrap {
  overflow-x: auto;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.admin-table th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.admin-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: #f9fafb; }

.filter-select {
  width: auto;
  padding: 6px 10px;
  font-size: 13px;
}

/* Online indicator */
.dot-online { color: var(--success); }
.dot-offline { color: var(--muted); }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.modal-title {
  margin: 0 0 16px;
  font-size: 18px;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}
