/* ============================================
   Snow Profiler — Modern CSS
   ============================================ */

/* --- Snow Symbol Font --- */
@font-face {
  font-family: 'snowsymbolsiacs';
  src: url('../assets/fonts/SnowSymbolIACS.woff2') format('woff2'),
       url('../assets/fonts/snowsymbolsiacs.woff')  format('woff');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

.snow-symbol {
  font-family: 'snowsymbolsiacs', sans-serif;
  font-size: 1.2em;
  line-height: 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Custom Properties --- */
:root {
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-surface-alt: #f0f2f5;
  --color-border: #dfe3e8;
  --color-border-focus: #4a90d9;
  --color-text: #1a2332;
  --color-text-muted: #6b7685;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-text: #ffffff;
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-success: #16a34a;
  --color-warning: #f59e0b;
  --color-accent: #7c3aed;
  --color-row-hover: rgba(37, 99, 235, 0.04);
  --color-row-alt: rgba(0, 0, 0, 0.015);
  --color-tab-active: var(--color-primary);
  --color-readonly: #f5f5f5;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --shadow-xl: 0 16px 48px rgba(0,0,0,0.16);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;

  --transition: 150ms ease;
  --transition-slow: 300ms ease;
}

/* --- Dark Mode --- */
[data-theme="dark"] {
  --color-bg: #0f1419;
  --color-surface: #1a2332;
  --color-surface-alt: #1e2a3a;
  --color-border: #2d3a4a;
  --color-border-focus: #5b9cf0;
  --color-text: #e4e8ee;
  --color-text-muted: #8899aa;
  --color-primary: #3b82f6;
  --color-primary-hover: #60a5fa;
  --color-row-hover: rgba(59, 130, 246, 0.08);
  --color-row-alt: rgba(255, 255, 255, 0.02);
  --color-readonly: #1e2a3a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
}

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

html {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* --- Typography --- */
h1 { font-size: 1.25rem; font-weight: 700; }
h2 { font-size: 1.125rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
label { font-size: 0.8125rem; font-weight: 500; color: var(--color-text-muted); display: flex; align-items: center; gap: 6px; margin-bottom: 4px; min-height: 17px; }

/* --- Container --- */
.container { max-width: 1280px; margin: 0 auto; padding: 0 16px; }

/* --- Header --- */
.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #66c7ff;
}

.brand h1 { font-size: 1.1rem; letter-spacing: -0.02em; font-weight: 400; }
.brand .brand-profiler { font-weight: 700; color: #66c7ff; }
.brand .brand-report { font-weight: 400; }
.brand .logo { flex-shrink: 0; }

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

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), transform 80ms ease, opacity 80ms ease;
  white-space: nowrap;
  font-family: inherit;
  /* Remove tap delay + grey flash on iOS/Android */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

/* Satisfying press feedback on all touch devices */
.btn:active {
  transform: scale(0.94);
  opacity: 0.82;
}

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

.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
}
.btn-outline:hover { background: var(--color-primary); color: var(--color-primary-text); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover { background: var(--color-surface-alt); color: var(--color-text); }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover { background: var(--color-danger-hover); }

.btn-icon {
  background: transparent;
  border: none;
  padding: 6px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition),
              transform 80ms ease, opacity 80ms ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
.btn-icon:hover { background: var(--color-surface-alt); color: var(--color-text); }
.btn-icon:active { transform: scale(0.90); opacity: 0.75; }

.btn-inline {
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 4px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), transform 80ms ease, opacity 80ms ease;
  font-family: inherit;
  line-height: 1;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn-inline:hover { background: rgba(37, 99, 235, 0.08); }
.btn-inline:active { transform: scale(0.92); opacity: 0.75; }

.btn-sm {
  padding: 4px 10px;
  font-size: 0.75rem;
}

/* --- Main Layout --- */
.app-main { flex: 1; padding: 20px 0; }

.profile-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

/* --- Card --- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

/* --- Form Fields --- */
.field { margin-bottom: 12px; }

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 24px;
}

.meta-col {
  display: flex;
  flex-direction: column;
}

/* Comments at bottom of right col: fill remaining height */
.meta-col .field-comments {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-top: 0;
}

.meta-col .field-comments textarea {
  flex: 1;
  resize: none;
  min-height: 60px;
}

@media (max-width: 640px) {
  .meta-grid { grid-template-columns: 1fr; }
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.875rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  box-sizing: border-box;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  line-height: 36px;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  line-height: normal;  /* override shared rule — prevents descender clipping */
  padding-top: 0;
  padding-bottom: 0;
}
input[type="date"],
input[type="time"] {
  line-height: normal;
}
textarea {
  height: auto;
  padding: 8px 10px;
}

/* Hide number input spinners for consistent look */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

input.readonly, input[readonly] {
  background: var(--color-readonly);
  cursor: default;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7685' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.coord-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.input-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-group input { flex: 1; }

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab {
  padding: 10px 18px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--transition), background var(--transition),
              border-color var(--transition), opacity 80ms ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
.tab:active { opacity: 0.65; }

.tab:hover { color: var(--color-text); background: var(--color-row-hover); }
.tab.active {
  color: var(--color-tab-active);
  border-bottom-color: var(--color-tab-active);
}

.tab-panel { min-height: 200px; }
.tab-panel[hidden] { display: none; }

/* --- Data Tables --- */
.data-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.data-table th {
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.01em;
  color: var(--color-text-muted);
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
  background: var(--color-surface);
  position: sticky;
  top: 0;
}

.data-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.data-table tbody tr:nth-child(even) { background: var(--color-row-alt); }
.data-table tbody tr:hover { background: var(--color-row-hover); }

.data-table .actions {
  white-space: nowrap;
  text-align: right;
}

.data-table .actions button {
  background: none;
  border: none;
  padding: 4px 6px;
  cursor: pointer;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  font-family: inherit;
}

.data-table .actions button:hover { color: var(--color-text); background: var(--color-surface-alt); }
.data-table .actions button.delete:hover { color: var(--color-danger); }

/* --- Inline Entry Form --- */
.entry-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  align-items: flex-end;
}

.entry-form .field {
  margin-bottom: 0;
  min-width: 80px;
  flex: 1;
}

.entry-form .field label {
  font-size: 0.6875rem;
  margin-bottom: 2px;
}

.entry-form input,
.entry-form select {
  padding: 6px 8px;
  font-size: 0.8125rem;
}

.form-error {
  grid-column: 1 / -1;
  color: #e05252;
  font-size: 0.8rem;
  padding: 2px 0;
}

/* Title row inside the entry form (e.g. "Create New Layer") */
.entry-form-title {
  flex: 0 0 100%;
  width: 100%;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  padding-bottom: 2px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 2px;
}

.entry-form .entry-actions {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

/* --- Custom Select / Dropdown Picker --- */
.picker-wrap {
  position: relative;
}

.picker-btn {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color var(--transition);
}

.picker-btn:focus-visible {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
  outline: none;
}

.picker-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 240px;
  overflow-y: auto;
  display: none;
}

.picker-dropdown.open { display: block; }

.picker-option {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 0.8125rem;
  transition: background var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

.picker-option:hover { background: var(--color-row-hover); }
.picker-option.selected { background: rgba(37, 99, 235, 0.08); font-weight: 500; }

.picker-option .grain-symbol {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--color-surface-alt);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

/* --- Radio Toggle (for density entry type) --- */
.toggle-group {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 12px;
}

.toggle-group label {
  padding: 6px 14px;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--color-text-muted);
  border-right: 1px solid var(--color-border);
  transition: all var(--transition);
  margin: 0;
}

.toggle-group label:last-child { border-right: none; }
.toggle-group input[type="radio"] { display: none; }
.toggle-group input[type="radio"]:checked + label {
  background: var(--color-primary);
  color: var(--color-primary-text);
}

/* --- Parametrize Button --- */
.parametrize-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}
.parametrize-wrap[hidden] {
  display: none;
}

/* --- Ram Profile Start Fields --- */
.ram-start {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}

@media (max-width: 480px) {
  .ram-start { grid-template-columns: 1fr; }
}

/* --- Collapsible Weather --- */
.weather-details {
  margin-bottom: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0;
}
.weather-details summary {
  padding: 8px 12px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.weather-details summary::-webkit-details-marker { display: none; }
.weather-details summary::before {
  content: '';
  display: inline-block;
  width: 0; height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
}
.weather-details[open] summary::before {
  transform: rotate(90deg);
}
.weather-details > .meta-grid {
  padding: 4px 12px 8px;
}

/* --- Comments field --- */
.field-comments {
  margin-top: 4px;
}
.field-comments textarea {
  min-height: 60px;
  resize: vertical;
}

/* --- Map Dialog --- */
.map-dialog {
  border: none;
  border-radius: var(--radius-xl);
  padding: 0;
  width: min(90vw, 800px);
  max-height: 90vh;
  box-shadow: var(--shadow-xl);
  background: var(--color-surface);
  color: var(--color-text);
}

.map-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.dialog-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
}

.dialog-header h2 { margin: 0; }
.dialog-header .hint { color: var(--color-text-muted); font-size: 0.8125rem; margin-top: 2px; }

.map-container {
  height: 400px;
  width: 100%;
}

.dialog-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* --- Confirm Dialog --- */
#confirm-dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  width: min(90vw, 400px);
  box-shadow: var(--shadow-xl);
  background: var(--color-surface);
  color: var(--color-text);
}

#confirm-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

#confirm-dialog p { padding: 16px 20px; }

/* --- Preview Dialog --- */
.preview-dialog {
  border: none;
  border-radius: var(--radius-xl);
  padding: 0;
  width: min(95vw, 1300px);
  height: 97vh;
  max-height: 97vh;
  box-shadow: var(--shadow-xl);
  background: #fff;
  color: var(--color-text);
  margin: auto;
  inset: 0;
  overflow: hidden;
}

.preview-dialog[open] {
  display: flex;
  flex-direction: column;
}

.preview-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.preview-dialog .dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.preview-controls {
  flex: 1;
  display: flex;
  justify-content: center;
}
.preview-controls select {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  font-size: 0.875rem;
}

.preview-dialog .btn-close-dialog {
  font-size: 1.5rem;
  line-height: 1;
  border: none;
  padding: 4px 8px;
}

.preview-body {
  padding: 12px 20px;
  overflow: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.preview-body svg {
  border: 1px solid #ccc;
  width: 100%;
  height: calc(97vh - 90px);
  background: #fff;
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--color-text-muted);
}

.empty-state svg {
  margin-bottom: 8px;
  opacity: 0.4;
}

.empty-state p { font-size: 0.875rem; }

/* --- Footer --- */
.app-footer {
  text-align: center;
  padding: 16px;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
}

/* --- Mobile dark mode button (bottom-right) --- */
.btn-theme-mobile {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  align-items: center;
  justify-content: center;
  padding: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 80ms ease, opacity 80ms ease, box-shadow var(--transition);
}
.btn-theme-mobile:active { transform: scale(0.88); opacity: 0.75; }

/* --- Utility --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* --- Mobile Optimizations --- */
@media (max-width: 768px) {
  /* Header: compact */
  .header-inner { height: 48px; padding: 0 12px; gap: 8px; }
  .brand h1 { font-size: 0.95rem; }
  .brand .logo { height: 26px; }

  /* Hide theme toggle from header, show floating button instead */
  #btn-theme { display: none; }
  .btn-theme-mobile { display: flex; }

  /* Buttons: touch-friendly */
  .btn { padding: 8px 12px; font-size: 0.8125rem; min-height: 40px; }
  .btn-sm { padding: 6px 10px; min-height: 36px; }
  .btn-icon { padding: 8px; min-height: 40px; min-width: 40px; }
  .header-actions .btn svg { flex-shrink: 0; }

  /* Main layout */
  .app-main { padding: 12px 0; }
  .container { padding: 0 10px; width: 100%; }
  .profile-grid { gap: 12px; }

  /* Cards: tighter on mobile */
  .card { padding: 12px; border-radius: var(--radius-md); }

  /* Form fields: 16px prevents iOS zoom on focus */
  input[type="text"],
  input[type="email"],
  input[type="number"],
  input[type="date"],
  input[type="time"],
  select { height: 42px; font-size: 16px; line-height: normal; }
  textarea { font-size: 16px; }
  label { font-size: 0.75rem; }
  .field { margin-bottom: 10px; }

  /* Inputs must not overflow their container */
  input, select, textarea { max-width: 100%; box-sizing: border-box; }

  /* Tabs: scrollable, compact, hide scrollbar chrome */
  .tabs { gap: 0; margin-bottom: 12px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 8px 10px; font-size: 0.75rem; }

  /* Data tables: compact but horizontally scrollable */
  .data-table-wrap { -webkit-overflow-scrolling: touch; }
  .data-table { font-size: 0.75rem; }
  .data-table th { padding: 6px 6px; font-size: 0.6875rem; }
  .data-table td { padding: 5px 6px; }

  /* Bigger edit/delete touch targets on mobile */
  .data-table .actions button {
    padding: 8px 10px;
    font-size: 1.05rem;
    min-height: 44px;
    min-width: 36px;
  }

  /* Entry forms */
  .entry-form { gap: 8px; }
  .entry-form .field { min-width: 0; }

  /* Details/Weather section */
  details summary { font-size: 0.8125rem; }

  /* Preview dialog: full-screen on mobile */
  .preview-dialog {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    inset: 0;
    margin: 0;
  }
  .preview-body { padding: 8px; }
  .preview-body svg { height: calc(100vh - 70px); width: auto; max-width: 100%; }

  /* Map dialog */
  .map-dialog { width: 95vw; }
  .map-container { height: 300px; }
}

@media (max-width: 640px) {
  /* Header: hide button text labels, icon only */
  .header-actions .btn-text { display: none; }
  #btn-preview,
  #btn-export-caaml { padding: 8px 10px; min-width: 40px; justify-content: center; }

  /* Coordinate group */
  .coord-group { grid-template-columns: 1fr 1fr; gap: 6px; }

  /* Weather grid */
  .weather-grid { grid-template-columns: 1fr !important; }

  /* Layer entry form: structured rows — use minmax(0,1fr) so cells can shrink */
  .layer-entry-form {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    flex-wrap: unset;
    width: 100%;
  }
  .layer-entry-form .field {
    width: auto;
    min-width: 0;
    flex: unset;
  }
  /* Moisture (Θ) + Hardness (K): full width */
  .layer-entry-form .field[data-layer-group="moisture"],
  .layer-entry-form .field[data-layer-group="hardness"] {
    grid-column: 1 / -1;
  }
  /* Actions row and title: full width */
  .layer-entry-form .entry-actions,
  .layer-entry-form .entry-form-title {
    grid-column: 1 / -1;
  }
  /* Ensure selects & inputs don't overflow their grid cell */
  .layer-entry-form select,
  .layer-entry-form input {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  /* Other entry forms: full width stacked */
  .entry-form:not(.layer-entry-form) { flex-direction: column; }
  .entry-form:not(.layer-entry-form) .field { width: 100%; min-width: unset; }

  /* Stability test forms */
  .stb-entry { flex-direction: column; }
  .stb-entry .field { width: 100%; }

  /* Meta grid: single column */
  .meta-grid { grid-template-columns: 1fr !important; }
  .meta-col { min-width: 0; }
}

@media (max-width: 360px) {
  .brand h1 { display: none; }
  .header-inner { height: 44px; }
  .card { padding: 10px; }
  .container { padding: 0 8px; }
}

/* --- Print --- */
@media print {
  .app-header, .app-footer, .header-actions, .entry-form, .actions { display: none !important; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .profile-grid { grid-template-columns: 1fr; }
}
