:root {
  --color-bg: #f9fafb;
  --color-surface: #ffffff;
  --color-surface-elevated: #ffffff;
  --color-border-subtle: #d1d5db;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-accent: #ea580c;
  --color-accent-soft: rgba(234, 88, 12, 0.1);
  --color-accent-strong: #9a3412;
  --color-danger: #dc2626;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-pill: 999px;
  --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.12);
  --shadow-subtle: 0 0 0 1px rgba(209, 213, 219, 0.5);
  /* Thai: Sarabun + system Thai fallbacks (WCAG AA, NFR3) */
  --font-sans: 'Sarabun', 'Thonburi', 'Tahoma', 'Leelawadee UI', system-ui, sans-serif;
}

/* --- 1. GLOBAL RESET & LAYOUT FIXES (Removes Black Border) --- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%; /* Ensures full height */
  overflow-x: hidden; /* Prevents side scrolling */
}

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background-color: var(--color-bg);
  background: radial-gradient(circle at top, #f9fafb 0%, #f3f4f6 55%, #e5e7eb 100%);
  background-attachment: fixed; /* Keeps background stable on scroll */
  -webkit-font-smoothing: antialiased;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none; /* Prevent iOS bounce effect */
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* iOS safe area padding for notch/status bar */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* --- 2. VIEW MANAGEMENT --- */
.view {
  display: none;
  width: 100%;
  min-height: 100vh;
}

.view:not([hidden]) {
  display: flex; /* Changed to flex to support centering logic */
  flex-direction: column;
}

/* --- 3. PORTAL SPECIFIC STYLES (Centered Layout) --- */
.view-portal {
  /* This centers the content perfectly */
  justify-content: center;
  align-items: center;
  padding: 2rem;
  background: linear-gradient(180deg, #ffffff 0%, #f9fafb 40%, #f3f4f6 100%);
  text-align: center;
}

.portal-header {
  margin-bottom: 2rem;
  max-width: 500px;
}

.portal-title {
  font-size: 2.25rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: var(--color-text);
  letter-spacing: 0.02em;
  line-height: 1.35;
}

/* Responsive portal title for different screen sizes */
@media (max-width: 768px) {
  .portal-title {
    font-size: 1.85rem;
    line-height: 1.3;
  }
}

@media (max-width: 480px) {
  .portal-title {
    font-size: 1.6rem;
    line-height: 1.25;
  }
}

@media (max-width: 360px) {
  .portal-title {
    font-size: 1.4rem;
    line-height: 1.2;
  }
}

.portal-subtitle {
  font-size: 1.25rem;
  margin: 0;
  color: var(--color-text-muted);
  font-weight: 400;
  line-height: 1.5;
}

.portal-nav {
  width: 100%;
  max-width: 320px; /* Limits button width on large screens */
  margin-bottom: 1.5rem;
}

.portal-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.portal-btn {
  display: block;
  width: 100%;
  min-height: 4rem;
  padding: 0 1.25rem;
  font-family: var(--font-sans);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--color-text);
  background: var(--color-surface);
  border: 3px solid var(--color-accent);
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.portal-btn:active {
  transform: scale(0.97);
}

.portal-hint {
  font-size: 1.1rem;
  color: var(--color-text-muted);
  margin: 0;
  max-width: 400px;
  line-height: 1.5;
}

/* --- 4. DASHBOARD STYLES --- */
.view-dashboard {
  /* Restores standard padding for the dashboard view */
  padding: 1.25rem 1.25rem 0.45rem;
  max-width: 960px;
  margin: 0 auto;
}

@media (min-width: 768px) {
  .view-dashboard {
    padding-top: 2rem;
  }
}

.app-header {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  position: relative;
}

.app-header-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.app-header h1 {
  font-size: 1.68rem;
  letter-spacing: 0.03em;
  margin: 0;
}

.enterprise-name {
  margin: 0;
  margin-top: 0.25rem;
  margin-bottom: 0.5rem;
  color: var(--color-text);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
}

.app-tagline {
  margin: 0;
  margin-bottom: 0.5rem;
  color: var(--color-text-muted);
  font-size: 1.15rem;
}

.app-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.15rem 0.8rem;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(248, 250, 252, 0.3);
  background: radial-gradient(circle at top left, #f97316 0, #b91c1c 40%, #020617 100%);
  color: #fefce8;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
}

main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 960px) {
  main {
    flex-direction: row;
    align-items: flex-start;
  }
}

/* --- 5. PANELS & BLOCKS --- */
.panel {
  border-radius: var(--radius-lg);
  padding: 1rem 1rem 1.1rem;
  box-shadow: var(--shadow-soft), var(--shadow-subtle);
  border: 1px solid var(--color-border-subtle);
  backdrop-filter: blur(28px);
}

.panel-primary {
  flex: 3;
  background:
    radial-gradient(circle at top left, rgba(148, 163, 184, 0.15), transparent 55%),
    linear-gradient(to bottom right, rgba(255, 255, 255, 0.98), rgba(249, 250, 251, 0.95));
}

.panel-secondary {
  flex: 2;
  background:
    radial-gradient(circle at top right, rgba(251, 146, 60, 0.1), transparent 55%),
    linear-gradient(to bottom right, rgba(255, 255, 255, 0.98), rgba(249, 250, 251, 0.95));
}

.panel-header {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0.85rem;
}

.panel-header-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-accent-strong);
}

.panel-subtitle {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 1.1rem;
}

.block {
  border-radius: var(--radius-md);
  background: linear-gradient(to bottom right, rgba(255, 255, 255, 0.95), rgba(249, 250, 251, 0.9));
  border: 1px solid var(--color-border-subtle);
  padding: 0.9rem 0.85rem;
  margin-bottom: 0.7rem;
}

.block-header {
  margin-bottom: 0.5rem;
}

.block-header-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.block-header h3 {
  margin: 0;
  font-size: 1.25rem;
}

.block-subtitle {
  margin: 0.1rem 0 0;
  color: var(--color-text-muted);
  font-size: 1rem;
}

/* --- 6. INTERACTIVE ELEMENTS --- */
.btn {
  border-radius: var(--radius-pill);
  border: none;
  cursor: pointer;
  font: inherit;
  padding: 0.6rem 1.3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.8rem;
  min-width: 2.8rem;
  text-decoration: none;
  white-space: nowrap;
  font-size: 1rem;
}

.btn-accent {
  background: radial-gradient(circle at top, #22c55e 0%, #16a34a 35%, #15803d 100%);
  color: #d0ebf2;
  font-weight: 600;
  box-shadow: 0 10px 35px rgba(248, 250, 252, 0.25);
}

.btn-accent[aria-disabled='true'] {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}

.btn-outline {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border-subtle);
  font-size: 1rem;
}

.contact-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.5rem;
}

@media (min-width: 480px) {
  .contact-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.contact-card {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  align-items: flex-start;
  justify-content: center;
  padding: 0.6rem 0.8rem;
  border-radius: 25px;
  border: 1px solid var(--color-border-subtle);
  text-decoration: none;
  background: radial-gradient(circle at top left, rgba(248, 250, 252, 0.5), transparent 55%);
  color: var(--color-text);
  min-height: 2.6rem;
}

.contact-card:hover {
  border-color: #ea580c;
  box-shadow: 0 0 0 1px rgba(234, 88, 12, 0.3);
}

.contact-card-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.contact-card-number {
  font-size: 1rem;
  color: var(--color-text-muted);
}

.inline-error {
  margin-top: 0.5rem;
  font-size: 1rem;
  color: var(--color-danger);
}

.evac-list {
  margin: 0.25rem 0 0;
  padding-left: 1.1rem;
  font-size: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.map-figure {
  margin: 0.75rem 0 0;
}

.map-image {
  width: 100%;
  display: block;
  border-radius: 14px;
  border: 1px solid var(--color-border-subtle);
  background: radial-gradient(circle at top, #f9fafb, #f3f4f6 60%, #e5e7eb 100%);
}

.map-caption {
  margin-top: 0.45rem;
  font-size: 1rem;
  color: var(--color-text-muted);
}

/* --- 7. RESOURCES PANEL --- */

/* Priority Badge for Resources */
.resource-badge {
  background: var(--color-accent);
  color: white;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 10px;
  white-space: nowrap;
}
.resources-panel {
  margin-top: 0.3rem;
  border-radius: var(--radius-md);
  border: 1px dashed var(--color-border-subtle);
  background: linear-gradient(to bottom right, rgba(255, 255, 255, 0.95), rgba(249, 250, 251, 0.9));
  padding: 0.7rem 0.7rem 0.75rem;
  /* Visual toggle handled by JS logic */
}

.resources-hint {
  margin: 0 0 0.45rem;
  font-size: 1rem;
  color: var(--color-text-muted);
}

.resources-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.resource-item-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  border-radius: 15px;
  border: 1px solid var(--color-border-subtle);
  text-decoration: none;
  color: var(--color-text);
  background: var(--color-surface);
  font-size: 1.1rem;
}

.resource-item-link:hover {
  border-color: var(--color-accent);
}

.btn-reset-org {
  margin-top: 0.75rem;
  width: 100%;
}

.app-footer {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  text-align: center;
}

/* Top-Right Organization Change Button */
.btn-header-org {
  position: absolute;
  top: calc(3rem + env(safe-area-inset-top));
  right: 0;
  z-index: 100;
  min-height: 2.8rem;
  padding: 0.6rem 1rem;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border-subtle);
  font-size: 1rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.2s, border-color 0.2s;
}

.btn-header-org:hover {
  background: var(--color-bg);
  border-color: var(--color-accent);
}

.btn-header-org:active {
  transform: scale(0.97);
}

/* Shared Toggle Button Styles - Instant Response */
.btn-toggle {
  width: 100%;
  background-color: rgba(209, 213, 219, 0.5);
  outline: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s, border-color 0.1s;
  transform: scale(1);
}

.btn-toggle:focus-visible {
  box-shadow: 0 0 0 2px var(--color-accent);
}

.btn-toggle:focus:not(:focus-visible) {
  box-shadow: none;
}

.btn-toggle:active {
  background-color: rgba(191, 192, 197, 0.7);
  transform: scale(0.97);
  transition: transform 0.05s;
}

.btn-toggle::-moz-focus-inner {
  border: 0;
}

/* Emergency Contacts Toggle Button - Position only */
.btn-emergency-toggle {
  margin-top: 0.5rem;
  font-size: 1rem;
}

/* Resources Toggle Button - Position only */
.btn-resources-toggle {
  margin-top: 0.75rem;
}

/* More Resources Toggle Button - Responsive like Header Button */
.more-toggle {
  white-space: nowrap;
  transition: background 0.1s, border-color 0.1s;
}

.more-toggle:hover {
  background: var(--color-bg);
  border-color: var(--color-accent);
}

.more-toggle:active {
  transform: scale(0.97);
}

.site-footer {
  padding: 0.4rem 1.5rem 1rem;
  text-align: left;
  border-top: 0.1px solid var(--color-border-subtle);
  font-size: 0.7rem;
  color: var(--color-text-muted);
}

.footer-content {
  display: flex;
  flex-direction: column;
  align-items: left;
  gap: 0.1rem;
}

.footer-content p {
  margin: 0;
}

.footer-links a {
  color: var(--color-text-muted);
  text-decoration: none;
}

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