/* ========================================================
   HTView - Styling Modern, Hemat Ruang, & Responsif
   ======================================================== */

:root {
  /* Font Families */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Fira Code', 'Cascadia Code', Menlo, Monaco, Consolas, monospace;

  /* Sizing */
  --header-height: 44px;
  --panel-header-height: 34px;
  --statusbar-height: 26px;
  --line-height-editor: 22px;
  --font-size-editor: 13.5px;

  /* Transitions */
  --trans-fast: 0.15s ease;
  --trans-normal: 0.25s ease;
}

/* ----------------- Dark Theme (Default) ----------------- */
[data-theme="dark"] {
  --bg-app: #0c0e14;
  --bg-header: #12151e;
  --bg-panel: #11141f;
  --bg-editor: #0e111a;
  --bg-gutter: #0b0d14;
  --bg-statusbar: #0e111a;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --bg-active: rgba(255, 255, 255, 0.1);
  --bg-dropdown: #161a27;
  --bg-preview-canvas: #1e2230;

  --border-subtle: rgba(255, 255, 255, 0.07);
  --border-medium: rgba(255, 255, 255, 0.12);
  --border-focus: #6366f1;

  --text-main: #e2e8f0;
  --text-muted: #8492a6;
  --text-dim: #4c566a;

  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --accent-glow: rgba(99, 102, 241, 0.25);

  --gutter-text: #485268;
  --gutter-text-active: #c7d2fe;
  --line-highlight: rgba(99, 102, 241, 0.08);

  --resizer-line: rgba(255, 255, 255, 0.08);
  --resizer-hover: #6366f1;
  --shadow-dropdown: 0 10px 25px -5px rgba(0, 0, 0, 0.6), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --shadow-preview: 0 12px 36px rgba(0, 0, 0, 0.4);
}

/* ----------------- Light Theme ----------------- */
[data-theme="light"] {
  --bg-app: #f1f5f9;
  --bg-header: #ffffff;
  --bg-panel: #ffffff;
  --bg-editor: #fafbfc;
  --bg-gutter: #f1f5f9;
  --bg-statusbar: #f8fafc;
  --bg-hover: rgba(0, 0, 0, 0.05);
  --bg-active: rgba(0, 0, 0, 0.08);
  --bg-dropdown: #ffffff;
  --bg-preview-canvas: #cbd5e1;

  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-medium: rgba(0, 0, 0, 0.15);
  --border-focus: #4f46e5;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;

  --accent-primary: #4f46e5;
  --accent-primary-hover: #4338ca;
  --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --accent-glow: rgba(79, 70, 229, 0.2);

  --gutter-text: #94a3b8;
  --gutter-text-active: #4338ca;
  --line-highlight: rgba(79, 70, 229, 0.07);

  --resizer-line: rgba(0, 0, 0, 0.08);
  --resizer-hover: #4f46e5;
  --shadow-dropdown: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.06);
  --shadow-preview: 0 10px 30px rgba(0, 0, 0, 0.12);
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

/* ========================================================
   Header (Minimalis & Compact)
   ======================================================== */
.app-header {
  height: var(--header-height);
  background-color: var(--bg-header);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  position: relative;
  z-index: 50;
  user-select: none;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.3px;
  color: var(--text-main);
}

.brand-icon {
  width: 20px;
  height: 20px;
  color: #818cf8;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.brand-name span {
  color: #818cf8;
  font-weight: 600;
}

.divider-v {
  width: 1px;
  height: 18px;
  background-color: var(--border-subtle);
  margin: 0 4px;
}

.divider-v-sm {
  width: 1px;
  height: 14px;
  background-color: var(--border-subtle);
  margin: 0 2px;
}

/* Tombol Standar Header */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--trans-fast);
  color: var(--text-muted);
  background: transparent;
  text-decoration: none;
  white-space: nowrap;
}

.btn-sm {
  height: 28px;
  padding: 0 8px;
}

.btn-ghost:hover {
  background-color: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-subtle);
}

.btn-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.chevron-icon {
  width: 12px;
  height: 12px;
  transition: transform var(--trans-fast);
}

.file-input-label {
  cursor: pointer;
}

/* Status Indicator */
.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 0 6px;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  background-color: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 8px #10b981;
  animation: pulse-ring 2.5s infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

/* Theme Toggle Button */
.btn-theme {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-hover);
}

.btn-theme:hover {
  color: var(--text-main);
  border-color: var(--border-medium);
  background-color: var(--bg-active);
}

.btn-theme svg {
  width: 14px;
  height: 14px;
}

[data-theme="dark"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* Dropdown Menu Sampel */
.dropdown-wrapper {
  position: relative;
}

.dropdown-wrapper.open .chevron-icon {
  transform: rotate(180deg);
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 240px;
  background-color: var(--bg-dropdown);
  border: 1px solid var(--border-medium);
  border-radius: 8px;
  box-shadow: var(--shadow-dropdown);
  padding: 6px;
  z-index: 100;
  animation: dropdown-pop 0.15s ease-out;
}

.dropdown-wrapper.open .dropdown-menu {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

@keyframes dropdown-pop {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 7px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background-color var(--trans-fast);
}

.dropdown-item:hover {
  background-color: var(--bg-hover);
}

.item-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-main);
}

.item-desc {
  font-size: 11px;
  color: var(--text-dim);
}

/* ========================================================
   Workspace (Dual Panel Split)
   ======================================================== */
.workspace {
  width: 100%;
  height: calc(100% - var(--header-height));
  display: flex;
  overflow: hidden;
  position: relative;
}

.panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-panel);
}

.panel-editor {
  width: 50%;
  min-width: 260px;
}

.panel-preview {
  flex: 1;
  min-width: 260px;
}

/* Panel Header (Sub-bar) */
.panel-header {
  height: var(--panel-header-height);
  background-color: var(--bg-header);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  font-size: 11.5px;
  color: var(--text-muted);
  user-select: none;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.file-tag {
  background-color: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid rgba(99, 102, 241, 0.25);
}

.preview-badge {
  background-color: rgba(16, 185, 129, 0.15);
  color: #10b981;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.panel-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--trans-fast);
}

.panel-action-btn svg {
  width: 13px;
  height: 13px;
}

.panel-action-btn:hover {
  color: var(--text-main);
  background-color: var(--bg-hover);
}

.panel-action-btn.active {
  color: var(--accent-primary);
  background-color: var(--bg-active);
}

/* ========================================================
   Editor: Line Numbers + Textarea Container
   ======================================================== */
.editor-container {
  flex: 1;
  display: flex;
  background-color: var(--bg-editor);
  overflow: hidden;
  position: relative;
}

/* Gutter Baris (Line numbers) */
.line-gutter {
  width: 46px;
  min-width: 46px;
  background-color: var(--bg-gutter);
  border-right: 1px solid var(--border-subtle);
  overflow: hidden;
  user-select: none;
  padding-top: 10px;
  padding-bottom: 10px;
}

.line-numbers {
  display: flex;
  flex-direction: column;
  text-align: right;
  padding-right: 10px;
  font-family: var(--font-mono);
  font-size: var(--font-size-editor);
  line-height: var(--line-height-editor);
  color: var(--gutter-text);
  will-change: transform;
}

.line-num {
  height: var(--line-height-editor);
  line-height: var(--line-height-editor);
  transition: color var(--trans-fast);
}

.line-num.active {
  color: var(--gutter-text-active);
  font-weight: 600;
}

/* Textarea Input */
.code-editor {
  flex: 1;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: var(--font-size-editor);
  line-height: var(--line-height-editor);
  padding: 10px 14px;
  tab-size: 2;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: break-word;
  overflow-y: scroll;
  overflow-x: auto;
}

.code-editor.no-wrap {
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}

.code-editor::placeholder {
  color: var(--text-dim);
  opacity: 0.6;
}

/* Custom Scrollbar */
.code-editor::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.code-editor::-webkit-scrollbar-track {
  background: transparent;
}

.code-editor::-webkit-scrollbar-thumb {
  background-color: var(--border-medium);
  border-radius: 5px;
  border: 2px solid var(--bg-editor);
}

.code-editor::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-dim);
}

/* Editor Status Bar */
.editor-statusbar {
  height: var(--statusbar-height);
  background-color: var(--bg-statusbar);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 11px;
  color: var(--text-muted);
  user-select: none;
}

.statusbar-left, .statusbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-sep {
  color: var(--text-dim);
  font-size: 8px;
}

.badge-tab, .badge-enc {
  background-color: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--border-subtle);
  font-size: 10px;
  color: var(--text-dim);
}

/* ========================================================
   Resizer (Drag Splitter)
   ======================================================== */
.resizer {
  width: 6px;
  background-color: transparent;
  cursor: col-resize;
  position: relative;
  z-index: 20;
  transition: background-color var(--trans-fast);
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.resizer-handle {
  width: 2px;
  height: 24px;
  background-color: var(--border-medium);
  border-radius: 1px;
  transition: all var(--trans-fast);
}

.resizer:hover, .resizer.dragging {
  background-color: var(--bg-hover);
}

.resizer:hover .resizer-handle,
.resizer.dragging .resizer-handle {
  background-color: var(--resizer-hover);
  height: 48px;
  width: 3px;
  box-shadow: 0 0 10px var(--accent-glow);
}

/* ========================================================
   Preview Panel & Iframe
   ======================================================== */
.device-switcher {
  display: flex;
  background-color: var(--bg-hover);
  border-radius: 4px;
  padding: 1px;
}

.device-btn {
  background: transparent;
  border: none;
  width: 22px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--trans-fast);
}

.device-btn svg {
  width: 12px;
  height: 12px;
}

.device-btn:hover {
  color: var(--text-main);
}

.device-btn.active {
  background-color: var(--bg-panel);
  color: var(--accent-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.preview-wrapper {
  flex: 1;
  background-color: var(--bg-preview-canvas);
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0;
  transition: background-color var(--trans-normal);
}

.preview-wrapper.device-mode {
  padding: 16px;
}

.iframe-container {
  width: 100%;
  height: 100%;
  background-color: #ffffff;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
  position: relative;
}

.preview-wrapper.device-mode .iframe-container {
  height: 100%;
  max-height: 840px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-preview);
  border: 1px solid var(--border-medium);
}

#preview-frame {
  width: 100%;
  height: 100%;
  border: none;
  background-color: #ffffff;
  display: block;
}

/* ========================================================
   Toast Notification
   ======================================================== */
.toast {
  position: fixed;
  bottom: 38px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background-color: var(--bg-dropdown);
  color: var(--text-main);
  border: 1px solid var(--border-medium);
  box-shadow: var(--shadow-dropdown);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

/* ========================================================
   Media Query untuk Responsiveness Layar Kecil
   ======================================================== */
@media (max-width: 768px) {
  .workspace {
    flex-direction: column;
  }

  .panel-editor, .panel-preview {
    width: 100% !important;
    height: 50% !important;
  }

  .resizer {
    width: 100%;
    height: 6px;
    cursor: row-resize;
  }

  .resizer-handle {
    width: 24px;
    height: 2px;
  }

  .resizer:hover .resizer-handle,
  .resizer.dragging .resizer-handle {
    width: 48px;
    height: 3px;
  }

  .brand-name {
    display: none;
  }

  .btn-text {
    display: none;
  }
}
