:root {
  --bg: #f7f8fb;
  --card: #ffffff;
  --muted: #6b7280;
  --accent: #ef4444;
  --accent-600: #dc2626;
  --primary: #162038;
  --glass: rgba(15, 23, 42, 0.04);
  --radius: 12px;
  --shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
  --transition: 200ms ease;
  --focus: rgba(239, 68, 68, 0.18);
  --max-width: 1100px;
}

/* Reset & base */
* {
  box-sizing: border-box
}

html,
body {
  height: 100%
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  background: var(--bg);
  color: var(--primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.4;
  padding-bottom: 40px;
  /* keep global transitions off for instant theme switch */
  transition: none;
}

/* Screen-reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0
}

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  gap: 12px;
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.06), transparent);
  border-bottom: 1px solid rgba(15, 23, 42, 0.04);
}

.brand h1 {
  margin: 0;
  font-size: 1.1rem
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center
}

/* Emergency button */
.emergency-btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(239, 68, 68, 0.18);
  transition: transform var(--transition), box-shadow var(--transition);
  min-height: 44px;
}

.emergency-btn:active {
  transform: scale(.98)
}

.emergency-btn:hover {
  box-shadow: 0 10px 28px rgba(239, 68, 68, 0.22)
}

/* Layout */
.container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 16px;
  max-width: var(--max-width);
  margin: 16px auto;
}

/* Panels */
.left-panel,
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* ensure panels stretch to full width of their grid cell */
  align-items: stretch;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  color: var(--primary);
  /* ensure card text uses primary color */
}

/* Form */
.form-card h2 {
  margin: 0 0 8px 0;
  font-size: 1rem
}

label {
  display: block;
  margin-bottom: 8px;
  color: var(--primary)
}

label.inline {
  display: flex;
  align-items: center;
  gap: 8px
}

.label-text {
  display: block;
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 6px
}

input[type="text"],
input[type="tel"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  background: transparent;
  outline: none;
  transition: box-shadow var(--transition), border-color var(--transition);
  color: var(--primary);
  /* ensure input text is visible in dark mode */
}

input::placeholder,
textarea::placeholder {
  color: rgba(15, 23, 42, 0.35);
}

input:focus,
textarea:focus,
select:focus {
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.06);
  border-color: rgba(15, 23, 42, 0.12)
}

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

.btn {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  background: transparent;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 44px;
  color: var(--primary)
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent)
}

.btn.ghost {
  background: transparent
}

.icon-btn {
  background: transparent;
  border: 0;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
  color: var(--primary)
}

/* Controls */
.controls {
  display: flex;
  gap: 8px;
  align-items: center
}

.controls input {
  flex: 1
}

.controls select {
  width: 150px
}

/* Cards grid */
.cards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 8px;
  width: 100%;
}

/* Ensure each card fills its grid cell so layout looks centered and consistent */
.cards-grid>.card {
  width: 100%;
  box-sizing: border-box;
}

/* Contact card */
.contact-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 42, 0.04);
  background: var(--card);
  color: var(--primary);
}

.contact-info {
  flex: 1
}

.contact-name {
  font-weight: 700;
  color: var(--primary)
}

.contact-meta {
  font-size: .9rem;
  color: var(--muted);
  margin-top: 6px
}

.card-actions {
  display: flex;
  gap: 8px;
  align-items: center
}

.call-btn {
  background: linear-gradient(180deg, #10b981, #059669);
  color: #fff;
  padding: 8px 10px;
  border-radius: 8px;
  border: 0
}

.delete-btn {
  background: transparent;
  border: 1px solid rgba(15, 23, 42, 0.06);
  padding: 8px;
  border-radius: 8px;
  color: var(--muted)
}

.priority-badge {
  background: var(--accent-600);
  color: #fff;
  padding: 6px 8px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700
}

/* Hover effects */
.contact-card:hover {
  transform: translateY(-4px);
  transition: transform var(--transition);
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.06)
}

/* Form error */
.form-error {
  color: var(--accent);
  font-size: .9rem;
  margin-top: 6px
}

/* Footer */
.footer {
  max-width: var(--max-width);
  margin: 12px auto;
  padding: 8px 16px;
  color: var(--muted)
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(2, 6, 23, 0.45);
  z-index: 9999;
  padding: 16px;
}

.modal[aria-hidden="false"] {
  display: flex
}

.modal-content {
  max-width: 720px;
  width: 100%;
  outline: none
}

.import-list {
  max-height: 320px;
  overflow: auto;
  border-radius: 8px;
  padding: 8px;
  border: 1px solid rgba(15, 23, 42, 0.04)
}

.import-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.03)
}

.import-item:last-child {
  border-bottom: 0
}

/* Larger tap targets and accessible spacing */
.btn,
.icon-btn,
.call-btn,
.delete-btn,
.emergency-btn {
  min-height: 44px;
  padding: 12px 14px;
  font-size: 1rem;
  touch-action: manipulation;
}

/* File button style */
.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px dashed rgba(15, 23, 42, 0.06);
  background: transparent;
  border-radius: 8px;
  padding: 10px;
}

/* Focus outlines for keyboard users */
.btn:focus,
.icon-btn:focus,
.call-btn:focus,
.delete-btn:focus,
.emergency-btn:focus,
.modal-content:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Responsive */
@media(min-width:880px) {
  .container {
    grid-template-columns: 360px 1fr
  }

  .cards-grid {
    grid-template-columns: repeat(2, 1fr)
  }

  .btn {
    min-height: 40px
  }
}

/* Dark mode */
body.dark {
  --bg: #0b1220;
  --card: #071022;
  --muted: #cbd5e1;
  /* brighter muted text for readability */
  --primary: #e6eef8;
  --glass: rgba(255, 255, 255, 0.03);
  background: linear-gradient(180deg, #071022, #081226);
}

/* Ensure topbar text and icons are readable in dark mode */
body.dark .topbar {
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.08), transparent);
  color: var(--primary);
}

/* Make sure cards, labels, inputs use the dark-mode colors */
body.dark .card {
  background: var(--card);
  color: var(--primary);
}

body.dark label {
  color: var(--primary);
}

body.dark .label-text {
  color: var(--muted);
}

body.dark input,
body.dark textarea,
body.dark select {
  color: var(--primary);
  border-color: rgba(255, 255, 255, 0.06);
}

body.dark input::placeholder,
body.dark textarea::placeholder {
  color: rgba(230, 238, 248, 0.35);
}

body.dark .contact-name {
  color: var(--primary);
}

body.dark .contact-meta {
  color: var(--muted);
}

body.dark .footer {
  color: var(--muted);
}

/* Keep transitions for interactive elements but not for global theme change */
.card,
.btn,
.contact-card,
.call-btn,
.delete-btn {
  transition: box-shadow var(--transition), transform var(--transition), background-color var(--transition), border-color var(--transition);
}

/* Accessibility: ensure right panel stretches and content centers properly */
.right-panel {
  align-items: stretch;
}

/* Ensure grid items are centered within the available space on large screens */
@media(min-width:1200px) {
  .container {
    padding-left: 24px;
    padding-right: 24px;
  }

  .cards-grid {
    gap: 16px;
  }
}