:root {
  color-scheme: light;

  /* Coastal Action Brand Palette - Option 2: Deep Ocean & Sand */
  --coastal-ocean: #0cc0df;        /* Logo Ocean Wave */
  --coastal-aqua: #5ce1e6;         /* Logo Aqua Wave */
  --coastal-sand: #ffeb99;         /* Logo Beach Sand */
  --coastal-sand-text: #6b4e00;    /* High-contrast sand text */
  --coastal-deep: #08859b;         /* Primary Action Teal */
  --coastal-deep-hover: #066b7d;   /* Primary Hover */
  --coastal-dark: #111827;         /* Logo Ink Charcoal */

  --panel-bg: rgba(255, 255, 255, 0.95);
  --panel-border: rgba(12, 192, 223, 0.22);
  --panel-shadow: 0 16px 36px rgba(8, 133, 155, 0.12);

  --accent: #08859b;
  --accent-hover: #066b7d;
  --accent-light: #ebf9fa;
  --text-main: #111827;
  --text-muted: #4b5563;
  --border-subtle: rgba(12, 192, 223, 0.14);

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-main);
  background: linear-gradient(180deg, #e6f7f9 0%, #f4fbfc 100%);
  overflow: hidden;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 420px) minmax(0, 1fr);
  gap: 16px;
  height: 100vh;
  padding: 16px;
}

/* Sidebar styling */
.sidebar {
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.control-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  background: var(--panel-bg);
  box-shadow: var(--panel-shadow);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  scrollbar-width: thin;
  scrollbar-color: rgba(8, 133, 155, 0.25) transparent;
}

.control-panel::-webkit-scrollbar {
  width: 6px;
}
.control-panel::-webkit-scrollbar-track {
  background: transparent;
}
.control-panel::-webkit-scrollbar-thumb {
  background: rgba(8, 133, 155, 0.25);
  border-radius: 4px;
}
.control-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(8, 133, 155, 0.5);
}

.panel-header {
  flex-shrink: 0;
  margin-bottom: 16px;
}

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

.panel-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 20px;
  background: var(--coastal-sand);
  color: var(--coastal-sand-text);
  border: 1px solid rgba(212, 167, 19, 0.35);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.panel-desc {
  margin: 0 0 14px;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

/* Form Controls */
.control-group {
  margin-bottom: 14px;
  flex-shrink: 0;
}

.control-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-main);
}

.select-state {
  width: 100%;
  padding: 9px 12px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-main);
  background: #fff;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.select-state:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(12, 192, 223, 0.22);
}

.slider-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 6px;
  cursor: pointer;
}

.overlay-value {
  min-width: 44px;
  text-align: right;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.count-readout {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.count-readout strong {
  color: var(--accent);
  font-weight: 700;
}

/* Search bar */
.search-wrapper {
  position: relative;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.search-input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  font-size: 0.85rem;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-main);
  outline: none;
  transition: all 0.2s;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(12, 192, 223, 0.22);
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 0.85rem;
}

/* Actions Toolbar */
.toolbar-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: #fff;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.btn:hover {
  background: var(--accent-light);
  border-color: rgba(12, 192, 223, 0.35);
}

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

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

.btn-sm {
  padding: 4px 8px;
  font-size: 0.74rem;
}

/* Sheet List Section */
.sheets-section {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 220px;
}

.sheets-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
  flex-shrink: 0;
}

.sheet-list {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 160px;
  max-height: 50vh;
  padding-right: 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(8, 133, 155, 0.25) transparent;
}

/* Scrollbar styling */
.sheet-list::-webkit-scrollbar {
  width: 6px;
}
.sheet-list::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.02);
  border-radius: 4px;
}
.sheet-list::-webkit-scrollbar-thumb {
  background: rgba(8, 133, 155, 0.25);
  border-radius: 4px;
}
.sheet-list::-webkit-scrollbar-thumb:hover {
  background: rgba(8, 133, 155, 0.5);
}

.sheet-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.sheet-item:hover {
  border-color: rgba(12, 192, 223, 0.35);
  box-shadow: 0 2px 8px rgba(8, 133, 155, 0.08);
}

.sheet-item.is-focused {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 2px rgba(12, 192, 223, 0.35);
}

.sheet-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sheet-checkbox {
  cursor: pointer;
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.sheet-title {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sheet-tag {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--coastal-sand-text);
  background: #fff8dc;
  border: 1px solid rgba(212, 167, 19, 0.35);
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: color 0.15s, background 0.15s;
}

.icon-btn:hover {
  color: var(--accent);
  background: var(--accent-light);
}

/* Status / Helper footer */
.panel-footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.panel-footer-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.panel-footer-link:hover {
  text-decoration: underline;
}

/* Map Shell */
.map-shell {
  min-width: 0;
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.58);
  box-shadow: var(--panel-shadow);
  position: relative;
}

#map {
  height: 100%;
  width: 100%;
}

.map-loading-overlay {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 32, 43, 0.88);
  color: #fff;
  padding: 8px 18px;
  border-radius: 30px;
  font-size: 0.82rem;
  font-weight: 500;
  z-index: 100;
  display: none;
  align-items: center;
  gap: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  backdrop-filter: blur(8px);
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Modal details */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-content {
  background: #ffffff;
  border-radius: var(--radius-md);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  max-width: 520px;
  width: 100%;
  overflow: hidden;
  animation: modalIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: #f4fbfc;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--accent);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 20px;
  font-size: 0.86rem;
  max-height: 70vh;
  overflow-y: auto;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
}

.detail-table th,
.detail-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}

.detail-table th {
  color: var(--text-muted);
  width: 35%;
  font-weight: 600;
}

/* Responsive */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    padding: 8px;
    gap: 8px;
    height: 100vh;
  }

  .sidebar {
    height: auto;
    max-height: 48vh;
  }

  .control-panel {
    padding: 14px;
    max-height: 48vh;
  }

  .sheet-list {
    max-height: 200px;
  }
}
