/* ===== RESET & VARIABLES ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --accent: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.12);
  --radius: 12px;
  --radius-lg: 16px;
  --header-h: 64px;
  --sidebar-w: 260px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #1e3a8a;
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.5);
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
  overflow: hidden;
}

/* ===== HEADER ===== */
.header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  transition: background var(--transition), border var(--transition);
}
.header-inner {
  display: flex; align-items: center; gap: 16px;
  height: 100%; padding: 0 20px;
}
.logo {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; color: var(--text);
  font-weight: 700; font-size: 1.25rem;
}
.logo-icon { font-size: 1.5rem; }
.logo-accent { color: var(--primary); }
.header-nav { display: flex; gap: 8px; margin-left: auto; }
.nav-link {
  padding: 6px 12px; text-decoration: none;
  color: var(--text-muted); font-weight: 500;
  border-radius: 8px; transition: var(--transition);
}
.nav-link:hover { color: var(--primary); background: var(--primary-light); }
[data-theme="dark"] .nav-link:hover { background: var(--primary-light); color: var(--text); }

.menu-toggle, .theme-toggle {
  background: none; border: none; cursor: pointer;
  font-size: 1.3rem; padding: 8px; border-radius: 8px;
  color: var(--text); transition: var(--transition);
}
.menu-toggle:hover, .theme-toggle:hover { background: var(--surface-2); }
.menu-toggle { display: none; }

/* ===== LAYOUT ===== */
.app-container {
  display: flex; height: 100vh; padding-top: var(--header-h);
}
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 16px 8px;
  transition: transform var(--transition);
}
.sidebar-section { margin-bottom: 20px; }
.sidebar-title {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); padding: 0 12px 8px; font-weight: 700;
}
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; text-decoration: none;
  color: var(--text); border-radius: 8px;
  font-size: 0.9rem; font-weight: 500;
  transition: var(--transition); margin-bottom: 2px;
}
.sidebar-link span { font-size: 1.1rem; }
.sidebar-link:hover { background: var(--surface-2); }
.sidebar-link.active {
  background: var(--primary); color: #fff;
}
.sidebar-link.active span { filter: brightness(1.2); }

.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: 50;
}

.main {
  flex: 1; overflow-y: auto; padding: 24px;
  scroll-behavior: smooth;
}

/* ===== VIEWS ===== */
.view { display: none; animation: fadeIn .3s ease; max-width: 1100px; margin: 0 auto; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.view-header { margin-bottom: 24px; }
.view-header h2 {
  font-size: 1.75rem; font-weight: 700; margin-bottom: 6px;
}
.view-header p { color: var(--text-muted); font-size: 0.95rem; }

/* ===== HOME ===== */
.hero { text-align: center; padding: 40px 0 48px; }
.hero-title {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800; letter-spacing: -.02em; line-height: 1.15;
}
.gradient-text {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero-subtitle {
  color: var(--text-muted); font-size: 1.05rem;
  max-width: 620px; margin: 16px auto 24px;
}
.hero-badges { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.badge {
  padding: 6px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 0.85rem; font-weight: 500; box-shadow: var(--shadow);
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.tool-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px 20px;
  text-decoration: none; color: var(--text);
  transition: all var(--transition); cursor: pointer;
  box-shadow: var(--shadow);
}
.tool-card:hover {
  transform: translateY(-3px); box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}
.tool-icon {
  font-size: 2rem; margin-bottom: 12px;
  width: 56px; height: 56px; display: flex;
  align-items: center; justify-content: center;
  background: var(--primary-light); border-radius: 12px;
}
[data-theme="dark"] .tool-icon { background: var(--primary-light); }
.tool-card h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: 4px; }
.tool-card p { font-size: 0.85rem; color: var(--text-muted); }

/* ===== DROP ZONE ===== */
.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius-lg);
  padding: 48px 24px; text-align: center; cursor: pointer;
  background: var(--surface); transition: all var(--transition);
  margin-bottom: 20px;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--primary); background: var(--primary-light);
  transform: scale(1.005);
}
[data-theme="dark"] .drop-zone.dragover { background: rgba(59,130,246,.1); }
.drop-icon { font-size: 3rem; margin-bottom: 12px; }
.drop-title { font-size: 1.05rem; font-weight: 600; margin-bottom: 4px; }
.drop-sub { font-size: 0.85rem; color: var(--text-muted); }

/* ===== FILE LIST ===== */
.file-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.file-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  box-shadow: var(--shadow); animation: fadeIn .2s ease;
}
.file-number {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; flex-shrink: 0;
}
.file-icon { font-size: 1.4rem; flex-shrink: 0; }
.file-meta { flex: 1; min-width: 0; }
.file-name {
  font-weight: 500; font-size: 0.9rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-size { font-size: 0.75rem; color: var(--text-muted); }
.file-remove {
  background: none; border: none; cursor: pointer;
  font-size: 1.1rem; color: var(--text-muted);
  padding: 6px; border-radius: 6px; transition: var(--transition);
}
.file-remove:hover { background: var(--danger); color: #fff; }

/* ===== FILE INFO ===== */
.file-info {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  margin-bottom: 20px; font-size: 0.9rem;
}
.file-info strong { display: block; margin-bottom: 4px; }
.file-info .muted { color: var(--text-muted); font-size: 0.85rem; }

/* ===== ACTIONS ===== */
.actions {
  display: flex; gap: 12px; justify-content: flex-end;
  margin-top: 20px; flex-wrap: wrap;
}

/* ===== BUTTONS ===== */
.btn {
  padding: 10px 20px; border-radius: 10px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; transition: all var(--transition);
  font-family: inherit; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px;
}
.btn-primary {
  background: var(--primary); color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); transform: translateY(-1px); }
.btn-primary:disabled {
  background: var(--border); color: var(--text-muted);
  cursor: not-allowed;
}
.btn-secondary {
  background: var(--surface); color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-2); }
.btn-icon {
  padding: 8px 12px; background: var(--surface);
  border: 1px solid var(--border); color: var(--text);
  font-size: 1rem; min-width: 42px;
}
.btn-icon:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== FORMS ===== */
.form { margin-bottom: 20px; }
.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; font-size: 0.85rem; font-weight: 600;
  margin-bottom: 6px; color: var(--text);
}
.field input[type="text"], .field input[type="password"],
.field input[type="number"], .field input[type="color"] {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font-size: 0.95rem; font-family: inherit;
  transition: var(--transition);
}
.field input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.field input[type="color"] { height: 44px; padding: 4px; cursor: pointer; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.radio-group { display: flex; gap: 16px; flex-wrap: wrap; padding: 12px 0; }
.radio { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 0.9rem; }
.radio input { accent-color: var(--primary); }

/* ===== INFO CARD ===== */
.info-card {
  background: var(--primary-light); border-left: 4px solid var(--primary);
  padding: 14px 18px; border-radius: 10px; margin-bottom: 20px;
}
[data-theme="dark"] .info-card { background: rgba(59,130,246,.12); }
.info-card strong { display: block; margin-bottom: 4px; color: var(--primary); }
.info-card p { font-size: 0.85rem; color: var(--text-muted); }

/* ===== RESULT CARD ===== */
.result-card {
  background: var(--surface); border: 1px solid var(--success);
  border-radius: var(--radius); padding: 20px;
  margin-top: 20px; box-shadow: var(--shadow-md);
}
.result-card h4 { color: var(--success); margin-bottom: 12px; font-size: 1.05rem; }
.result-row {
  display: flex; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.result-row:last-child { border-bottom: none; }
.result-row strong { color: var(--primary); }

/* ===== RESULT AREA ===== */
.result-area {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-top: 20px;
}
.result-header {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px;
}
.result-header > span { font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }
.text-area {
  width: 100%; min-height: 400px; padding: 16px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
  font-family: 'SF Mono', Monaco, 'Cascadia Code', Consolas, monospace;
  font-size: 0.85rem; line-height: 1.6; resize: vertical;
  white-space: pre-wrap; word-wrap: break-word;
}

/* ===== GALLERY ===== */
.gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px; margin-top: 20px;
}
.gallery-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; box-shadow: var(--shadow);
  transition: var(--transition);
}
.gallery-item:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.gallery-item img { width: 100%; height: 180px; object-fit: contain; background: var(--surface-2); }
.gallery-item-footer {
  padding: 8px 10px; display: flex; justify-content: space-between;
  align-items: center; font-size: 0.75rem; color: var(--text-muted);
}
.gallery-item-footer button {
  background: var(--primary); color: #fff; border: none;
  padding: 4px 10px; border-radius: 6px; cursor: pointer;
  font-size: 0.75rem; font-weight: 600;
}

/* ===== VIEWER ===== */
.viewer-toolbar {
  display: flex; justify-content: space-between;
  align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px;
  margin-bottom: 16px; box-shadow: var(--shadow);
}
.toolbar-group { display: flex; gap: 6px; align-items: center; }
.page-info {
  padding: 0 10px; font-size: 0.85rem;
  font-weight: 600; color: var(--text-muted); min-width: 70px;
  text-align: center;
}

.viewer-container {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: auto;
  height: calc(100vh - 280px); padding: 24px;
  display: flex; flex-direction: column; align-items: center;
  gap: 20px;
}
.viewer-canvas-wrap { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.viewer-canvas-wrap canvas {
  box-shadow: var(--shadow-lg); border-radius: 4px;
  background: #fff; max-width: 100%; height: auto;
}
.viewer-container.night-mode { background: #0a0a0a; }
.viewer-container.night-mode canvas { filter: invert(1) hue-rotate(180deg); }

.bookmarks-panel {
  position: fixed; top: var(--header-h); right: 0; bottom: 0;
  width: 320px; background: var(--surface);
  border-left: 1px solid var(--border); z-index: 60;
  box-shadow: var(--shadow-lg); padding: 16px;
  overflow-y: auto; animation: slideIn .25s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: none; } }
.panel-header {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 16px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.panel-header h4 { font-size: 1rem; }
.bookmarks-list { display: flex; flex-direction: column; gap: 8px; }
.bookmark-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; background: var(--surface-2);
  border-radius: 8px; cursor: pointer; transition: var(--transition);
}
.bookmark-item:hover { background: var(--primary-light); }
.bookmark-item .bm-page { font-size: 0.75rem; color: var(--text-muted); }
.bookmark-item .bm-title { font-weight: 500; font-size: 0.9rem; }
.bookmark-item .bm-del {
  background: none; border: none; color: var(--danger);
  cursor: pointer; font-size: 1rem;
}
.empty-msg { text-align: center; color: var(--text-muted); padding: 20px; font-size: 0.9rem; }

/* ===== TEXT VIEWER ===== */
.text-viewer {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 0.9rem; line-height: 1.7;
  white-space: pre-wrap; word-wrap: break-word;
  max-height: calc(100vh - 320px); overflow-y: auto;
  color: var(--text);
}
.text-viewer.night { background: #0a0a0a; color: #e5e5e5; }

/* ===== IMAGE VIEWER ===== */
.image-viewer {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); height: calc(100vh - 300px);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; position: relative;
}
.image-viewer img {
  max-width: 100%; max-height: 100%;
  transition: transform .2s ease; user-select: none;
  box-shadow: var(--shadow-lg);
}

/* ===== TOAST ===== */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 999; max-width: 360px;
}
.toast {
  background: var(--surface); color: var(--text);
  border-left: 4px solid var(--primary);
  padding: 14px 18px; border-radius: 10px;
  box-shadow: var(--shadow-lg); font-size: 0.9rem;
  animation: toastIn .3s ease; min-width: 240px;
  display: flex; align-items: center; gap: 10px;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--primary); }
@keyframes toastIn { from { transform: translateX(120%); opacity: 0; } to { transform: none; opacity: 1; } }
.toast.out { animation: toastOut .3s ease forwards; }
@keyframes toastOut { to { transform: translateX(120%); opacity: 0; } }

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; backdrop-filter: blur(4px);
}
.loading-card {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 32px 40px; text-align: center;
  box-shadow: var(--shadow-lg); min-width: 280px;
}
.spinner {
  width: 48px; height: 48px; border-radius: 50%;
  border: 4px solid var(--border); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite; margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-card p { font-weight: 600; color: var(--text); }
.progress-bar {
  height: 6px; background: var(--border); border-radius: 3px;
  overflow: hidden; margin-top: 16px; display: none;
}
.progress-bar.active { display: block; }
.progress-fill {
  height: 100%; background: var(--primary);
  width: 0%; transition: width 0.2s ease;
  border-radius: 3px;
}

/* ===== UTILITIES ===== */
.hidden { display: none !important; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .menu-toggle { display: block; }
  .header-nav { display: none; }
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; bottom: 0;
    transform: translateX(-100%); z-index: 55;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .sidebar-overlay.active { display: block; }
  .main { padding: 16px; }
  .tools-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .bookmarks-panel { width: 100%; }
}

@media (max-width: 600px) {
  .hero { padding: 24px 0 32px; }
  .tools-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tool-card { padding: 16px 12px; }
  .tool-icon { width: 44px; height: 44px; font-size: 1.5rem; }
  .tool-card h3 { font-size: 0.95rem; }
  .tool-card p { font-size: 0.75rem; }
  .actions { flex-direction: column-reverse; }
  .actions .btn { width: 100%; }
  .viewer-toolbar { padding: 8px; }
  .btn-icon { padding: 6px 10px; font-size: 0.9rem; min-width: 36px; }
}
/* ===== LANGUAGE SWITCHER ===== */
.lang-switcher-wrapper { position: relative; }
.lang-toggle {
  background: none; border: none; cursor: pointer;
  font-size: 1.3rem; padding: 8px; border-radius: 8px;
  color: var(--text); transition: var(--transition);
}
.lang-toggle:hover { background: var(--surface-2); }
.lang-menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px; min-width: 180px;
  box-shadow: var(--shadow-lg); z-index: 200;
  animation: fadeIn .2s ease;
}
.lang-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px; background: none;
  border: none; cursor: pointer; text-align: left;
  border-radius: 8px; font-size: 0.9rem;
  color: var(--text); font-family: inherit;
  transition: var(--transition);
}
.lang-btn:hover { background: var(--surface-2); }
.lang-btn.active { background: var(--primary); color: #fff; }
.lang-btn span:first-child { font-size: 1.2rem; }
.logo-icon img {
  height: 50px; /* Adjust this number to match the text size */
  width: auto;  /* Keeps the aspect ratio correct */
  display: block;
}