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

:root {
  --bg:        #0a0a0b;
  --bg-2:      #111113;
  --bg-3:      #1a1a1f;
  --border:    #2a2a32;
  --accent:    #e8ff47;
  --accent-2:  #ff6b35;
  --text:      #f0f0f2;
  --text-muted:#6b6b7a;
  --text-dim:  #3a3a48;
  --radius:    6px;
  --font-ui:   'Syne', sans-serif;
  --font-mono: 'DM Mono', monospace;
  --topbar-h:  56px;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── TOPBAR ── */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: rgba(10,10,11,.92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
}

.logo {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--accent);
}

#nav-auth {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .04em;
  padding: 7px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .2s, color .2s;
}
.btn-ghost:hover { border-color: var(--text-muted); color: var(--text); }

.btn-outline-accent {
  background: none;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 7px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .2s, color .2s;
}
.btn-outline-accent:hover { background: var(--accent); color: #000; }

.nav-user {
  display: flex;
  align-items: center;
  gap: 12px;
}
.nav-username {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.nav-username span { color: var(--accent); }

/* ── MAIN ── */
#app {
  display: flex;
  max-width: 860px;
  margin: var(--topbar-h) auto 0;
  padding: 0;
  min-height: calc(100vh - var(--topbar-h));
}

/* ── FEED SECTION ── */
#feed-section {
  flex: 1;
  border-right: 1px solid var(--border);
  min-height: 100%;
}

/* ── COMPOSE ── */
#compose-area {
  border-bottom: 1px solid var(--border);
  padding: 20px;
  background: var(--bg-2);
}

#compose-input {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: .95rem;
  line-height: 1.5;
  padding: 14px 16px;
  resize: none;
  min-height: 80px;
  transition: border-color .2s;
  outline: none;
}
#compose-input:focus { border-color: var(--accent); }
#compose-input::placeholder { color: var(--text-dim); }

.compose-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  margin-top: 10px;
}

#char-count {
  font-family: var(--font-mono);
  font-size: .8rem;
  color: var(--text-muted);
  transition: color .2s;
}
#char-count.warn { color: var(--accent-2); }
#char-count.danger { color: #ff3333; }

#btn-post {
  background: var(--accent);
  color: #000;
  border: none;
  font-family: var(--font-ui);
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 9px 22px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity .2s, transform .1s;
}
#btn-post:hover { opacity: .88; }
#btn-post:active { transform: scale(.97); }
#btn-post:disabled { opacity: .4; cursor: not-allowed; }

/* ── FEED ── */
#feed { padding: 0; }

.tweet-card {
  border-bottom: 1px solid var(--border);
  padding: 18px 20px;
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  cursor: default;
  transition: background .15s;
  animation: fadeSlide .3s ease both;
}
.tweet-card:hover { background: var(--bg-2); }

@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.tweet-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  font-family: var(--font-mono);
}

.tweet-body { min-width: 0; }

.tweet-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.tweet-author {
  font-weight: 700;
  font-size: .88rem;
  color: var(--text);
}

.tweet-time {
  font-size: .75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.tweet-dm-btn {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: .7rem;
  padding: 3px 10px;
  border-radius: 20px;
  cursor: pointer;
  transition: border-color .2s, color .2s;
  display: none;
}
.tweet-dm-btn:hover { border-color: var(--accent); color: var(--accent); }

.tweet-card:hover .tweet-dm-btn { display: block; }

.tweet-content {
  font-size: .92rem;
  line-height: 1.6;
  color: var(--text);
  word-break: break-word;
}

/* ── FEED LOADER / END ── */
#feed-loader {
  padding: 32px;
  text-align: center;
}
#feed-end {
  padding: 32px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: .75rem;
  color: var(--text-dim);
}

.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── DM SECTION ── */
#dm-section {
  width: 320px;
  flex-shrink: 0;
  padding: 20px;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#dm-section h2 {
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Inbox */
.inbox-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.inbox-item:hover { background: var(--bg-3); border-color: var(--text-dim); }

.inbox-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; color: var(--accent);
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.inbox-info { min-width: 0; }
.inbox-name { font-size: .85rem; font-weight: 600; }
.inbox-time { font-size: .72rem; color: var(--text-muted); font-family: var(--font-mono); }

/* Conversation */
#conversation { display: flex; flex-direction: column; gap: 10px; flex: 1; }

#conv-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

#btn-back-inbox {
  background: none; border: none;
  color: var(--text-muted); font-family: var(--font-mono); font-size: .75rem;
  cursor: pointer; padding: 4px 0;
}
#btn-back-inbox:hover { color: var(--text); }

#conv-username {
  font-weight: 700; font-size: .9rem;
  font-family: var(--font-mono); color: var(--accent);
}

#conv-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  padding-right: 4px;
}
#conv-messages::-webkit-scrollbar { width: 3px; }
#conv-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.dm-bubble {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: .82rem;
  line-height: 1.5;
  word-break: break-word;
}
.dm-bubble.sent {
  align-self: flex-end;
  background: var(--accent);
  color: #000;
  border-bottom-right-radius: 4px;
}
.dm-bubble.recv {
  align-self: flex-start;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

#dm-compose {
  display: flex;
  gap: 8px;
  margin-top: auto;
}
#dm-input {
  flex: 1;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: .82rem;
  padding: 8px 12px;
  outline: none;
}
#dm-input:focus { border-color: var(--accent); }
#btn-send-dm {
  background: var(--accent);
  color: #000;
  border: none;
  font-family: var(--font-ui);
  font-size: .78rem;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
}

/* ── MODALS ── */
#modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  z-index: 200;
}

.modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(.96);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 460px;
  padding: 36px 32px 32px;
  z-index: 210;
  opacity: 0;
  pointer-events: none;
  transition: transform .2s, opacity .2s;
}
.modal.open {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.modal h2 {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 24px;
  letter-spacing: -.02em;
}

.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  background: none; border: none;
  color: var(--text-muted); font-size: 1rem;
  cursor: pointer; padding: 4px 8px;
  border-radius: var(--radius);
  transition: color .15s, background .15s;
}
.modal-close:hover { color: var(--text); background: var(--bg-3); }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.form-group input {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: .9rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color .2s;
}
.form-group input:focus { border-color: var(--accent); }

.form-error {
  background: rgba(255,51,51,.1);
  border: 1px solid rgba(255,51,51,.3);
  color: #ff6666;
  font-size: .82rem;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 14px;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #000;
  border: none;
  font-family: var(--font-ui);
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: .02em;
  padding: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity .2s;
  margin-bottom: 16px;
}
.btn-primary:hover { opacity: .88; }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

.form-alt {
  font-size: .82rem;
  color: var(--text-muted);
  text-align: center;
}
.form-alt a { color: var(--accent); text-decoration: none; font-weight: 600; }
.form-alt a:hover { text-decoration: underline; }

/* ── TOAST ── */
#toast {
  position: fixed;
  bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: .85rem;
  font-family: var(--font-mono);
  padding: 12px 22px;
  border-radius: 32px;
  z-index: 300;
  opacity: 0;
  transition: transform .3s, opacity .3s;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
#toast.success { border-color: var(--accent); color: var(--accent); }
#toast.error   { border-color: #ff5555; color: #ff5555; }

/* ── TWEET ACTIONS BAR ── */
.tweet-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: .72rem;
  padding: 4px 10px;
  border-radius: 20px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.action-btn:hover {
  background: var(--bg-3);
  border-color: var(--border);
  color: var(--text);
}
.action-btn.liked {
  color: #ff5577;
  border-color: rgba(255,85,119,.3);
  background: rgba(255,85,119,.07);
}
.action-btn.liked:hover {
  background: rgba(255,85,119,.14);
}
.action-btn .action-icon { font-size: .85rem; line-height: 1; }

/* ── COMMENTS PANEL ── */
.comments-panel {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fadeSlide .2s ease both;
}

.comment-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.comment-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: .65rem; font-weight: 700; color: var(--accent);
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.comment-body { min-width: 0; }
.comment-author {
  font-size: .75rem;
  font-weight: 700;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-bottom: 2px;
}
.comment-author span { color: var(--accent); }
.comment-text {
  font-size: .82rem;
  color: var(--text);
  line-height: 1.5;
  word-break: break-word;
}

.comment-compose {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.comment-input {
  flex: 1;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: .82rem;
  padding: 7px 12px;
  outline: none;
  transition: border-color .2s;
}
.comment-input:focus { border-color: var(--accent); }
.comment-submit {
  background: var(--accent);
  color: #000;
  border: none;
  font-family: var(--font-ui);
  font-size: .75rem;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: opacity .2s;
}
.comment-submit:hover { opacity: .85; }

/* ── FORWARD MODAL ── */
#modal-forward .forward-preview {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: .82rem;
  color: var(--text-muted);
  line-height: 1.5;
}
#modal-forward .forward-preview strong {
  color: var(--accent);
  font-family: var(--font-mono);
  display: block;
  margin-bottom: 4px;
  font-size: .75rem;
}
#modal-forward .forward-preview p {
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── DM BUBBLE FORWARD ── */
.dm-bubble .forward-card {
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  border-left: 2px solid rgba(0,0,0,.25);
  background: rgba(0,0,0,.1);
  font-size: .75rem;
  line-height: 1.4;
}
.dm-bubble.recv .forward-card {
  border-left-color: var(--accent);
  background: rgba(232,255,71,.06);
}
.dm-bubble .forward-card .fwd-author {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: .7rem;
  opacity: .8;
  margin-bottom: 2px;
}
.dm-bubble .forward-card .fwd-content {
  opacity: .9;
}

/* ── UTILS ── */
.hidden { display: none !important; }

/* ── AUTO-REFRESH INDICATOR ── */
#refresh-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  display: inline-block;
  transition: background .3s;
}
#refresh-dot.active { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── RESPONSIVE ── */
@media (max-width: 640px) {
  #dm-section {
    display: none !important;
  }
  #feed-section {
    border-right: none;
  }
}


/* ── THEME SWITCHER (Light mode) ── */
body.light-mode {
  --bg:        #f5f5f7;
  --bg-2:      #ffffff;
  --bg-3:      #f0f0f2;
  --border:    #e0e0e6;
  --accent:    #0066cc;
  --accent-2:  #ff6b35;
  --text:      #1a1a1f;
  --text-muted:#6b6b7a;
  --text-dim:  #a0a0ab;
}

body.light-mode #topbar {
  background: rgba(255,255,255,.92);
  border-bottom-color: var(--border);
}

body.light-mode .tweet-card:hover {
  background: var(--bg-3);
}

body.light-mode .modal {
  background: var(--bg-2);
}

body.light-mode .form-error {
  background: rgba(255,51,51,.05);
}

body.light-mode .spinner {
  border-color: var(--border);
  border-top-color: var(--accent);
}

body.light-mode .dm-bubble.sent {
  background: var(--accent);
  color: white;
}

body.light-mode .dm-bubble.recv {
  background: #e5e5ea;
  border-color: var(--border);
  color: var(--text);
}

body.light-mode #toast {
  background: var(--bg-2);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

body.light-mode .inbox-item:hover {
  background: var(--bg-3);
}

body.light-mode .btn-ghost {
  border-color: var(--border);
}

body.light-mode .btn-ghost:hover {
  background: var(--bg-3);
}

body.light-mode .btn-outline-accent {
  border-color: var(--accent);
  color: var(--accent);
}

body.light-mode .btn-outline-accent:hover {
  background: var(--accent);
  color: white;
}

body.light-mode #compose-input,
body.light-mode .form-group input,
body.light-mode #dm-input {
  background: var(--bg-3);
  border-color: var(--border);
  color: var(--text);
}

body.light-mode .tweet-avatar {
  background: var(--bg-3);
  border-color: var(--border);
}

/* Animation de transition pour un changement fluide */
body,
#topbar,
.tweet-card,
.modal,
.dm-bubble,
.btn-ghost {
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}