@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500&family=Outfit:wght@700&display=swap');

:root {
  --bg-primary: #f5f5f7;
  --bg-secondary: #ffffff;
  --bg-tertiary: #eeeef0;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --accent: #00b368;
  --accent-hover: #009957;
  --accent-dim: rgba(0, 179, 104, 0.08);
  --border: rgba(0, 0, 0, 0.08);
  --transition: 0.3s ease;
  --radius: 12px;
  --sidebar-width: 240px;
  --icon-primary: #121331;
  --icon-secondary: #08a88a;
}

[data-theme="dark"] {
  --bg-primary: #0a0a0a;
  --bg-secondary: #111111;
  --bg-tertiary: #1a1a1a;
  --text-primary: #ffffff;
  --text-secondary: #888888;
  --accent: #00FF88;
  --accent-hover: #00cc6a;
  --accent-dim: rgba(0, 255, 136, 0.1);
  --border: rgba(255, 255, 255, 0.08);
  --icon-primary: #ffffff;
  --icon-secondary: #00FF88;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  height: 100vh;
  overflow: hidden;
}

/* ===== LAYOUT ===== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: auto 1fr;
  height: 100vh;
}

/* ===== HEADER ===== */
.header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.header__logo {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.5px;
  white-space: nowrap;
  margin-right: auto;
}

.header__logo span {
  color: var(--accent);
}

.header__right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header__search {
  position: relative;
  width: 280px;
}

.header__search input {
  width: 100%;
  padding: 0.5rem 1rem 0.5rem 2.5rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  outline: none;
  transition: var(--transition);
}

.header__search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.header__search input::placeholder {
  color: var(--text-secondary);
}

.header__search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 0.875rem;
  pointer-events: none;
}

/* ===== STATS (below header, in main) ===== */
.main__stats {
  font-size: 0.75rem;
  color: var(--text-secondary);
  padding: 0 0.25rem;
}

/* ===== HAMBURGER ===== */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  padding: 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}

.hamburger span {
  display: block;
  height: 2px;
  background: var(--text-secondary);
  border-radius: 2px;
  transition: var(--transition);
}

.hamburger:hover span {
  background: var(--accent);
}

/* ===== SIDEBAR OVERLAY (mobile) ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 29;
}

/* ===== SIDEBAR ===== */
.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0.75rem 0;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 4px; }

.sidebar__title {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-secondary);
  padding: 0.5rem 1rem 0.25rem;
}

.sidebar__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 1rem;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-secondary);
  transition: var(--transition);
  border-left: 2px solid transparent;
}

.sidebar__item:hover {
  color: var(--text-primary);
  background: var(--accent-dim);
}

.sidebar__item.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-left-color: var(--accent);
}

.sidebar__item-count {
  font-size: 0.7rem;
  color: var(--text-secondary);
  opacity: 0.5;
}

.sidebar__item.active .sidebar__item-count {
  color: var(--accent);
  opacity: 0.7;
}

/* ===== MAIN CONTENT ===== */
.main {
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.main::-webkit-scrollbar { width: 6px; }
.main::-webkit-scrollbar-track { background: transparent; }
.main::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 4px; }

/* ===== ICON GRID ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.5rem;
}

.grid__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 0.5rem 0.6rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.grid__item:hover {
  border-color: var(--accent);
  background: var(--bg-tertiary);
  transform: translateY(-1px);
}

.grid__item.active {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.grid__item lord-icon {
  width: 96px;
  height: 96px;
  display: block;
}

.grid__item-title {
  font-size: 0.65rem;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 0.4rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.grid__item:hover .grid__item-title {
  color: var(--text-primary);
}

.grid__item.active .grid__item-title {
  color: var(--accent);
}

/* ===== DETAIL PANEL (right sidebar) ===== */
.detail {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 20;
  overflow-y: auto;
  overflow-x: hidden;
}

.detail.open {
  transform: translateX(0);
}

.detail::-webkit-scrollbar { width: 4px; }
.detail::-webkit-scrollbar-track { background: transparent; }
.detail::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 4px; }

.detail__inner {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.detail__close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.5rem;
  transition: var(--transition);
  z-index: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.detail__close:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

/* Preview */
.detail__preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2.5rem 0 0.75rem;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  margin: 0 -0.25rem;
}

.detail__preview lord-icon {
  width: 160px;
  height: 160px;
}

.detail__preview-title {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  padding-bottom: 0.75rem;
}

/* Controls */
.detail__controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.detail__section-title {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-secondary);
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.detail__colors {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.detail__row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.detail__label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  min-width: 80px;
}

.detail__color-picker {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  padding: 0;
  flex-shrink: 0;
}

.detail__color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.detail__color-picker::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

.detail__color-hex {
  font-family: monospace;
  font-size: 0.75rem;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 6px;
  width: 72px;
  height: 28px;
  outline: none;
}
.detail__color-hex:focus {
  border-color: var(--accent);
}

/* Pill buttons */
.pills {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.pill {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.7rem;
  transition: var(--transition);
}

.pill:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

.pill.active {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
  font-weight: 500;
}

/* Export section */
.detail__export {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.detail__code {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-family: 'DM Mono', monospace;
  font-size: 0.6rem;
  color: var(--accent);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 140px;
  overflow-y: auto;
  line-height: 1.5;
}

.detail__actions {
  display: flex;
  gap: 0.5rem;
}

.detail__copy-btn,
.detail__download-btn {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  font-size: 0.75rem;
  transition: var(--transition);
}

.detail__copy-btn {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

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

.detail__download-btn {
  background: var(--accent);
  color: var(--bg-primary);
}

.detail__download-btn:hover {
  background: var(--accent-hover);
}

/* ===== LOADING / EMPTY ===== */
.loading, .empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.loading::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 0.75rem;
}

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

/* ===== THEME TOGGLE ===== */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: var(--transition);
  flex-shrink: 0;
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.logout-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: var(--transition);
  flex-shrink: 0;
}

.logout-btn:hover {
  color: #ff5050;
  border-color: rgba(255, 80, 80, 0.4);
}

/* ===== FAMILY / STYLE SWITCHER ===== */
.family-switcher {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.family-group {
  margin-bottom: 0.5rem;
}

.family-group:last-child {
  margin-bottom: 0;
}

.family-group__title {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-secondary);
  padding: 0.3rem 0.25rem 0.25rem;
}

.family-group__styles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
}

.style-tab {
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.65rem;
  transition: var(--transition);
  text-align: center;
}

.style-tab:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

.style-tab.active {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
  font-weight: 500;
}

.style-tab.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.style-tab.disabled:hover {
  color: var(--text-secondary);
  border-color: var(--border);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
  }

  .hamburger {
    display: flex;
  }

  .header__search {
    width: auto;
    flex: 1;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    width: var(--sidebar-width);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .detail { width: 100%; }
}
