/* =========================================================
   NASC WEA Alert Generator — Styles
   ========================================================= */

/* --- Design Tokens ---------------------------------------- */
:root {
  --color-brand-teal:     #099186;
  --color-brand-teal-dk:  #077a71;
  --color-brand-teal-lt:  #e6f4f3;

  --color-safe:    #16a34a;
  --color-caution:    #d97706;
  --color-caution-bg: #fffbeb;
  --color-danger:     #dc2626;

  --color-bg:       #f1f5f9;
  --color-surface:  #ffffff;
  --color-border:   #e2e8f0;
  --color-text:     #1e293b;
  --color-muted:    #64748b;

  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;

  --shadow-card: 0 1px 3px rgba(0,0,0,.07), 0 4px 16px rgba(0,0,0,.06);

  --font: 'DM Sans', system-ui, -apple-system, sans-serif;
}

/* --- Reset & Base ------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: var(--font);
  font-size: 1rem;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

a { color: var(--color-brand-teal); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--color-brand-teal-dk); }

/* --- Header ----------------------------------------------- */
.header-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.brand-link {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-text);
  text-decoration: none;
}
.brand-link:hover { color: var(--color-brand-teal-dk); }

.header-divider { color: var(--color-border); }

.site-header {
  background: var(--color-surface);
  border-bottom: 3px solid var(--color-brand-teal);
  padding: 0.875rem 1.5rem;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
}

.header-tool-name {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

/* --- Page Intro ------------------------------------------- */
.page-intro {
  max-width: 1100px;
  margin: 2rem auto 0;
  padding: 0 1.5rem;
}

.page-intro h1 {
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.page-intro p {
  margin-top: 0.5rem;
  color: var(--color-muted);
  max-width: 60ch;
}


/* --- App Layout ------------------------------------------- */
.app-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  max-width: 1100px;
  margin: 1.5rem auto 3rem;
  padding: 0 1.5rem;
  align-items: start;
}

/* --- Panel Titles ----------------------------------------- */
.panel-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--color-text);
}

/* --- Form Panel ------------------------------------------- */
.form-panel {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.125rem;
  transition: opacity 200ms ease;
}

.form-panel--disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* Template selector */
.template-select {
  width: 100%;
  padding: 0.625rem 2.25rem 0.625rem 0.75rem;
  font-size: 1rem;
  font-family: var(--font);
  color: var(--color-text);
  background-color: var(--color-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  min-height: 44px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.template-select:focus {
  outline: none;
  border-color: var(--color-brand-teal);
  box-shadow: 0 0 0 3px rgba(9,145,134,.15);
}

/* Template description */
.template-desc {
  font-size: 0.8125rem;
  color: var(--color-muted);
  line-height: 1.5;
}
.template-desc:empty { display: none; }

/* Field groups */
#fields-container {
  display: flex;
  flex-direction: column;
  gap: 1.125rem;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field-group--age input {
  max-width: 8rem;
}

label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.4;
}

.field-hint {
  font-size: 0.8125rem;
  color: var(--color-muted);
  line-height: 1.4;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-size: 1rem;
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-bg);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  min-height: 44px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
  appearance: none;
  -webkit-appearance: none;
}

input[type="text"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--color-brand-teal);
  box-shadow: 0 0 0 3px rgba(9,145,134,.15);
}

/* Behavior fieldset */
.behavior-fieldset {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.behavior-fieldset legend {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  padding: 0 0.375rem;
}

#checkboxes-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  cursor: pointer;
  min-height: 44px;
  padding: 0.25rem 0;
}

.checkbox-label input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.checkbox-custom {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.125rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 150ms, background 150ms;
}

.checkbox-label input:checked ~ .checkbox-custom {
  background: var(--color-brand-teal);
  border-color: var(--color-brand-teal);
}

.checkbox-label input:checked ~ .checkbox-custom::after {
  content: '';
  display: block;
  width: 0.4rem;
  height: 0.65rem;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translateY(-1px);
}

.checkbox-label input:focus ~ .checkbox-custom {
  box-shadow: 0 0 0 3px rgba(9,145,134,.2);
  border-color: var(--color-brand-teal);
}

.checkbox-text {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  font-size: 0.9375rem;
}

.checkbox-desc {
  font-size: 0.8125rem;
  color: var(--color-muted);
  font-weight: 400;
}

/* --- Preview Panel ---------------------------------------- */
.preview-panel {
  position: sticky;
  top: 1.5rem;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.preview-panel-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.editing-badge {
  align-items: center;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--color-caution-bg);
  color: var(--color-caution);
  border: 1px solid rgba(217,119,6,.2);
}
.editing-badge:not([hidden]) { display: inline-flex; }

.preview-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.5rem;
}

/* Character counter */
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.char-counter {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-safe);
  transition: color 200ms;
}

.char-counter[data-state="caution"] { color: var(--color-caution); }
.char-counter[data-state="over"]    { color: var(--color-danger); }

.char-limit {
  font-weight: 400;
  color: var(--color-muted);
}

.char-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.char-counter[data-state="caution"] .char-badge {
  background: var(--color-caution-bg);
  color: var(--color-caution);
}

.char-counter[data-state="over"] .char-badge {
  color: var(--color-danger);
}

/* Alert preview text */
.alert-preview-text {
  font-size: 0.9375rem;
  line-height: 1.7;
  color: var(--color-text);
  background: var(--color-bg);
  border-radius: var(--radius-md);
  padding: 1rem;
  min-height: 6rem;
  word-break: break-word;
}

.alert-preview-text .dynamic-field {
  font-weight: 600;
}

/* Edit textarea — matches .alert-preview-text */
#alert-edit {
  display: block;
  width: 100%;
  font-size: 0.9375rem;
  line-height: 1.7;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1.5px solid var(--color-brand-teal);
  border-radius: var(--radius-md);
  padding: 1rem;
  min-height: 6rem;
  font-family: var(--font);
  resize: none;
  box-shadow: 0 0 0 3px rgba(9,145,134,.1);
}

#alert-edit:focus {
  outline: none;
}

/* Copy + Edit actions */
.preview-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
}

.btn-copy {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-family: var(--font);
  font-weight: 600;
  color: #fff;
  background: var(--color-brand-teal);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  min-height: 44px;
  transition: background 150ms ease, transform 100ms ease;
}

.btn-copy:hover { background: var(--color-brand-teal-dk); }
.btn-copy:active { transform: scale(0.98); }


.btn-edit {
  padding: 0.75rem 1rem;
  font-size: 0.9375rem;
  font-family: var(--font);
  font-weight: 600;
  color: var(--color-muted);
  background: var(--color-bg);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
  transition: border-color 150ms, color 150ms, background 150ms;
}

.btn-edit:hover {
  border-color: var(--color-brand-teal);
  color: var(--color-brand-teal);
}

.copy-confirm {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-safe);
  white-space: nowrap;
}


/* --- Footer ----------------------------------------------- */
.site-footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 1rem 1.5rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--color-muted);
}

/* --- Responsive ------------------------------------------- */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    margin-top: 1rem;
  }

  .form-panel { order: 2; }
  .preview-panel {
    order: 1;
    position: static;
  }

  .page-intro { margin-top: 1.25rem; }
  .page-intro h1 { font-size: 1.375rem; }
}

@media (max-width: 480px) {
  .app-layout { padding: 0 1rem; gap: 1rem; margin-bottom: 2rem; }
  .form-panel, .preview-card { padding: 1.25rem; }
}

/* --- Print ------------------------------------------------- */
@media print {
  .site-header,
  .site-footer,
  .form-panel,
  .preview-actions,
  .wea-note,
  .char-counter,
  .editing-badge { display: none; }

  .app-layout { display: block; padding: 0; margin: 0; }

  .preview-card {
    box-shadow: none;
    border: 1px solid #ccc;
    padding: 1rem;
  }

  .alert-preview-text {
    font-size: 1.25rem;
    background: none;
    padding: 0;
  }
}
