/* ==========================================================================
   SnapDroid Studio VR - Scratch 3.0 Light Theme UI & Responsive Styles
   ========================================================================== */

:root {
  --scratch-bg: #F9F9FB;
  --scratch-header: #4C97FF;
  --scratch-header-dark: #3373CC;
  --scratch-sidebar: #FFFFFF;
  --scratch-border: #E5E5E5;
  --scratch-border-dark: #D1D1D1;
  --scratch-text: #575E75;
  --scratch-text-dark: #2B334D;
  --scratch-white: #FFFFFF;
  --scratch-shadow: rgba(0, 0, 0, 0.08) 0px 2px 8px;
  
  /* Category Colors (Scratch 3.0 Palette + Android/VR Additions) */
  --cat-events: #FFBF00;
  --cat-events-dark: #E6AC00;
  --cat-android: #4C97FF;
  --cat-android-dark: #3373CC;
  --cat-permissions: #FF661A;
  --cat-permissions-dark: #E65C17;
  --cat-vr: #5CB1D6;
  --cat-vr-dark: #4792B3;
  --cat-ui: #9966FF;
  --cat-ui-dark: #774DCB;
  --cat-control: #FFAB19;
  --cat-control-dark: #CF8B17;
  --cat-logic: #59C059;
  --cat-logic-dark: #389438;
  --cat-variables: #FF6680;
  --cat-variables-dark: #DB4D66;
  --cat-extensions: #0FBD8C;
  --cat-extensions-dark: #0B8E69;

  /* UI Status Colors */
  --status-success: #0FBD8C;
  --status-warning: #FFAB19;
  --status-error: #FF6680;
  --font-main: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body, html {
  width: 100%;
  height: 100%;
  font-family: var(--font-main);
  background-color: var(--scratch-bg);
  color: var(--scratch-text-dark);
  overflow: hidden;
}

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

/* --- Top Navigation Header --- */
.header-bar {
  height: 54px;
  background-color: var(--scratch-header);
  color: var(--scratch-white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.3px;
  cursor: pointer;
}

.logo-badge {
  background: var(--scratch-white);
  color: var(--scratch-header);
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.apk-name-editor {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  padding: 3px 10px;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.apk-name-editor:hover {
  background: rgba(255, 255, 255, 0.28);
}

.apk-name-editor input {
  background: transparent;
  border: none;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  width: 160px;
  outline: none;
}

.apk-name-editor input::placeholder {
  color: rgba(255,255,255,0.7);
}

.apk-pkg-badge {
  font-size: 11px;
  background: rgba(0,0,0,0.2);
  padding: 2px 6px;
  border-radius: 4px;
  color: #E2F0FF;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Header Buttons */
.btn-header {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--scratch-white);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-header:hover {
  background: rgba(255, 255, 255, 0.28);
  transform: translateY(-1px);
}

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

.btn-header.primary-action {
  background: var(--status-success);
  border-color: var(--cat-extensions-dark);
  box-shadow: 0 2px 4px rgba(15, 189, 140, 0.4);
}

.btn-header.primary-action:hover {
  background: #12cf9a;
}

.btn-header.import-action {
  background: var(--cat-permissions);
  border-color: var(--cat-permissions-dark);
}

.linter-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.9);
  color: var(--scratch-text-dark);
  padding: 5px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: all 0.2s;
}

.linter-badge:hover {
  transform: scale(1.03);
}

.linter-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--status-success);
}

.linter-dot.warning { background: var(--status-warning); }
.linter-dot.error { background: var(--status-error); }

.mode-toggle-btn {
  background: rgba(0,0,0,0.15);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* --- Main Workspace Layout --- */
.main-workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* --- Left Side: Scratch Block Palette & Category Drawer --- */
.block-drawer {
  width: 320px;
  background: var(--scratch-sidebar);
  border-right: 1px solid var(--scratch-border);
  display: flex;
  flex-direction: column;
  z-index: 10;
  box-shadow: 2px 0 6px rgba(0,0,0,0.03);
}

.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  background: #F2F4F7;
  border-bottom: 1px solid var(--scratch-border);
  max-height: 140px;
  overflow-y: auto;
}

.cat-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--scratch-white);
  border: 1px solid var(--scratch-border);
  border-radius: 16px;
  font-size: 11px;
  font-weight: 700;
  color: var(--scratch-text-dark);
  cursor: pointer;
  transition: all 0.15s ease;
}

.cat-tab:hover {
  border-color: #B8C2D4;
  background: #F9FAFC;
}

.cat-tab.active {
  color: var(--scratch-white);
  border-color: transparent;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.cat-tab .cat-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.palette-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}

.palette-section-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--scratch-text);
  margin: 12px 0 8px 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* --- Block Styling (Scratch 3.0 Look & Puzzle Notches) --- */
.block-item {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  min-height: 38px;
  padding: 8px 14px;
  margin-bottom: 8px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: grab;
  box-shadow: 0 3px 0 rgba(0,0,0,0.2);
  transition: transform 0.1s, box-shadow 0.1s;
  border-radius: 4px;
  max-width: 280px;
}

.block-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 2px rgba(0,0,0,0.25);
}

.block-item:active {
  cursor: grabbing;
}

/* Stack Block Notch & Tabs (Top / Bottom) */
.block-stack {
  border-radius: 4px;
  border-top-left-radius: 4px;
  padding-top: 10px;
  padding-bottom: 10px;
}

.block-stack::before {
  content: "";
  position: absolute;
  top: -4px;
  left: 16px;
  width: 24px;
  height: 4px;
  background: inherit;
  border-top-left-radius: 3px;
  border-top-right-radius: 3px;
}

.block-stack::after {
  content: "";
  position: absolute;
  bottom: -4px;
  left: 16px;
  width: 24px;
  height: 4px;
  background: inherit;
  border-bottom-left-radius: 3px;
  border-bottom-right-radius: 3px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.2);
}

/* Hat Block (Event Trigger) */
.block-hat {
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 4px;
  padding-top: 12px;
  padding-bottom: 10px;
}

.block-hat::after {
  content: "";
  position: absolute;
  bottom: -4px;
  left: 16px;
  width: 24px;
  height: 4px;
  background: inherit;
  border-bottom-left-radius: 3px;
  border-bottom-right-radius: 3px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.2);
}

/* Value / Reporter Block (Rounded Pills) */
.block-value {
  border-radius: 20px;
  padding: 6px 14px;
}

/* Boolean Block (Hexagon edges) */
.block-bool {
  border-radius: 8px;
  padding: 6px 14px;
}

/* Block Inputs & Sockets */
.block-input-text, .block-input-number, .block-input-select {
  background: var(--scratch-white);
  color: var(--scratch-text-dark);
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 14px;
  padding: 3px 8px;
  margin: 0 4px;
  font-size: 12px;
  font-weight: 600;
  outline: none;
  min-width: 50px;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
  user-select: text;
  -webkit-user-select: text;
}

.block-input-select {
  cursor: pointer;
  border-radius: 6px;
}

.block-input-text:focus, .block-input-number:focus {
  border-color: #4C97FF;
  box-shadow: 0 0 0 2px rgba(76, 151, 255, 0.3);
}

/* --- Middle Canvas: Block Snapping Workspace --- */
.canvas-area {
  flex: 1;
  background-color: var(--scratch-bg);
  background-image: radial-gradient(#D6DDEB 1px, transparent 1px);
  background-size: 20px 20px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.canvas-toolbar {
  height: 44px;
  background: var(--scratch-white);
  border-bottom: 1px solid var(--scratch-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
  z-index: 5;
}

.current-file-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 13px;
  color: var(--scratch-text-dark);
  background: #EEF3FA;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid #D5E1F2;
}

.canvas-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-canvas {
  background: #F0F4F8;
  border: 1px solid var(--scratch-border);
  color: var(--scratch-text-dark);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}

.btn-canvas:hover {
  background: #E2E8F0;
}

.workspace-canvas {
  flex: 1;
  position: relative;
  overflow: auto;
  min-width: 100%;
  min-height: 100%;
  cursor: default;
}

.canvas-blocks-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 4000px;
  height: 4000px;
}

/* Cloned & Snapped Block Stacks on Canvas */
.canvas-block {
  position: absolute;
  cursor: grab;
  z-index: 10;
}

.canvas-block.dragging {
  cursor: grabbing;
  z-index: 1000 !important;
  opacity: 0.95;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.3));
}

.block-stack-container {
  display: flex;
  flex-direction: column;
}

.snap-highlight {
  outline: 3px dashed #FFBF00;
  outline-offset: 2px;
  box-shadow: 0 0 12px rgba(255, 191, 0, 0.8);
}

/* --- Right Side: Multi-Tab Inspector & APK Toolkit --- */
.inspector-panel {
  width: 380px;
  background: var(--scratch-sidebar);
  border-left: 1px solid var(--scratch-border);
  display: flex;
  flex-direction: column;
  z-index: 10;
  box-shadow: -2px 0 6px rgba(0,0,0,0.03);
}

.inspector-tabs {
  display: flex;
  background: #F2F4F7;
  border-bottom: 1px solid var(--scratch-border);
  overflow-x: auto;
}

.insp-tab {
  flex: 1;
  text-align: center;
  padding: 10px 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--scratch-text);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}

.insp-tab:hover {
  color: var(--scratch-header);
  background: #E8EDF5;
}

.insp-tab.active {
  color: var(--scratch-header);
  background: var(--scratch-white);
  border-bottom-color: var(--scratch-header);
}

.inspector-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* File Tree Explorer Tab */
.file-tree-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.file-tree-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--scratch-text-dark);
}

.btn-small {
  background: #EFF3F9;
  border: 1px solid var(--scratch-border);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-small:hover { background: #E0E7F1; }

.file-tree-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.file-node {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--scratch-text-dark);
  transition: background 0.15s;
}

.file-node:hover {
  background: #F0F4F8;
}

.file-node.active {
  background: #E2EFFE;
  color: #1A56DB;
}

.file-node-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-type-badge {
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 4px;
  background: #E5E7EB;
  color: #4B5563;
  font-weight: 700;
}

.file-type-badge.blocks { background: #DBEAFE; color: #1E40AF; }
.file-type-badge.manifest { background: #FEF3C7; color: #92400E; }
.file-type-badge.lib { background: #D1FAE5; color: #065F46; }
.file-type-badge.vr { background: #F3E8FF; color: #6B21A8; }

/* Form Groups & Cards */
.card-box {
  background: var(--scratch-white);
  border: 1px solid var(--scratch-border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.card-title {
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 10px;
  color: var(--scratch-text-dark);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--scratch-text);
  margin-bottom: 4px;
  text-transform: uppercase;
}

.form-input, .form-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--scratch-border-dark);
  border-radius: 6px;
  font-size: 13px;
  color: var(--scratch-text-dark);
  background: var(--scratch-white);
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus {
  border-color: var(--scratch-header);
}

/* Search Bar & Results */
.search-input-wrapper {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.search-input-wrapper input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--scratch-border-dark);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}

.search-results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 480px;
  overflow-y: auto;
}

.search-item {
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.search-item:hover {
  border-color: var(--scratch-header);
  background: #EFF6FF;
}

.search-item-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--scratch-header);
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
}

.search-item-snippet {
  font-size: 11px;
  color: #64748B;
  font-family: monospace;
  background: #fff;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid #E2E8F0;
}

/* Code Output / Smali / Manifest Viewer */
.code-viewer-pre {
  background: #1E293B;
  color: #F8FAFC;
  padding: 12px;
  border-radius: 6px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 11px;
  line-height: 1.4;
  overflow-x: auto;
  max-height: 260px;
  margin-top: 8px;
}

/* --- Modals & Popups (Library Confirm, Extension Creator, etc.) --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background: var(--scratch-white);
  border-radius: 12px;
  width: 90%;
  max-width: 580px;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.2), 0 10px 10px -5px rgba(0,0,0,0.1);
  overflow: hidden;
  transform: translateY(20px);
  transition: transform 0.2s ease;
  display: flex;
  flex-direction: column;
  max-height: 85vh;
}

.modal-overlay.active .modal-box {
  transform: translateY(0);
}

.modal-header {
  background: var(--scratch-header);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header.import-theme {
  background: var(--cat-permissions);
}

.modal-header.sign-theme {
  background: var(--cat-extensions);
}

.modal-title {
  font-size: 16px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 20px;
  background: #F8FAFC;
  border-top: 1px solid var(--scratch-border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-modal {
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--scratch-border-dark);
  background: #fff;
  color: var(--scratch-text-dark);
  transition: all 0.15s;
}

.btn-modal.primary {
  background: var(--scratch-header);
  color: #fff;
  border-color: var(--scratch-header-dark);
}

.btn-modal.confirm-import {
  background: var(--cat-permissions);
  color: #fff;
  border-color: var(--cat-permissions-dark);
}

.btn-modal.confirm-sign {
  background: var(--status-success);
  color: #fff;
  border-color: var(--cat-extensions-dark);
}

/* Linter Items */
.linter-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.linter-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}

.linter-item.error {
  background: #FEF2F2;
  border: 1px solid #FECACA;
  color: #991B1B;
}

.linter-item.warning {
  background: #FFFBEB;
  border: 1px solid #FDE68A;
  color: #92400E;
}

.linter-item.success {
  background: #ECFDF5;
  border: 1px solid #A7F3D0;
  color: #065F46;
}

/* Library & VR Badge in Confirmation Popup */
.lib-item-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #F1F5F9;
  border: 1px solid #E2E8F0;
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
}

/* --- Mobile Touch Optimization --- */
@media (max-width: 900px) {
  .header-bar {
    padding: 0 10px;
    height: 50px;
  }
  .apk-name-editor input {
    width: 110px;
  }
  .block-drawer {
    width: 240px;
  }
  .inspector-panel {
    width: 280px;
  }
  .btn-header span {
    display: none;
  }
}

/* Mobile specific touch styles when 'Mobile Mode' is activated */
body.mobile-mode .block-drawer {
  width: 260px;
}
body.mobile-mode .block-item {
  padding: 10px 16px;
  font-size: 14px;
}
body.mobile-mode .block-input-text,
body.mobile-mode .block-input-number {
  padding: 6px 10px;
  font-size: 14px;
}
