:root {
  --yellow: #F1C40F;
  --yellow-dark: #D4AC0D;
  --yellow-light: #FCF3CF;
  --yellow-bg: #FFF9E6;
  --black: #1a1a1a;
  --gray: #4a4a4a;
  --light-gray: #f5f5f5;
  --border: #ddd;
  --danger: #e74c3c;
  --success: #27ae60;
  --warn: #e67e22;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f0f0f0;
  color: var(--black);
  line-height: 1.4;
  overscroll-behavior: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  background: #fff;
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 20px rgba(0,0,0,0.08);
}

/* Header */
.app-header {
  background: var(--yellow);
  color: var(--black);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 3px solid var(--black);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark {
  background: var(--black);
  color: var(--yellow);
  font-weight: 800;
  font-size: 18px;
  padding: 6px 10px;
  border-radius: 6px;
  letter-spacing: -0.5px;
}

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.logo-text strong {
  font-size: 16px;
}

.logo-text span {
  font-size: 11px;
  opacity: 0.8;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 22px;
  padding: 4px 8px;
  cursor: pointer;
}

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(8px + var(--safe-bottom));
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

.nav-btn {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--gray);
  padding: 4px 12px;
  position: relative;
  cursor: pointer;
}

.nav-btn.active {
  color: var(--black);
  font-weight: 600;
}

.nav-btn.active .nav-icon {
  transform: scale(1.15);
}

.nav-icon {
  font-size: 20px;
  transition: transform 0.15s;
}

.badge {
  position: absolute;
  top: -2px;
  right: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* Main content */
#main-content {
  flex: 1;
  padding: 16px 16px 90px;
  overflow-y: auto;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-header {
  margin-bottom: 16px;
}

.view-header h1 {
  font-size: 22px;
  font-weight: 700;
}

.subtitle {
  font-size: 13px;
  color: var(--gray);
  margin-top: 2px;
}

/* Stats */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--yellow-light);
  border: 1px solid var(--yellow);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
}

.stat-card.warn {
  background: #fef5e7;
  border-color: var(--warn);
}

.stat-card.danger {
  background: #fdedec;
  border-color: var(--danger);
}

.stat-num {
  display: block;
  font-size: 24px;
  font-weight: 800;
}

.stat-label {
  font-size: 11px;
  color: var(--gray);
}

/* Search */
.search-bar {
  margin-bottom: 12px;
}

.search-bar input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--light-gray);
}

/* Cert list */
.cert-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cert-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
}

.cert-card:active {
  background: #fafafa;
}

.cert-card.due-soon {
  border-left: 4px solid var(--warn);
}

.cert-card.overdue {
  border-left: 4px solid var(--danger);
}

.cert-card .serial {
  font-weight: 700;
  font-size: 14px;
  color: var(--black);
}

.cert-card .address {
  font-size: 13px;
  color: var(--gray);
  margin: 4px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cert-card .meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--gray);
  margin-top: 6px;
}

.cert-card .status {
  font-weight: 600;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: #e8f8f0;
  color: var(--success);
}

.cert-card .status.warn {
  background: #fef5e7;
  color: var(--warn);
}

.cert-card .status.danger {
  background: #fdedec;
  color: var(--danger);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state h3 {
  color: var(--black);
  margin-bottom: 6px;
}

/* Forms */
.form-step {
  display: none;
}

.form-step.active {
  display: block;
}

.form-step h2 {
  font-size: 18px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--yellow);
}

.form-step h3 {
  font-size: 15px;
  margin: 18px 0 10px;
  color: var(--gray);
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--gray);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px; /* prevents zoom on iOS */
  background: #fff;
  -webkit-appearance: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--yellow-dark);
  box-shadow: 0 0 0 3px rgba(241, 196, 15, 0.25);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.radio-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
  font-size: 14px;
  color: var(--black);
  cursor: pointer;
}

.check-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.check-item {
  background: var(--yellow-bg);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--yellow);
}

.check-item label {
  font-size: 13px;
  margin-bottom: 0;
}

.form-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
  gap: 12px;
}

.btn {
  padding: 13px 20px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
  flex: 1;
  text-align: center;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--yellow);
  color: var(--black);
  border: 2px solid var(--black);
}

.btn.secondary {
  background: #fff;
  color: var(--black);
  border: 1px solid var(--border);
}

.btn.outline {
  background: #fff;
  border: 2px solid var(--yellow-dark);
  color: var(--black);
  margin-bottom: 10px;
  width: 100%;
}

.btn.danger {
  background: #fff;
  border: 1px solid var(--danger);
  color: var(--danger);
  width: 100%;
  margin-top: 8px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Step indicator */
.step-indicator {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.step {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #eee;
  color: var(--gray);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}

.step.active {
  background: var(--yellow);
  color: var(--black);
  border: 2px solid var(--black);
}

.step.done {
  background: var(--success);
  color: #fff;
}

/* Appliance card */
.appliance-card {
  background: var(--yellow-bg);
  border: 1px solid var(--yellow);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  position: relative;
}

.appliance-card h4 {
  font-size: 14px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
}

.appliance-card .remove-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 18px;
  cursor: pointer;
}

.hint {
  font-size: 13px;
  color: var(--gray);
  margin-bottom: 12px;
}

/* Settings */
.settings-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.settings-card h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

.small {
  font-size: 12px;
  color: var(--gray);
  margin-top: 8px;
}

/* Sheet / Modal */
.sheet {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  background: #fff;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 30px rgba(0,0,0,0.15);
  z-index: 200;
  overflow-y: auto;
  padding-bottom: calc(20px + var(--safe-bottom));
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: #ccc;
  border-radius: 2px;
  margin: 10px auto;
}

.sheet-content {
  padding: 0 16px 16px;
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--black);
  color: #fff;
  padding: 12px 20px;
  border-radius: 30px;
  font-size: 14px;
  z-index: 300;
  max-width: 90%;
  text-align: center;
  animation: toastIn 0.25s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Utility */
[hidden] {
  display: none !important;
}

/* Safe to use coloured buttons */
.safe-to-use-group {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.safe-btn {
  flex: 1;
  text-align: center;
  padding: 12px 8px;
  border-radius: 10px;
  border: 2px solid #ccc;
  background: #f5f5f5;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s;
  color: #555;
}

.safe-btn input {
  display: none;
}

.safe-btn.yes.selected {
  background: #27ae60;
  border-color: #1e8449;
  color: #fff;
}

.safe-btn.no.selected {
  background: #e74c3c;
  border-color: #c0392b;
  color: #fff;
}

.safe-btn.na.selected {
  background: #7f8c8d;
  border-color: #5d6d6e;
  color: #fff;
}

.safe-btn.yes:not(.selected):active,
.safe-btn.yes:not(.selected):hover {
  border-color: #27ae60;
  background: #e8f8f0;
}

.safe-btn.no:not(.selected):active,
.safe-btn.no:not(.selected):hover {
  border-color: #e74c3c;
  background: #fdedec;
}

/* Signature pad */
.signature-pad-wrap {
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  touch-action: none;
}

#signature-canvas {
  width: 100%;
  height: 160px;
  display: block;
  background: #fafafa;
}

.sig-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.sig-preview {
  margin-top: 12px;
  text-align: center;
}

.sig-preview img {
  max-width: 100%;
  max-height: 80px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
