/* CSS Custom Properties for theming — CivicActions brand palette */
/* Brand reference: https://civicactions-style-guide.readthedocs.io/en/latest/ */
:root {
  /* CivicActions brand tokens */
  --ca-red: #d83933;
  --ca-red-secondary: #8b0a03;
  --ca-blue-dark: #162e51;
  --ca-blue-secondary: #1a4480;
  --ca-blue-light: #73b3e7;
  --ca-gold: #fa9441;

  /* System tokens — light mode */
  --color-text: #171717;
  --color-text-secondary: #454545;
  --color-bg: #ffffff;
  --color-bg-panel: #ffffff;
  --color-border: #d6d7d9;
  --color-border-input: #71767a;
  --color-primary: #1a4480;
  --color-primary-text: #ffffff;
  --color-secondary-bg: #f0f0f0;
  --color-secondary-text: #171717;
  --color-info-bg: #e8f0fc;
  --color-info-text: #162e51;
  --color-success-bg: #ecf3ec;
  --color-success-text: #1b5e20;
  --color-warning-bg: #fef5e6;
  --color-warning-text: #7a4500;
  --color-error-bg: #fce8e7;
  --color-error-text: #8b0a03;
  --color-footer-bg: #f0f0f0;
  --color-link: #1a4480;
  --color-link-hover: #162e51;
  --color-accent: #d83933;
  --color-heading: #162e51;
  --color-success-border: #28a745;
}

[data-theme="dark"] {
  --color-text: #e9e9e9;
  --color-text-secondary: #a9aeb1;
  --color-bg: #1b1b1b;
  --color-bg-panel: #2d2d2d;
  --color-border: #3d4551;
  --color-border-input: #71767a;
  --color-primary: #73b3e7;
  --color-primary-text: #1b1b1b;
  --color-secondary-bg: #2d2d2d;
  --color-secondary-text: #e9e9e9;
  --color-info-bg: #162e51;
  --color-info-text: #b3d4f5;
  --color-success-bg: #1b3a1f;
  --color-success-text: #a3d9a5;
  --color-warning-bg: #3d2400;
  --color-warning-text: #ffc87a;
  --color-error-bg: #3d1110;
  --color-error-text: #f4a09d;
  --color-footer-bg: #2d2d2d;
  --color-link: #73b3e7;
  --color-link-hover: #b3d4f5;
  --color-accent: #f4a09d;
  --color-heading: #e9e9e9;
  --color-success-border: #a3d9a5;
}

body {
  font-family: 'Public Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  transition: background-color 0.2s ease, color 0.2s ease;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--color-heading);
  line-height: 1.3;
}

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

a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

.page-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: 48rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
  flex: 1;
}

.hero {
  margin-bottom: 1rem;
}

.lead {
  margin: 0.5rem 0 0;
}

.panel {
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 1rem 1rem 0.9rem;
  margin-bottom: 1rem;
  background: var(--color-bg-panel);
}

.field {
  margin-bottom: 0.85rem;
}

.field-inline {
  margin-bottom: 0.85rem;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

input[type="url"],
input[type="number"],
input[type="password"],
textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--color-border-input);
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  font: inherit;
  background: var(--color-bg);
  color: var(--color-text);
}

textarea {
  resize: vertical;
}

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

button {
  border: 1px solid var(--color-primary);
  border-radius: 6px;
  background: var(--color-primary);
  color: var(--color-primary-text);
  min-height: 2.6rem;
  padding: 0.45rem 0.85rem;
  font: inherit;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--color-link-hover);
  border-color: var(--color-link-hover);
}

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

button.secondary {
  background: var(--color-secondary-bg);
  color: var(--color-secondary-text);
  border-color: var(--color-border-input);
}

button.secondary:hover:not(:disabled) {
  background: var(--color-border);
  border-color: var(--color-border-input);
  color: var(--color-secondary-text);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.status {
  border-radius: 6px;
  padding: 0.75rem;
  margin-bottom: 0.35rem;
}

.status.info {
  background: var(--color-info-bg);
  color: var(--color-info-text);
}

.status.success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.status.warning {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
}

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

.hint {
  margin: 0.25rem 0 0;
  color: var(--color-text-secondary);
  font-size: 0.95rem;
}

@media (min-width: 640px) {
  .container {
    padding-top: 2rem;
  }

  .actions {
    grid-template-columns: repeat(3, minmax(0, max-content));
    justify-content: flex-start;
  }
}

/* Theme toggle button */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  min-height: 2.5rem;
  width: 2.5rem;
  padding: 0.5rem;
  border-radius: 50%;
  background: var(--color-secondary-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

.theme-toggle:hover {
  background: var(--color-border);
  transform: scale(1.05);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.theme-toggle .theme-icon {
  width: 20px;
  height: 20px;
  display: block;
  transition: opacity 0.2s ease;
}

.theme-toggle .theme-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Show sun icon in dark mode, moon icon in light mode */
[data-theme="light"] .theme-toggle .sun-icon {
  display: none;
}

[data-theme="light"] .theme-toggle .moon-icon {
  display: block;
}

[data-theme="dark"] .theme-toggle .sun-icon {
  display: block;
}

[data-theme="dark"] .theme-toggle .moon-icon {
  display: none;
}

/* Footer styles */
.site-footer {
  background-color: var(--color-footer-bg);
  border-top: 1px solid var(--color-border);
  padding: 1.5rem 1rem;
  margin-top: auto;
  text-align: center;
}

.site-footer p {
  margin: 0;
  color: var(--color-text-secondary);
  font-size: 0.95rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.25rem;
}

.site-footer a {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--color-link);
  text-decoration: none;
  font-weight: 500;
}

.site-footer a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

.site-footer a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

.site-footer svg {
  flex-shrink: 0;
}

/* Modal styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.6);
  animation: fadeIn 0.2s ease;
}

.modal.open {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background-color: var(--color-bg-panel);
  margin: 1rem;
  padding: 1.5rem;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  animation: slideIn 0.3s ease;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.5rem;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.75rem;
  line-height: 1;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  min-height: auto;
  border-radius: 4px;
}

.modal-close:hover {
  background: var(--color-secondary-bg);
  color: var(--color-text);
}

.modal-close:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.modal-body {
  line-height: 1.6;
}

.modal-body h3 {
  margin-top: 1.25rem;
  margin-bottom: 0.75rem;
  font-size: 1.125rem;
}

.modal-body p {
  margin: 0.75rem 0;
}

.modal-body ul {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
}

.modal-body li {
  margin: 0.5rem 0;
}

.modal-body a {
  color: var(--color-link);
  text-decoration: none;
  word-break: break-word;
}

.modal-body a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Disclaimer section */
.disclaimer {
  margin: 1.5rem 0;
  padding: 1rem;
  background: var(--color-info-bg);
  color: var(--color-info-text);
  border-radius: 6px;
  border-left: 4px solid var(--color-primary);
}

.disclaimer p {
  margin: 0.5rem 0;
}

.disclaimer p:first-child {
  margin-top: 0;
}

.disclaimer p:last-child {
  margin-bottom: 0;
}

.disclaimer-link {
  color: var(--color-primary);
  text-decoration: underline;
  cursor: pointer;
  font-weight: 500;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  display: inline;
  min-height: auto;
}

.disclaimer-link:hover {
  color: var(--color-link-hover);
}

.disclaimer-link:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 2px;
}

.page-estimate {
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.5rem;
}

/* AI streaming summary output */
.ai-summary {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--color-secondary-bg);
  color: var(--color-secondary-text);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 0.95rem;
  white-space: pre-wrap;
  min-height: 3rem;
}

.ai-summary[hidden] {
  display: none;
}

/* Notification Modal styles */
.notification-modal {
  position: fixed;
  top: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  width: 90%;
  max-width: 500px;
  animation: notificationSlideIn 0.3s ease;
}

@media (max-width: 640px) {
  .notification-modal {
    top: 1rem;
    width: 95%;
  }
}

.notification-modal[hidden] {
  display: none;
}

.notification-content {
  background-color: var(--color-success-bg);
  color: var(--color-success-text);
  border: 2px solid var(--color-success-border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.notification-modal.hiding {
  animation: notificationFadeOut 0.3s ease forwards;
}

.notification-content p {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
}

@keyframes notificationSlideIn {
  from {
    transform: translate(-50%, -100%);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

@keyframes notificationFadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translate(-50%, -20px);
  }
}