*,
*::before,
*::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #070d18;
  --surface: #0f1a2e;
  --surface2: #162236;
  --border: rgba(201, 169, 98, 0.15);
  --gold: #c9a962;
  --gold-dim: rgba(201, 169, 98, 0.5);
  --text: #eef2f7;
  --muted: rgba(238, 242, 247, 0.55);
  --user-bg: #1a3050;
  --ai-bg: #121f33;
  --accent: #5b9fd4;
  --radius: 12px;
}

html, body { height: 100%; }

.boot-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text);
  padding: 24px;
  text-align: center;
}
.boot-logo { font-size: 1.6rem; font-weight: 700; margin-bottom: 12px; }
.boot-logo span { color: var(--gold); }
.boot-msg { font-size: 0.9rem; color: var(--muted); max-width: 320px; line-height: 1.6; }

body {
  font-family: var(--opc-font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.hidden { display: none !important; }

/* Auth gate */
.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 30% 20%, rgba(201,169,98,0.08), transparent 50%),
              var(--bg);
}
.auth-card {
  width: min(360px, 92vw);
  padding: 36px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  text-align: center;
}
.auth-logo { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }
.auth-logo span { color: var(--gold); }
.auth-card p { color: var(--muted); font-size: 0.9rem; margin-bottom: 20px; }
.auth-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  margin-bottom: 12px;
}
.auth-error { color: #f87171; font-size: 0.85rem; margin-top: 10px; min-height: 1.2em; }

/* Layout */
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.brand-mark { color: var(--gold); font-size: 1.4rem; }
.brand strong { display: block; font-size: 0.95rem; }
.brand small { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.06em; }

.sidebar-section { margin-bottom: 20px; }
.sidebar-section label,
.section-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}
.sidebar-section select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
}

.template-list { display: flex; flex-direction: column; gap: 6px; }
.tpl-btn {
  text-align: left;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.tpl-btn:hover { border-color: var(--gold-dim); background: rgba(201,169,98,0.06); }
.tpl-btn.active { border-color: var(--gold); color: var(--gold); }

.sidebar-status {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
  padding-top: 16px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
}
.status-dot.online { background: #22c55e; }
.status-dot.template { background: #eab308; }

.sidebar-footer {
  padding-top: 12px;
  font-size: 0.82rem;
}
.sidebar-footer a { color: var(--gold-dim); text-decoration: none; }
.sidebar-footer a:hover { color: var(--gold); }

/* Chat */
.chat-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: linear-gradient(180deg, var(--bg) 0%, #0a1220 100%);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
}
.chat-header h1 { font-size: 1.1rem; font-weight: 600; }
.chat-header p { font-size: 0.82rem; color: var(--muted); margin-top: 4px; }

.btn-ghost, .btn-primary, .btn-send {
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.2s, transform 0.15s;
}
.btn-ghost {
  padding: 8px 14px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--gold-dim); }
.btn-primary {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--gold), #a8863f);
  color: #0a1628;
  font-weight: 600;
}
.btn-primary:hover { opacity: 0.92; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg {
  display: flex;
  gap: 12px;
  max-width: 820px;
  animation: fadeIn 0.3s ease;
}
.msg-user { align-self: flex-end; flex-direction: row-reverse; }
.msg-assistant { align-self: flex-start; }

.msg-avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
}
.msg-user .msg-avatar { background: var(--accent); color: #fff; }
.msg-assistant .msg-avatar { background: rgba(201,169,98,0.15); color: var(--gold); border: 1px solid var(--border); }

.msg-body {
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 0.92rem;
  line-height: 1.75;
}
.msg-user .msg-body { background: var(--user-bg); border-bottom-right-radius: 4px; }
.msg-assistant .msg-body { background: var(--ai-bg); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

.msg-body p { margin-bottom: 0.6em; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body em { color: var(--gold-dim); font-style: normal; }
.msg-body strong { color: var(--gold); }
.msg-body h1, .msg-body h2, .msg-body h3 { font-size: 1rem; margin: 1em 0 0.5em; color: var(--gold); }
.msg-body ul, .msg-body ol { margin: 0.5em 0 0.5em 1.2em; }
.msg-body code {
  background: rgba(0,0,0,0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
}
.msg-body pre {
  background: rgba(0,0,0,0.35);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.8em 0;
  font-size: 0.85em;
  white-space: pre-wrap;
}

.msg-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.msg-actions button {
  padding: 5px 12px;
  font-size: 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}
.msg-actions button:hover { color: var(--gold); border-color: var(--gold-dim); }

.msg.loading .msg-body::after {
  content: '▋';
  animation: blink 1s step-end infinite;
  color: var(--gold);
  margin-left: 4px;
}

.composer {
  display: flex;
  gap: 12px;
  padding: 16px 28px 24px;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 160px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.5;
}
.composer textarea:focus { outline: none; border-color: var(--gold-dim); }
.btn-send {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--gold), #a8863f);
  color: #0a1628;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { transform: scale(1.04); }
.btn-send:disabled { opacity: 0.45; cursor: not-allowed; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes blink { 50% { opacity: 0; } }

.sidebar-footer.sidebar-nav-links { display: flex; flex-direction: column; gap: 8px; }
.sidebar-footer a { color: var(--gold-dim, rgba(201,169,98,0.5)); text-decoration: none; font-size: 0.82rem; }
.sidebar-footer a:hover { color: var(--gold, #c9a962); }

.posts-mini { max-height: 140px; overflow-y: auto; font-size: 0.75rem; }
.posts-mini .muted { opacity: 0.45; }
.post-item { padding: 6px 0; border-bottom: 1px solid rgba(128,128,128,0.1); }
.post-status { color: var(--gold, #c9a962); margin-right: 6px; }
.post-preview { opacity: 0.6; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.msg-actions .btn-publish { color: var(--gold, #c9a962); border-color: rgba(201,169,98,0.4); }

.btn-sm { padding: 6px 14px !important; font-size: 0.82rem !important; }

.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-box {
  position: relative; background: var(--surface, #0f1a2e); border: 1px solid var(--border);
  border-radius: 14px; padding: 24px; width: min(440px, 92vw); max-height: 85vh; overflow-y: auto;
}
.modal-box h3 { margin-bottom: 8px; color: var(--gold, #c9a962); }
.modal-desc { font-size: 0.85rem; color: var(--muted); margin-bottom: 16px; }
.platform-checks { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.plat-check { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; cursor: pointer; }
.schedule-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 0.85rem; margin-bottom: 20px; }
.schedule-row input[type="datetime-local"] {
  padding: 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-family: inherit;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .brand { margin-bottom: 0; padding-bottom: 0; border: none; width: 100%; }
  .sidebar-section { flex: 1; min-width: 140px; margin-bottom: 0; }
  .template-list { flex-direction: row; flex-wrap: wrap; }
  .sidebar-status, .sidebar-footer { display: none; }
  .messages { padding: 16px; }
  .composer { padding: 12px 16px 20px; }
}
