:root {
  /* Safaricom Brand Colors */
  --saf-green: #00a650;
  --saf-green-dark: #008c44;
  --saf-green-light: #4fc47f;
  --saf-red: #e60000;
  --saf-red-dark: #cc0000;
  
  /* Light theme with Safaricom feel */
  --bg: #f5f7fa;
  --bg-gradient: linear-gradient(135deg, #ffffff 0%, #f0f4f8 50%, #e8f5e9 100%);
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --border: #e0e6ed;
  --border-light: #f0f2f5;
  --text: #1a1a1a;
  --text-secondary: #4a5568;
  --muted: #718096;
  --accent: var(--saf-green);
  --accent-dim: var(--saf-green-dark);
  --accent-light: rgba(0, 166, 80, 0.1);
  --danger: var(--saf-red);
  --danger-light: rgba(230, 0, 0, 0.08);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

#app {
  max-width: 420px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 1.25rem 1rem 2.5rem;
  display: flex;
  flex-direction: column;
}

.brand {
  text-align: center;
  margin-bottom: 1.5rem;
  padding-top: 0.5rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.brand p {
  margin: 0.4rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

input[type="text"],
input[type="password"],
input[type="tel"] {
  width: 100%;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

.field {
  margin-bottom: 1rem;
}

.field:last-child {
  margin-bottom: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.95rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--saf-green) 0%, var(--saf-green-dark) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 166, 80, 0.3);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-primary:not(:disabled):hover {
  box-shadow: 0 4px 16px rgba(0, 166, 80, 0.4);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border-light);
  border-color: var(--muted);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  width: auto;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.btn-ghost:hover {
  color: var(--danger);
}

.btn-danger {
  background: linear-gradient(135deg, var(--saf-red) 0%, var(--saf-red-dark) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(230, 0, 0, 0.25);
}

.btn-danger:not(:disabled):hover {
  box-shadow: 0 4px 16px rgba(230, 0, 0, 0.35);
}

.row-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
}

.msg {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  font-weight: 500;
}

.msg-error {
  background: var(--danger-light);
  border: 1px solid rgba(230, 0, 0, 0.2);
  color: var(--danger);
}

.msg-success {
  background: var(--accent-light);
  border: 1px solid rgba(0, 166, 80, 0.2);
  color: var(--saf-green-dark);
}

.hidden {
  display: none !important;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  background: var(--surface);
  padding: 0.35rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.tab {
  flex: 1;
  padding: 0.75rem;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.tab:hover:not(.active) {
  background: var(--bg);
}

.tab.active {
  background: linear-gradient(135deg, var(--saf-green) 0%, var(--saf-green-dark) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 166, 80, 0.25);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.history-item {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-light);
}

.history-item:last-child {
  border-bottom: none;
}

.history-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.history-content {
  flex: 1;
  min-width: 0;
}

.history-serial {
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  word-break: break-all;
  color: var(--text);
}

.history-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.3rem;
}

.btn-delete {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  border-radius: 8px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-delete:hover {
  background: var(--danger-light);
  border-color: var(--danger);
  color: var(--danger);
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0;
}

.top-bar span {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#scanModal,
#pinSetupModal,
#deleteModal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  align-items: center;
  justify-content: center;
}

#scanModal .inner,
#pinSetupModal .inner,
#deleteModal .inner {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-lg);
}

#qrReader {
  width: 100%;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  min-height: 200px;
}

.loader {
  text-align: center;
  color: var(--muted);
  padding: 1rem;
  font-size: 0.9rem;
}

footer.note {
  margin-top: auto;
  padding-top: 2rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

footer.note a {
  font-weight: 600;
}

.serial-input {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.history-month {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  padding: 0.5rem 0;
  margin-bottom: 0.5rem;
  border-bottom: 2px solid var(--accent-light);
}

.history-count {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  padding: 0.75rem 0;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-top: 0.5rem;
}

/* Safaricom accent strip */
.brand::before {
  content: "";
  display: block;
  width: 50px;
  height: 4px;
  background: linear-gradient(90deg, var(--saf-green), var(--saf-green-light));
  border-radius: 2px;
  margin: 0 auto 1rem;
}
