:root {
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-text: #1a2233;
  --color-text-muted: #647089;
  --color-border: #dde3ea;
  --color-primary: #1f6feb;
  --color-primary-hover: #185ec7;
  --color-error-bg: #fdecec;
  --color-error-text: #b3261e;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(20, 30, 50, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

.page-center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.brand svg {
  color: var(--color-primary);
}

.brand span {
  font-size: 18px;
  font-weight: 600;
}

h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.subtitle {
  color: var(--color-text-muted);
  font-size: 14px;
  margin: 0 0 24px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--color-text-muted);
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group svg {
  position: absolute;
  left: 12px;
  color: var(--color-text-muted);
  pointer-events: none;
}

.input-group input {
  width: 100%;
  padding: 10px 12px 10px 38px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color 0.15s ease;
}

.input-group input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.input-group .toggle-visibility {
  position: absolute;
  right: 10px;
  left: auto;
  pointer-events: auto;
  cursor: pointer;
  background: none;
  border: none;
  padding: 4px;
  display: flex;
  color: var(--color-text-muted);
}

.input-group .toggle-visibility:hover {
  color: var(--color-text);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  font-size: 13px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text-muted);
  cursor: pointer;
}

button.primary {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: var(--color-primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s ease;
}

button.primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

button.primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}

button.primary.loading .spinner {
  display: inline-block;
}

button.primary.loading .btn-label {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 64px 24px;
  color: var(--color-text-muted);
  font-size: 14px;
}

.spinner-page {
  width: 26px;
  height: 26px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.error-banner {
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
}

.error-banner.visible {
  display: flex;
}

.dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: min(380px, calc(100vw - 32px));
  text-align: center;
}

.dialog::backdrop {
  background: rgba(20, 30, 50, 0.45);
}

.dialog-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: #e6f4ea;
  color: #1e7e34;
}

.dialog h2 {
  font-size: 18px;
  margin: 0 0 8px;
}

.dialog p {
  color: var(--color-text-muted);
  font-size: 14px;
  margin: 0;
}

.dialog-actions {
  margin-top: 24px;
}

.dialog-actions button.primary {
  width: 100%;
}

.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.dashboard-body {
  padding: 32px 24px;
}

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.stat-tile-label {
  color: var(--color-text-muted);
  font-size: 13px;
}

.stat-tile-value {
  font-size: 28px;
  font-weight: 600;
}

button.secondary {
  padding: 8px 14px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button.secondary:hover {
  border-color: var(--color-text-muted);
}

button.secondary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* App shell / nav */

.app-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 24px;
}

.app-nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}

.app-nav a:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.app-nav a.active {
  background: var(--color-bg);
  color: var(--color-primary);
}

.header-left {
  display: flex;
  align-items: center;
}

.page-body {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px;
}

.page-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.page-title-row h1 {
  font-size: 22px;
  margin: 0;
}

.subnav {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
}

.subnav a {
  padding: 10px 4px;
  margin-right: 20px;
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}

.subnav a:hover {
  color: var(--color-text);
}

.subnav a.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

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

.masked-password .copy-password-btn {
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: var(--color-text-muted);
  display: inline-flex;
}

.masked-password .copy-password-btn:hover {
  color: var(--color-primary);
}

.masked-password .copy-password-btn.copied {
  color: #1e7e34;
}

button.primary.small,
a.button-link {
  width: auto;
  padding: 9px 16px;
  font-size: 13px;
  display: inline-flex;
  text-decoration: none;
}

/* Table */

.table-wrap {
  overflow-x: auto;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table.templates-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.templates-table th {
  text-align: left;
  padding: 12px 16px;
  color: var(--color-text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

table.templates-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

table.templates-table tr:last-child td {
  border-bottom: none;
}

table.templates-table tr.row-link {
  cursor: pointer;
}

table.templates-table tr.row-link:hover {
  background: var(--color-bg);
}

.template-name-cell {
  font-weight: 600;
}

.template-message-cell {
  max-width: 320px;
  color: var(--color-text-muted);
}

#contactList li {
  padding: 7px 14px;
  border-bottom: 1px solid var(--color-border);
}

#contactList li:last-child {
  border-bottom: none;
}

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--color-text-muted);
}

/* Status badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-approved {
  background: #e6f4ea;
  color: #1e7e34;
}

.badge-pending {
  background: #fff4e0;
  color: #9a6700;
}

.badge-rejected {
  background: var(--color-error-bg);
  color: var(--color-error-text);
}

.badge-unknown {
  background: #eef0f3;
  color: var(--color-text-muted);
}

/* Form sections (Create Template) */

.form-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  max-width: 720px;
}

.form-section {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--color-border);
}

.form-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.form-section h2 {
  font-size: 15px;
  margin: 0 0 4px;
}

.form-section .section-hint {
  color: var(--color-text-muted);
  font-size: 13px;
  margin: 0 0 16px;
}

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

@media (max-width: 560px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--color-text-muted);
}

.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.field textarea {
  resize: vertical;
  min-height: 90px;
}

.field .hint {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 4px;
}

.field .hint.char-count {
  text-align: right;
}

.field .field-error {
  font-size: 12px;
  color: var(--color-error-text);
  margin-top: 4px;
  display: none;
}

.field.has-error input,
.field.has-error select,
.field.has-error textarea {
  border-color: var(--color-error-text);
}

.field.has-error .field-error {
  display: block;
}

.carousel-card {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
}

.carousel-card h3 {
  font-size: 13px;
  margin: 0 0 12px;
  color: var(--color-text-muted);
}

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

.form-actions button.primary {
  width: auto;
  padding: 10px 20px;
}

/* Detail page */

.detail-grid {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 12px 16px;
  font-size: 14px;
}

.detail-grid dt {
  color: var(--color-text-muted);
}

.detail-grid dd {
  margin: 0;
  white-space: pre-wrap;
}

.detail-message-box {
  background: var(--color-bg);
  border-radius: 8px;
  padding: 16px;
  white-space: pre-wrap;
  font-size: 14px;
}

.meta-error-box {
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 13px;
  margin-top: 8px;
}

.meta-error-box strong {
  display: block;
  margin-bottom: 4px;
}

/* Mobile */

.bottom-nav {
  display: none;
}

@media (max-width: 720px) {
  /* Primary navigation moves to the bottom-nav bar on mobile - the old
     horizontally-scrolling top nav was hard to discover/use with a thumb. */
  .app-nav {
    display: none;
  }

  .dashboard-header {
    padding: 12px 16px;
  }

  .page-body,
  .dashboard-body {
    padding: 20px 16px calc(88px + env(safe-area-inset-bottom));
  }

  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    justify-content: space-around;
    align-items: flex-end;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  }

  .bottom-nav-item {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 4px 0;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 11px;
    font-weight: 500;
  }

  .bottom-nav-item.active {
    color: var(--color-primary);
  }

  .bottom-nav-center {
    position: relative;
    margin-top: -30px;
  }

  .bottom-nav-fab {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    box-shadow: var(--shadow);
    margin-bottom: 3px;
  }

  .bottom-nav-center.active .bottom-nav-fab {
    background: var(--color-primary-hover);
  }

  .page-title-row {
    flex-wrap: wrap;
    gap: 10px;
  }

  .form-card {
    padding: 20px;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions button.primary,
  .form-actions a.button-link {
    width: 100%;
  }

  .detail-grid {
    grid-template-columns: 1fr;
    gap: 4px 0;
  }

  .detail-grid dt {
    margin-top: 10px;
  }

  .detail-grid dt:first-child {
    margin-top: 0;
  }
}
