/* MyDeskMate Mobile PWA - Native App Styling */
:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;
  --primary-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --secondary: #0ea5e9;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #27354f;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-sub: #cbd5e1;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 0 20px rgba(79, 70, 229, 0.4);
  --bottom-bar-height: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
}

/* App Shell Container */
#app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--bottom-bar-height) + var(--safe-bottom));
  position: relative;
  background-color: var(--bg-dark);
}

/* Header */
.app-header {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  z-index: 50;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  object-fit: cover;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--primary-gradient);
  color: #fff;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

.offline-pill {
  display: none;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  background: #374151;
  color: #9ca3af;
  padding: 3px 8px;
  border-radius: var(--radius-full);
}

.offline-pill.is-offline {
  display: inline-flex;
  background: #7f1d1d;
  color: #fca5a5;
}

.install-header-btn {
  display: none;
  background: var(--primary-gradient);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease;
}

.install-header-btn:active {
  transform: scale(0.95);
}

/* Main Scrollable View Area */
.views-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

.app-view {
  display: none;
  padding: 16px;
  padding-bottom: 24px;
  min-height: 100%;
}

.app-view.active {
  display: block;
  animation: fadeIn 0.2s ease-out;
}

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

/* Home View */
.hero-banner {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.18) 0%, rgba(124, 58, 237, 0.12) 100%);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}

.hero-banner h1 {
  font-size: 1.35rem;
  font-weight: 800;
  margin-bottom: 6px;
  color: #fff;
}

.hero-banner p {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.quick-action-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-gradient);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-glow);
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-sub);
  margin: 18px 0 12px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Tool Cards Grid */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

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

.tool-icon-wrap {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  margin-bottom: 10px;
}

.icon-purple { background: rgba(124, 58, 237, 0.2); color: #a78bfa; }
.icon-blue { background: rgba(14, 165, 233, 0.2); color: #38bdf8; }
.icon-green { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.icon-orange { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.icon-rose { background: rgba(244, 63, 94, 0.2); color: #fb7185; }
.icon-amber { background: rgba(217, 119, 6, 0.2); color: #fde047; }

.tool-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.tool-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.tool-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 0.65rem;
  font-weight: 700;
  background: rgba(79, 70, 229, 0.25);
  color: #818cf8;
  padding: 2px 6px;
  border-radius: var(--radius-full);
}

/* Install Promo Banner */
.install-card {
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
  border: 1px solid #4338ca;
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.install-card-info h3 {
  font-size: 0.98rem;
  font-weight: 700;
  color: #fff;
}

.install-card-info p {
  font-size: 0.78rem;
  color: #c7d2fe;
}

.install-cta-btn {
  background: #fff;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* PDF Editor View */
#view-editor {
  padding: 0;
  height: 100%;
  display: none;
  flex-direction: column;
}

#view-editor.active {
  display: flex;
}

.editor-top-bar {
  background: #1e293b;
  border-bottom: 1px solid var(--border-color);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 20;
}

.editor-btn-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.editor-btn {
  background: #334155;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.editor-btn:active {
  background: var(--primary);
}

.editor-btn.btn-primary {
  background: var(--primary-gradient);
  box-shadow: var(--shadow-sm);
}

.page-indicator {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.editor-canvas-container {
  flex: 1;
  overflow: auto;
  background: #090d16;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 16px;
  touch-action: pan-x pan-y;
}

#canvas-wrapper {
  position: relative;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  background: #ffffff;
  border-radius: 4px;
  max-width: 100%;
  display: none;
}

#pdf-render-canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

#pdf-draw-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  touch-action: none; /* Crucial for drawing on mobile */
  cursor: crosshair;
}

/* Interactive Elements Overlay Layer */
#pdf-elements-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 10;
}

.pdf-interactive-item {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  cursor: move;
  user-select: none;
  border: 1.5px dashed rgba(99, 102, 241, 0.7);
  border-radius: 6px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.05);
  box-sizing: border-box;
  z-index: 20;
}

.pdf-interactive-item.active {
  border: 2px solid #4f46e5;
  box-shadow: 0 0 14px rgba(79, 70, 229, 0.45);
  background: rgba(255, 255, 255, 0.15);
  z-index: 25;
}

/* Whiteout Opaque Box for Erasing Existing PDF Text */
.pdf-interactive-item.whiteout-item {
  background: #ffffff !important;
  border: 1.5px dashed #64748b;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
  border-radius: 3px;
}

.pdf-interactive-item.whiteout-item.active {
  border: 2px solid #3b82f6;
  box-shadow: 0 0 14px rgba(59, 130, 246, 0.5);
}

.item-whiteout-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.72rem;
  color: #94a3b8;
  font-weight: 700;
  pointer-events: none;
  opacity: 0.75;
  user-select: none;
  white-space: nowrap;
}

.pdf-interactive-item.whiteout-item.active .item-whiteout-label {
  opacity: 0.35;
}

.pdf-interactive-item .item-text-content {
  width: 100%;
  height: 100%;
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
  outline: none;
}

.pdf-interactive-item .item-img-content {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  display: block;
}

/* Item Action Header Controls */
.item-controls-header {
  position: absolute;
  top: -34px;
  left: 0;
  display: none;
  align-items: center;
  gap: 4px;
  background: #1e293b;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  box-shadow: var(--shadow-sm);
  z-index: 30;
  white-space: nowrap;
}

.pdf-interactive-item.active .item-controls-header {
  display: inline-flex;
}

.item-btn {
  background: #334155;
  color: #fff;
  border: none;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.item-btn:active {
  background: var(--primary);
}

.item-btn.btn-delete {
  background: #dc2626;
  color: #fff;
}

/* Corner Resize Handle */
.item-resize-handle {
  position: absolute;
  bottom: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  background: #4f46e5;
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: nwse-resize;
  touch-action: none;
  display: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  z-index: 25;
}

.pdf-interactive-item.active .item-resize-handle {
  display: block;
}

/* Floating Text Formatting Toolbar */
.text-format-bar {
  background: #1e293b;
  border-bottom: 1px solid var(--border-color);
  padding: 6px 12px;
  display: none;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  z-index: 18;
  -webkit-overflow-scrolling: touch;
}

.text-format-bar.active {
  display: flex;
}

.format-group {
  display: flex;
  align-items: center;
  gap: 4px;
  border-right: 1px solid var(--border-color);
  padding-right: 8px;
}

.format-select {
  background: #334155;
  color: #fff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  outline: none;
}

.format-btn {
  background: #334155;
  color: #cbd5e1;
  border: none;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  min-width: 26px;
  text-align: center;
}

.format-btn.active {
  background: var(--primary);
  color: #fff;
}

/* Modal Segmented Tabs (e.g. Draw vs Upload) */
.modal-tabs {
  display: flex;
  gap: 6px;
  background: #0f172a;
  padding: 4px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

.modal-tab-btn {
  flex: 1;
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
}

.modal-tab-btn.active {
  background: var(--primary-gradient);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.modal-tab-pane {
  display: none;
}

.modal-tab-pane.active {
  display: block;
}

/* Compression Preset Options Cards */
.compress-options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 14px 0;
}

.compress-option-card {
  background: #0f172a;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.15s ease;
}

.compress-option-card:hover, .compress-option-card.active {
  border-color: var(--primary);
  background: rgba(79, 70, 229, 0.12);
}

.compress-card-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
}

.compress-card-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.compress-target-badge {
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

.custom-kb-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.custom-kb-input {
  background: #0f172a;
  color: #fff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.9rem;
  width: 120px;
  outline: none;
}

.empty-editor-state {
  text-align: center;
  padding: 30px 20px;
  max-width: 320px;
}

.empty-editor-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.8;
}

.empty-editor-state h2 {
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.empty-editor-state p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 18px;
}

/* Editor Bottom Tool Strip */
.editor-tools-dock {
  background: #1e293b;
  border-top: 1px solid var(--border-color);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 4px;
  overflow-x: auto;
}

.dock-tool {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  min-width: 52px;
  transition: all 0.15s ease;
}

.dock-tool svg, .dock-tool span.icon {
  font-size: 1.2rem;
}

.dock-tool.active {
  color: #fff;
  background: var(--primary);
}

/* Modals & Bottom Sheets */
.app-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}

.app-modal.active {
  display: flex;
  animation: modalFade 0.2s ease-out;
}

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

.modal-sheet {
  background: #1e293b;
  width: 100%;
  max-width: 500px;
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  border-top: 1px solid var(--border-color);
  padding: 20px;
  padding-bottom: calc(20px + var(--safe-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

.modal-close {
  background: #334155;
  color: #cbd5e1;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
}

/* Signature Pad Canvas */
#sig-canvas {
  width: 100%;
  height: 180px;
  background: #f8fafc;
  border-radius: var(--radius-md);
  border: 2px dashed #94a3b8;
  touch-action: none;
  display: block;
}

.sig-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  gap: 10px;
}

.color-pickers {
  display: flex;
  gap: 8px;
}

.color-dot {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  cursor: pointer;
  border: 2px solid transparent;
}

.color-dot.active {
  border-color: #fff;
  transform: scale(1.15);
}

.sig-actions {
  display: flex;
  gap: 8px;
}

.btn-secondary {
  background: #334155;
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--primary-gradient);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

/* Quick Tools List */
.tool-dropzone {
  border: 2px dashed var(--border-color);
  background: rgba(30, 41, 59, 0.5);
  border-radius: var(--radius-md);
  padding: 24px 16px;
  text-align: center;
  margin-bottom: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tool-dropzone:active, .tool-dropzone.dragover {
  border-color: var(--primary);
  background: rgba(79, 70, 229, 0.1);
}

.file-item-pill {
  background: #334155;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.85rem;
}

/* Bottom App Navigation Bar */
.app-nav-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: calc(var(--bottom-bar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 60;
}

.nav-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
  height: 100%;
  justify-content: center;
  transition: all 0.15s ease;
}

.nav-tab .tab-icon {
  font-size: 1.25rem;
  transition: transform 0.15s ease;
}

.nav-tab.active {
  color: #818cf8;
}

.nav-tab.active .tab-icon {
  transform: translateY(-2px);
  color: #818cf8;
}

/* Toast Messages */
.app-toast {
  position: fixed;
  top: calc(16px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%) translateY(-30px);
  background: #1e293b;
  color: #fff;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 200;
}

.app-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Hidden file inputs */
.visually-hidden {
  display: none !important;
}

