/* =============================================================
   Iris Dashboard — Aligned Design Language (Light Mode)
   ============================================================= */

@view-transition {
  navigation: auto;
}

:root {
  /* Aligned Design Tokens */
  --bg-primary: #FFFFFF;
  --bg-secondary: #F8F9FA;
  --bg-tertiary: #F1F3F4;
  --bg-hover: #EEEEF0;

  --text-primary: #0D0D0D;
  --text-secondary: #374151;
  --text-muted: #6B7280;
  --text-subtle: #9CA3AF;

  --accent: #9147FF; /* Twitch Purple */
  --accent-hover: #772CE8;
  --accent-light: rgba(145, 71, 255, 0.1);
  --accent-border: rgba(145, 71, 255, 0.25);

  --border: #E5E7EB;
  --border-strong: #D1D5DB;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.10);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 999px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Iris-specific overrides mapped to design system variables */
  --bg-dark: var(--bg-primary);
  --bg-panel: var(--bg-secondary);
  --bg-canvas: var(--bg-tertiary);
  --glass-bg: var(--bg-primary);
  --glass-border: var(--border);
  --danger: #DC2626;
  --text-light: var(--text-primary);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Typography */
h1, h2, h3, h4 {
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

/* Layout */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* =============================================================
   NAVIGATION
   ============================================================= */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  gap: 16px;
  width: 90%;
  max-width: 1200px;
  margin: 0 auto;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  text-decoration: none;
}

.nav-logo-icon {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all var(--transition);
  text-decoration: none;
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--accent-light);
  color: var(--accent);
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: border-color var(--transition);
}
.nav-avatar:hover {
  border-color: var(--border-strong);
}

/* Sub-Navigation for Iris Views */
.sub-nav {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.sub-nav-inner {
  display: flex;
  align-items: center;
  height: 48px;
  width: 90%;
  max-width: 1200px;
  margin: 0 auto;
}

.sub-nav .nav-links {
  display: flex;
  gap: 8px;
}

.sub-nav .nav-link {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.sub-nav .nav-link.active {
  background: var(--accent-light);
  color: var(--accent);
}

/* User dropdown dropdown menu */
#kn-user-dropdown {
  position: relative;
}
#kn-user-menu {
  position: absolute;
  right: 0;
  top: 120%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  width: 180px;
  display: none;
  overflow: hidden;
  z-index: 200;
}
#kn-user-menu.active {
  display: block;
}
.kn-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 16px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--bg-secondary);
  transition: background var(--transition);
  background: none;
  border: none;
  cursor: pointer;
}
.kn-menu-item:hover { background: var(--bg-hover); }
.kn-menu-item.logout { color: #DC2626; }
.kn-menu-item.logout:hover { background: #FEF2F2; }


/* =============================================================
   MAIN CONTENT
   ============================================================= */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Top Bar */
#topbar {
  height: 56px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 16px;
}

#topbar .left,
#topbar .right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#topbar h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px var(--accent-light);
}

.btn-cyan {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent-border);
}
.btn-cyan:hover {
  background: rgba(145, 71, 255, 0.2);
}

.btn-danger {
  background: #FEF2F2;
  color: #DC2626;
  border-color: #FECACA;
}
.btn-danger:hover {
  background: #FEE2E2;
}

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-hover); }

input, select, textarea {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.85rem;
  width: 100%;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

input::placeholder { color: var(--text-subtle); }

/* =============================================================
   WORKSPACE
   ============================================================= */
#workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Canvas Area */
#canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  padding: 24px;
  overflow: auto;
}

#canvas-wrapper {
  position: relative;
  box-shadow: var(--shadow-lg);
  background: white;
  border: 1px solid var(--border);
}

#canvas {
  position: relative;
  width: 1920px;
  height: 1080px;
  transform-origin: top left;
  background: transparent;
  overflow: hidden;
}

#canvas.has-grid {
  background-image:
    linear-gradient(rgba(0,0,0,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
}

/* Canvas Element */
.canvas-element {
  position: absolute;
  cursor: grab;
  user-select: none;
  border: 1px solid transparent;
  overflow: hidden;
}

.canvas-element:hover {
  border-color: var(--accent-border);
}

.canvas-element.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
  z-index: 9999 !important;
}

.canvas-element.dragging {
  cursor: grabbing;
  opacity: 0.9;
}

/* Resize handles */
.resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  display: none;
  z-index: 10000;
}

.canvas-element.selected .resize-handle {
  display: block;
}

.resize-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.resize-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.resize-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.resize-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }

/* Element content preview in canvas */
.el-preview {
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-radius: 4px;
  padding: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}

/* =============================================================
   PROPERTIES PANEL
   ============================================================= */
#properties-panel {
  width: 300px;
  min-width: 300px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

#properties-panel .panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.95rem;
}

#properties-panel .panel-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* =============================================================
   OVERLAY LIST VIEW
   ============================================================= */
#overlay-list {
  padding: 32px 24px;
  overflow-y: auto;
  max-width: 1200px;
  margin: 0 auto;
  width: 90%;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
}

.card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: all var(--transition);
  cursor: pointer;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card .card-title {
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.card .card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

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

.card-new {
  border-style: dashed;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  color: var(--text-muted);
}

.card-new:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* =============================================================
   ELEMENT LIBRARY
   ============================================================= */
#element-library {
  height: 180px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

#element-library .lib-header {
  padding: 12px 20px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#element-library .lib-items {
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  overflow-x: auto;
  flex: 1;
  align-items: center;
}

.lib-item {
  min-width: 100px;
  height: 80px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: grab;
  transition: all var(--transition);
  padding: 8px;
  text-align: center;
}

.lib-item:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.lib-item i {
  font-size: 1.4rem;
  color: var(--accent);
}

.lib-item span {
  font-size: 0.75rem;
  font-weight: 600;
}

/* =============================================================
   MODAL
   ============================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 480px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.modal h3 {
  margin-bottom: 16px;
}

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

/* =============================================================
   TOAST
   ============================================================= */
.toast-container {
  position: fixed;
  top: 80px; /* shift down to not cover navigation */
  right: 20px;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  min-width: 240px;
  font-size: 0.9rem;
  box-shadow: var(--shadow-md);
  animation: slideInRight 0.3s ease;
  color: var(--text-primary);
}

.toast.success { border-left-color: #1DB954; }
.toast.error { border-left-color: var(--danger); }

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

/* =============================================================
   PRESETS GALLERY
   ============================================================= */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  padding: 32px 24px;
  max-width: 1200px;
  margin: 0 auto;
  width: 90%;
}

.preset-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
}

.preset-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.preset-card .preset-thumb {
  height: 120px;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--text-subtle);
}

.preset-card .preset-info {
  padding: 12px;
}

.preset-card .preset-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.preset-card .preset-category {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* =============================================================
   SCROLLBAR
   ============================================================= */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.2); }

/* =============================================================
   RESPONSIVE
   ============================================================= */
@media (max-width: 1200px) {
  #properties-panel { width: 260px; min-width: 260px; }
}
