/* ============================================================
   ProStudy Sim Editor - Stylesheet
   Dark theme with ProStudy brand colors
   ============================================================ */

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-deep:       #0D3B4C;
  --bg-panel:      #1A5568;
  --bg-card:       #1E6178;
  --accent:        #2D9596;
  --accent-hover:  #35ACAD;
  --success:       #4ADE80;
  --error:         #F87171;
  --warning:       #FBBF24;
  --text:          #E2E8F0;
  --text-muted:    #94A3B8;
  --text-dim:      #64748B;
  --terminal-bg:   #0d1117;
  --terminal-text: #4ADE80;
  --bezel:         #1a1a2e;
  --input-bg:      #0F4456;
  --border:        #2D7A8A;
  --phone-scale:   0.7;
  --font-mono:     'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --font-ui:       'Inter', system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-deep);
  -webkit-font-smoothing: antialiased;
}

[x-cloak] {
  display: none !important;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-full {
  width: 100%;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 6px 12px;
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.btn-send {
  background: var(--accent);
  color: #fff;
  padding: 10px 20px;
  min-width: 80px;
}

.btn-send:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-stop {
  background: var(--error);
  color: #fff;
  padding: 10px 16px;
}

.btn-stop:hover:not(:disabled) {
  background: #EF4444;
}

.btn-revert {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
}

.btn-revert:hover:not(:disabled) {
  color: var(--error);
  border-color: var(--error);
}

/* ---------- Login ---------- */
.login-backdrop {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg-deep);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-panel);
  border-radius: 16px;
  padding: 40px 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.login-brand svg {
  margin-bottom: 16px;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-muted);
}

.login-form .form-group {
  margin-bottom: 20px;
}

.login-form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.login-form input {
  width: 100%;
  padding: 12px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-ui);
  outline: none;
  transition: border-color 0.15s;
}

.login-form input:focus {
  border-color: var(--accent);
}

.login-error {
  color: var(--error);
  font-size: 13px;
  margin-bottom: 12px;
  text-align: center;
}

/* ---------- Editor Layout ---------- */
.editor-layout {
  display: grid;
  grid-template-rows: auto 1fr 180px auto;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Header ---------- */
.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  gap: 16px;
}

.header-left {
  flex-shrink: 0;
}

.header-brand {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.header-center {
  flex: 1;
  max-width: 400px;
  margin: 0 auto;
}

.sim-selector {
  width: 100%;
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-ui);
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='%2394A3B8'%3E%3Cpath d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.sim-selector:focus {
  border-color: var(--accent);
}

.sim-selector option {
  background: var(--bg-panel);
  color: var(--text);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.status-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.status-dot.dot-idle {
  background: var(--success);
}

.status-dot.dot-working {
  background: var(--warning);
  animation: pulse-dot 1.5s ease-in-out infinite;
}

.status-dot.dot-queued {
  background: var(--warning);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-dot.dot-error,
.status-dot.dot-disconnected {
  background: var(--error);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.status-text {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.session-counter {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
  font-family: var(--font-mono);
  background: var(--input-bg);
  padding: 4px 8px;
  border-radius: 6px;
}

/* ---------- Main 3-Column Grid ---------- */
.editor-main {
  display: grid;
  grid-template-columns: 40% 35% 25%;
  gap: 1px;
  background: var(--border);
  overflow: hidden;
}

/* ---------- Panels ---------- */
.panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-deep);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panel-body {
  flex: 1;
  overflow: auto;
  position: relative;
}

.panel-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
}

.panel-placeholder p {
  color: var(--text-dim);
  font-size: 14px;
}

/* ---------- PDF Panel ---------- */
.pdf-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

/* ---------- Phone Preview ---------- */
.phone-container {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 12px 12px;
  overflow: hidden;
}

.phone-scaler {
  transform-origin: top center;
  flex-shrink: 0;
}

.phone-frame {
  width: 376px;
  height: 828px;
  border-radius: 44px;
  border: 8px solid var(--bezel);
  background: #000;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  position: relative;
}

.phone-notch {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 28px;
  background: var(--bezel);
  border-radius: 0 0 18px 18px;
  z-index: 2;
}

.phone-iframe {
  width: 360px;
  height: 800px;
  border: none;
  background: #fff;
}

.file-size-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(45, 149, 150, 0.15);
  padding: 2px 8px;
  border-radius: 10px;
  font-family: var(--font-mono);
}

/* ---------- History Panel ---------- */
.history-count {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}

.history-list {
  padding: 8px;
}

.history-entry {
  background: var(--bg-panel);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
}

.history-prompt {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 8px;
  word-break: break-word;
}

.history-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.history-time {
  font-size: 12px;
  color: var(--text-dim);
}

.history-size-delta {
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-mono);
}

.history-size-delta.size-up {
  color: var(--warning);
}

.history-size-delta.size-down {
  color: var(--success);
}

.history-status {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 1px 6px;
  border-radius: 4px;
}

.history-status.status-completed {
  color: var(--success);
  background: rgba(74, 222, 128, 0.1);
}

.history-status.status-failed {
  color: var(--error);
  background: rgba(248, 113, 113, 0.1);
}

.history-status.status-reverted {
  color: var(--text-muted);
  background: rgba(148, 163, 184, 0.1);
}

.history-status.status-pending {
  color: var(--warning);
  background: rgba(251, 191, 36, 0.1);
}

/* ---------- Terminal ---------- */
.terminal-panel {
  display: flex;
  flex-direction: column;
  background: var(--terminal-bg);
  border-top: 1px solid var(--border);
  overflow: hidden;
}

.terminal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}

.terminal-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.terminal-ws-status {
  font-size: 11px;
  font-weight: 500;
}

.terminal-ws-status.ws-connected {
  color: var(--success);
}

.terminal-ws-status.ws-disconnected {
  color: var(--error);
}

.terminal-output {
  flex: 1;
  padding: 12px 16px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--terminal-text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Input Bar ---------- */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
}

.input-wrapper {
  flex: 1;
  position: relative;
}

.input-wrapper textarea {
  width: 100%;
  padding: 10px 14px;
  padding-right: 90px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-ui);
  outline: none;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.input-wrapper textarea:focus {
  border-color: var(--accent);
}

.input-wrapper textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.char-counter {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  pointer-events: none;
}

.char-counter.char-warn {
  color: var(--warning);
}

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .editor-main {
    grid-template-columns: 50% 50%;
  }

  .panel-history {
    display: none;
  }
}

@media (max-width: 900px) {
  .editor-main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .panel-history {
    display: none;
  }

  .phone-container {
    padding: 12px 8px;
  }

  .header-center {
    max-width: 200px;
  }
}

/* ---------- Scrollbar Styling ---------- */
::-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(--accent);
}

/* ---------- Selection ---------- */
::selection {
  background: rgba(45, 149, 150, 0.3);
  color: var(--text);
}
