/* ============================================================
   EBTE v2.0 Styles — Dark theme + 3-tier Responsive
   ============================================================ */

/* ===== Variables ===== */
:root {
  --primary: #B8956A;
  --primary-light: rgba(184,149,106,0.08);
  --primary-border: rgba(184,149,106,0.3);
  --bg: #1a1a2e;
  --bg-surface: #16213e;
  --bg-card: #1c2a4a;
  --bg-input: #0f1a30;
  --text: #e0e0e0;
  --text-muted: #8899aa;
  --border: #2a3a5a;
  --danger: #e74c3c;
  --success: #27ae60;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ===== Login Screen ===== */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 5000;
}

.login-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 90%;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow);
}

.login-title {
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 3px;
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.login-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  text-align: center;
  letter-spacing: 2px;
}

.login-input:focus {
  outline: none;
  border-color: var(--primary);
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 20px;
  margin: 10px 0;
}

.login-btn {
  width: 100%;
  padding: 12px;
  font-size: 15px;
}

/* ===== App Screen ===== */
.app-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ===== Toolbar ===== */
.toolbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  z-index: 100;
  position: relative;
}

.toolbar-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 1px;
}

.toolbar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.toolbar-mobile-only {
  display: none;
  margin-left: auto;
  font-size: 18px;
  padding: 6px 10px;
}

.toolbar-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 200;
  overflow: hidden;
}

.toolbar-menu.open { display: block; }

.toolbar-menu-item {
  display: block;
  width: 100%;
  padding: 12px 20px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.toolbar-menu-item:hover { background: var(--primary-light); }
.toolbar-menu-item.danger { color: var(--danger); }

/* ===== Save Status ===== */
.save-status {
  font-size: 12px;
  font-weight: 600;
  transition: all 0.3s;
  white-space: nowrap;
}

.save-status.saving {
  color: var(--primary);
  animation: pulse 1s infinite;
}

.save-status.saved { color: var(--success); }
.save-status.error { color: var(--danger); cursor: pointer; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== Buttons ===== */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover { background: rgba(231,76,60,0.1); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ===== Tabs ===== */
.tabs-bar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 2px;
  flex-shrink: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab {
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab .tab-close {
  font-size: 14px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  opacity: 0.5;
  transition: all 0.2s;
}

.tab .tab-close:hover {
  opacity: 1;
  background: rgba(231,76,60,0.2);
  color: var(--danger);
}

.tab-add {
  padding: 10px 14px;
  font-size: 16px;
  color: var(--primary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-weight: 700;
  -webkit-tap-highlight-color: transparent;
}
.tab-add:hover { color: var(--text); }

/* ===== Main Layout ===== */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ===== Preview Pane ===== */
.preview-pane {
  flex: 6;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.preview-header {
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.preview-container {
  flex: 1;
  overflow: auto;
  background: #fff;
}

.preview-container iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* ===== Fields Pane ===== */
.fields-pane {
  flex: 4;
  display: flex;
  flex-direction: column;
  min-width: 260px;
  background: var(--bg-surface);
}

.fields-header {
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.fields-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.field-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.field-card.active {
  border-left-color: var(--primary);
  background: var(--primary-light);
}

.field-card.modified .field-label::after {
  content: '\25CF';
  color: var(--primary);
  margin-left: 6px;
  font-size: 10px;
}

.field-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.field-tag {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: rgba(184,149,106,0.15);
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}

.field-class {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'SF Mono', Monaco, monospace;
  word-break: break-all;
}

.field-textarea {
  width: 100%;
  min-height: 56px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  line-height: 1.5;
  transition: border-color 0.2s;
}

.field-textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Rich field preview */
.field-rich-preview {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

.field-rich-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  font-style: italic;
}

/* ===== Output Bar ===== */
.output-bar {
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.output-bar-header {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.output-bar-header span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.output-bar-content { display: none; padding: 0 16px 12px; }
.output-bar.open .output-bar-content { display: block; }

.output-textarea {
  width: 100%;
  height: 150px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  font-size: 12px;
  font-family: 'SF Mono', Monaco, monospace;
  resize: vertical;
  line-height: 1.4;
}

.output-textarea:focus { outline: none; border-color: var(--primary); }

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 700px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal h2 {
  font-size: 18px;
  color: var(--primary);
  margin-bottom: 16px;
}

.modal label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 14px;
}

.modal input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}

.modal input[type="text"]:focus { outline: none; border-color: var(--primary); }

.modal textarea {
  width: 100%;
  height: 200px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-size: 12px;
  font-family: 'SF Mono', Monaco, monospace;
  resize: vertical;
  line-height: 1.4;
}

.modal textarea:focus { outline: none; border-color: var(--primary); }

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

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 16px;
  padding: 40px;
  text-align: center;
}

.empty-state-icon { font-size: 48px; opacity: 0.3; }
.empty-state h3 { font-size: 18px; color: var(--text); }
.empty-state p { font-size: 14px; max-width: 400px; line-height: 1.6; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-card);
  color: var(--text);
  padding: 10px 24px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--primary);
  box-shadow: var(--shadow);
  z-index: 9999;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}

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

/* ===== Confirm Dialog ===== */
.confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}
.confirm-overlay.open { display: flex; }
.confirm-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow);
}
.confirm-box p { margin-bottom: 18px; font-size: 14px; line-height: 1.5; }
.confirm-box .modal-actions { justify-content: center; }

/* ===== Mobile View Switcher ===== */
.view-switcher {
  display: none;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 8px 16px;
  gap: 8px;
  flex-shrink: 0;
}

.view-switcher-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   RESPONSIVE: Tablet (768px - 1024px) — stack vertically
   ============================================================ */
@media (max-width: 1024px) {
  .main {
    flex-direction: column;
  }

  .preview-pane {
    flex: none;
    height: 50vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .fields-pane {
    flex: 1;
    min-width: unset;
  }
}

/* ============================================================
   RESPONSIVE: Mobile (<768px) — full-screen view switching
   ============================================================ */
@media (max-width: 768px) {
  /* Toolbar */
  .toolbar-desktop { display: none; }
  .toolbar-mobile-only { display: inline-flex; }

  /* Tabs: smaller padding */
  .tab { padding: 8px 12px; font-size: 12px; }
  .tab .tab-close { width: 24px; height: 24px; font-size: 16px; }

  /* Main: stack and toggle */
  .main {
    flex-direction: column;
  }

  .preview-pane {
    height: auto;
    flex: 1;
    border-right: none;
    border-bottom: none;
  }

  .fields-pane {
    flex: 1;
    min-width: unset;
  }

  /* View switching */
  body[data-view="preview"] .fields-pane { display: none; }
  body[data-view="fields"] .preview-pane { display: none; }

  .view-switcher { display: flex; }

  /* Toast above view switcher */
  .toast { bottom: 100px; }

  /* Modal full-screen on mobile */
  .modal {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }

  .modal textarea {
    flex: 1;
    height: auto;
    min-height: 120px;
  }

  /* Bigger touch targets */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }
  .field-textarea { font-size: 16px; /* prevent iOS zoom */ }
  .login-input { font-size: 16px; }
}
