/* ==========================================================================
   Design System & CSS Variables
   ========================================================================== */
:root {
  /* Color Palette */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;

  --bg-color: #f5f7fb;
  --card-bg: #ffffff;

  --text-main: #111827;
  --text-muted: #64748b;

  --border-color: #e5e7eb;
  --border-hover: #d1d5db;

  --success: #10b981;
  --danger: #ef4444;
  --danger-hover: #dc2626;

  /* Interactive States */
  --tool-hover: #f3f4f6;
  --tool-active: #eff6ff;
  --tool-active-color: #2563eb;

  /* Shadows for Depth */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md:
    0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg:
    0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

  /* Border Radii */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* Spacing Scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  /* Animation Timings */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  overflow: hidden; /* Prevent body scroll, gives app-like feel */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 600;
  color: var(--text-main);
}

/* Material Icons configuration */
.material-symbols-outlined {
  font-variation-settings:
    "FILL" 0,
    "wght" 400,
    "GRAD" 0,
    "opsz" 24;
  user-select: none;
}

/* ==========================================================================
   Main Application Layout
   ========================================================================== */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ==========================================================================
   Topbar (Header)
   ========================================================================== */
.topbar {
  height: 56px;
  background-color: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.topbar-left,
.topbar-center,
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-right: var(--space-4);
  cursor: pointer;
}

.logo-icon {
  color: var(--primary);
  font-size: 28px;
  transition: transform var(--transition-fast);
}

.logo:hover .logo-icon {
  transform: scale(1.1) rotate(-5deg);
}

.logo-text {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.board-info {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.board-title {
  font-size: 0.95rem;
  font-weight: 500;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-fast);
  outline: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
}

.board-title:hover,
.board-title:focus {
  background-color: var(--tool-hover);
}

.badge {
  font-size: 0.75rem;
  background-color: var(--border-color);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 500;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color var(--transition-fast);
}

.avatar:hover {
  border-color: var(--primary);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ==========================================================================
   UI Components: Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn .material-symbols-outlined {
  font-size: 18px;
}

.btn.primary {
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  color: white;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

.btn.primary:hover {
  background: linear-gradient(135deg, var(--primary-hover), #2563eb);
  box-shadow: 0 4px 6px rgba(37, 99, 235, 0.3);
  transform: translateY(-1px);
}

.btn.primary:active {
  transform: translateY(0);
}

.btn.secondary {
  background-color: var(--card-bg);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn.secondary:hover {
  background-color: var(--tool-hover);
  border-color: var(--border-hover);
}

.btn.danger {
  background-color: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn.danger:hover {
  background-color: var(--danger-hover);
  color: white;
  border-color: var(--danger-hover);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background-color: var(--tool-hover);
  color: var(--text-main);
}

.icon-btn.small {
  width: 28px;
  height: 28px;
}

.icon-btn.small .material-symbols-outlined {
  font-size: 18px;
}

/* ==========================================================================
   Left Sidebar Toolbar
   ========================================================================== */
.toolbar-left {
  width: 64px;
  background-color: var(--card-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-3) 0;
  gap: var(--space-3);
  z-index: 5;
  box-shadow: 1px 0 2px rgba(0, 0, 0, 0.02);
}

.tool-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.tool-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

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

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

.divider {
  width: 1px;
  height: 24px;
  background-color: var(--border-color);
}

.divider-horizontal {
  width: 32px;
  height: 1px;
  background-color: var(--border-color);
  margin: var(--space-1) 0;
}

/* ==========================================================================
   Right Sidebar Properties Panel
   ========================================================================== */
.properties-right {
  width: 260px;
  background-color: var(--card-bg);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 5;
  box-shadow: -1px 0 2px rgba(0, 0, 0, 0.02);
  overflow-y: auto;
}

.panel-section {
  padding: var(--space-4);
}

.panel-section h3 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: var(--space-4);
  font-weight: 600;
}

.property-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
  gap: var(--space-3);
}

.property-row label {
  font-size: 0.85rem;
  color: var(--text-main);
  font-weight: 500;
}

/* Custom Color Picker */
.color-picker-wrapper {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-color);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

input[type="color"] {
  width: 150%;
  height: 150%;
  margin: -25%;
  border: none;
  padding: 0;
  cursor: pointer;
}

/* Color Presets Palette */
.preset-colors {
  justify-content: flex-start;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.color-preset {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition:
    transform var(--transition-fast),
    outline-color var(--transition-fast);
}

.color-preset:hover {
  transform: scale(1.15);
}

.color-preset.active {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Custom Sliders */
.slider {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  background: var(--border-color);
  border-radius: var(--radius-full);
  outline: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: var(--shadow-md);
}

.value-display {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* Select Dropdown */
.font-select {
  width: 100%;
  padding: 8px var(--space-2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text-main);
  background-color: var(--card-bg);
  outline: none;
  cursor: pointer;
}

.font-select:focus {
  border-color: var(--primary);
}

.full-width {
  width: 100%;
}

.action-btn {
  margin-bottom: var(--space-2);
}

.action-btn:last-child {
  margin-bottom: 0;
}

/* Canvas container placeholder - actual canvas styles in canvas.css */
.canvas-container {
  flex: 1;
}

/* ==========================================================================
   Bottom Status Bar
   ========================================================================== */
.statusbar {
  height: 32px;
  background-color: var(--card-bg);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  font-size: 0.75rem;
  color: var(--text-muted);
  z-index: 10;
}

.status-left,
.status-center,
.status-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.status-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 500;
}

/* Connection Indicator */
.indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--border-color);
}

.connection.online .indicator {
  background-color: var(--success);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.autosave-status {
  color: var(--text-muted);
  font-style: italic;
}

.status-btn {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: 4px;
  transition: all var(--transition-fast);
}

.status-btn:hover {
  background-color: var(--tool-hover);
  color: var(--text-main);
}

.status-btn.active {
  color: var(--primary);
}

.status-btn .material-symbols-outlined {
  font-size: 16px;
}

.coordinates {
  font-variant-numeric: tabular-nums;
  min-width: 85px;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */
@media (max-width: 992px) {
  .board-title {
    max-width: 150px;
  }
}

@media (max-width: 768px) {
  .topbar-center {
    display: none; /* Hide middle undo/redo actions on small screens */
  }

  .properties-right {
    display: none; /* In a real app, this would be a toggle drawer */
  }

  .statusbar {
    display: none;
  }
}

/* ==========================================================================
   Background Picker Modal
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background-color: var(--card-bg);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px) scale(0.95);
  transition: all var(--transition-fast);
}

.modal-overlay.active .modal-content {
  transform: translateY(0) scale(1);
}

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

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-body {
  padding: var(--space-5);
  overflow-y: auto;
}

.bg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--space-4);
}

.bg-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  transition: all var(--transition-fast);
  background-color: transparent;
}

.bg-card:hover {
  background-color: var(--tool-hover);
}

.bg-card.active {
  border-color: var(--primary);
  background-color: var(--tool-active);
}

.bg-card:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.bg-preview {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.bg-name {
  font-size: 0.75rem;
  font-weight: 500;
  text-align: center;
  color: var(--text-main);
}
