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

html, body {
  height: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
}

/* ===== Design Tokens ===== */
:root {
  --color-forest: #2d5016;
  --color-forest-light: #3d6b20;
  --color-forest-dark: #1e3a0e;
  --color-earth: #8B6914;
  --color-cream: #f5f0e1;
  --color-parchment: #ede8d5;
  --color-terracotta: #c1440e;
  --color-terracotta-light: #d4581f;
  --color-sage: #a8c090;
  --color-sage-light: #c5d4b3;
  --color-soil: #5c4033;
  --color-soil-light: #8b7355;

  --bg-app: var(--color-cream);
  --bg-sidebar: var(--color-forest);
  --bg-header: var(--color-forest-dark);
  --bg-space: #ffffff;
  --bg-cell: var(--color-parchment);
  --bg-cell-hover: var(--color-sage-light);
  --border-cell: var(--color-soil-light);
  --text-primary: #2c2c2c;
  --text-light: var(--color-cream);
  --text-sidebar: var(--color-cream);
  --accent: var(--color-terracotta);

  --font-heading: 'Merriweather', Georgia, serif;
  --font-body: 'Inter', -apple-system, sans-serif;

  --cell-size: 52px;
  --space-gap: 24px;
  --sidebar-width: 260px;
  --border-radius: 8px;
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

/* ===== Typography ===== */
h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 700;
}

/* ===== Layout ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-header);
  color: var(--text-light);
  border-bottom: 3px solid var(--color-earth);
}

.app-title {
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  gap: 4px;
}

.app-icon {
  font-size: 1.6rem;
}

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: calc(100vh - 57px);
}

.sidebar {
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  padding: 16px;
  overflow-y: auto;
  border-right: 3px solid var(--color-earth);
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: var(--color-forest-dark);
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--color-soil-light);
  border-radius: 3px;
}

.main-area {
  padding: var(--space-gap);
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-gap);
  align-items: flex-start;
  align-content: flex-start;
}

.main-area::-webkit-scrollbar {
  width: 8px;
}

.main-area::-webkit-scrollbar-track {
  background: var(--color-parchment);
}

.main-area::-webkit-scrollbar-thumb {
  background: var(--color-soil-light);
  border-radius: 4px;
}

/* ===== Buttons ===== */
.btn {
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 8px 16px;
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

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

.btn-primary {
  background: var(--color-terracotta);
  color: white;
}

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

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

.btn-secondary:hover {
  background: var(--color-sage-light);
}

.btn-danger {
  background: #c0392b;
  color: white;
}

.btn-danger:hover {
  background: #e74c3c;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  font-size: 1rem;
  opacity: 0.6;
  transition: opacity var(--transition-fast);
  line-height: 1;
}

.btn-icon:hover {
  opacity: 1;
}

/* ===== Sidebar Sections ===== */
.sidebar-section {
  margin-bottom: 20px;
}

.sidebar-section-title {
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-sage);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--color-forest-light);
}

.sidebar-tool-row {
  display: flex;
  gap: 6px;
  margin-bottom: 4px;
}

.tool-btn {
  flex: 1;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 10px;
  border: 1px solid var(--color-forest-light);
  border-radius: 6px;
  background: transparent;
  color: var(--text-sidebar);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}

.tool-btn:hover {
  background: var(--color-forest-light);
}

.tool-btn.active {
  background: var(--color-terracotta);
  border-color: var(--color-terracotta);
  color: white;
}

.plant-list {
  list-style: none;
}

.plant-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--transition-fast);
  font-size: 0.85rem;
  user-select: none;
}

.plant-item:hover {
  background: var(--color-forest-light);
}

.plant-item.selected {
  background: var(--color-terracotta);
  border-left: 3px solid var(--color-cream);
}

.plant-item.highlighted {
  background: var(--color-forest-light);
  box-shadow: inset 0 0 0 1px var(--color-sage);
}

.plant-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.plant-emoji {
  font-size: 1rem;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.plant-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plant-count {
  font-size: 0.75rem;
  opacity: 0.7;
  background: var(--color-forest-dark);
  padding: 1px 6px;
  border-radius: 10px;
}

/* Custom plant form */
.custom-plant-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.custom-plant-form input[type="text"] {
  font-family: var(--font-body);
  font-size: 0.8rem;
  padding: 6px 8px;
  border: 1px solid var(--color-forest-light);
  border-radius: 6px;
  background: var(--color-forest-dark);
  color: var(--text-sidebar);
  outline: none;
}

.custom-plant-form input[type="text"]:focus {
  border-color: var(--color-sage);
}

.custom-plant-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.custom-plant-form input[type="color"] {
  width: 32px;
  height: 28px;
  border: 1px solid var(--color-forest-light);
  border-radius: 4px;
  background: var(--color-forest-dark);
  cursor: pointer;
  padding: 2px;
}

.custom-plant-form .btn {
  font-size: 0.8rem;
  padding: 6px 12px;
}

/* ===== Space Cards ===== */
.space-card {
  background: var(--bg-space);
  border-radius: var(--border-radius);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  border: 1px solid var(--color-sage);
}

.space-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--color-forest);
  color: var(--text-light);
}

.space-name {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
}

.space-dims {
  font-weight: 400;
  opacity: 0.7;
  font-size: 0.75rem;
}

.space-actions {
  display: flex;
  gap: 2px;
}

.space-actions .btn-icon {
  color: var(--text-light);
  font-size: 0.85rem;
}

/* ===== Cell Grid ===== */
.space-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell-size));
  grid-template-rows: repeat(var(--rows), var(--cell-size));
  border-top: 1px solid var(--border-cell);
  border-left: 1px solid var(--border-cell);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-right: 1px solid var(--border-cell);
  border-bottom: 1px solid var(--border-cell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  cursor: cell;
  transition: background var(--transition-fast);
  user-select: none;
  position: relative;
}

.cell.empty {
  background: var(--bg-cell);
}

.cell.empty:hover {
  background: var(--bg-cell-hover);
}

.cell.occupied {
  background: var(--bg-cell);
}

.cell.highlighted {
  box-shadow: inset 0 0 0 2px var(--accent), 0 0 8px rgba(193, 68, 14, 0.4);
  z-index: 1;
}

.cell.erase-mode {
  cursor: crosshair;
}

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 40px;
  text-align: center;
  color: var(--color-soil-light);
  width: 100%;
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-state-title {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  color: var(--color-soil);
  margin-bottom: 8px;
}

.empty-state-text {
  font-size: 0.9rem;
  max-width: 300px;
}

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 150ms ease;
}

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

.modal-dialog {
  background: var(--bg-space);
  border-radius: var(--border-radius);
  padding: 24px;
  min-width: 340px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  border: 2px solid var(--color-sage);
  animation: slideUp 200ms ease;
}

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

.modal-title {
  font-size: 1.1rem;
  color: var(--color-forest);
  margin-bottom: 16px;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-soil);
}

.modal-form input {
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: 8px 10px;
  border: 1px solid var(--color-sage);
  border-radius: 6px;
  outline: none;
  transition: border-color var(--transition-fast);
}

.modal-form input:focus {
  border-color: var(--color-forest);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

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

:focus-visible {
  outline: 2px solid var(--color-terracotta);
  outline-offset: 2px;
}
