/* ==========================================================================
   LarsChat — "Obsidian Terminal" Theme
   Deep charcoal + warm amber accents. Sharp geometry. Monospace precision.
   ========================================================================== */

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

:root {
  --black:       #0a0a0a;
  --obsidian:    #111111;
  --charcoal:    #1a1a1a;
  --graphite:    #242424;
  --slate:       #2e2e2e;
  --steel:       #3a3a3a;
  --ash:         #555;
  --smoke:       #888;
  --text:        #d4d0c8;
  --text-bright: #ebe8e0;

  --amber:       #d4a843;
  --amber-dim:   #b8922e;
  --amber-glow:  rgba(212, 168, 67, 0.12);
  --amber-ghost: rgba(212, 168, 67, 0.06);

  --red:         #c45c5c;
  --red-dim:     #a34848;
  --red-glow:    rgba(196, 92, 92, 0.12);

  --green:       #5a9e6f;

  --border:      #2a2a2a;
  --border-light:#333;

  --font-mono: 'IBM Plex Mono', 'SF Mono', 'Fira Code', monospace;
  --font-body: 'DM Sans', -apple-system, sans-serif;

  --radius: 0px;

  --header-h: 52px;
  --footer-h: 50px;
}

body {
  font-family: var(--font-body);
  background: var(--black);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Noise texture overlay */
.noise-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

/* Selection */
::selection {
  background: var(--amber);
  color: var(--black);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--steel);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--ash);
}

/* ==========================================================================
   Shared Elements
   ========================================================================== */

/* Inputs */
input[type="text"],
input[type="password"] {
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--obsidian);
  color: var(--text-bright);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}

input:focus {
  border-color: var(--amber-dim);
  box-shadow: 0 0 0 1px var(--amber-dim);
}

input::placeholder,
textarea::placeholder {
  color: var(--ash);
  font-family: var(--font-mono);
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.input-group label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--smoke);
}

.input-with-prefix {
  position: relative;
}

.input-prefix {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--amber);
  font-family: var(--font-mono);
  font-weight: 600;
  pointer-events: none;
}

.input-with-prefix input {
  padding-left: 1.8rem;
}

/* Buttons */
button {
  padding: 0.65rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--graphite);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  line-height: 1;
}

button:hover {
  background: var(--slate);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--amber);
  color: var(--black);
  font-weight: 600;
  border-color: var(--amber);
}

.btn-primary:hover {
  background: var(--amber-dim);
  border-color: var(--amber-dim);
}

.btn-ghost {
  background: transparent;
  color: var(--smoke);
  border-color: var(--border-light);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--ash);
  background: var(--amber-ghost);
}

.btn-full {
  width: 100%;
}

.danger-btn {
  background: var(--red-glow);
  color: var(--red);
  border-color: rgba(196, 92, 92, 0.25);
}

.danger-btn:hover {
  background: rgba(196, 92, 92, 0.2);
  border-color: var(--red-dim);
}

.error {
  color: var(--red);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.5rem 0.7rem;
  background: var(--red-glow);
  border-left: 2px solid var(--red);
}

.hint {
  color: var(--ash);
  font-size: 0.78rem;
  font-family: var(--font-mono);
}

/* ==========================================================================
   Views
   ========================================================================== */

.view {
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

[hidden] {
  display: none !important;
}

/* ==========================================================================
   Auth Views
   ========================================================================== */

#view-login {
  background:
    radial-gradient(ellipse 60% 50% at 50% 45%, var(--amber-ghost) 0%, transparent 70%),
    var(--black);
}

.auth-card {
  background: var(--obsidian);
  border: 1px solid var(--border);
  padding: 2.5rem;
  max-width: 420px;
  width: 92%;
  position: relative;
  animation: cardIn 0.4s ease-out;
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.auth-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--amber-dim), transparent);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--amber);
  color: var(--amber);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.05em;
}

.auth-brand h1 {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-bright);
  letter-spacing: -0.01em;
}

.auth-subtitle {
  text-align: center;
  color: var(--smoke);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 1.75rem;
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-card .error {
  margin-top: 0.75rem;
}

/* ==========================================================================
   Chat Layout
   ========================================================================== */

.chat-layout {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

/* Sidebar */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--obsidian);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  position: relative;
}

.sidebar-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, var(--amber-dim), transparent 70%);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-glyph {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--amber);
  border: 1px solid var(--amber-dim);
  padding: 0.15rem 0.35rem;
  letter-spacing: 0.05em;
  line-height: 1;
}

.sidebar-header h2 {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-bright);
}

.sidebar-header > button {
  background: none;
  border: none;
  color: var(--ash);
  padding: 0.3rem;
  transition: color 0.15s;
}

.sidebar-header > button:hover {
  color: var(--amber);
  background: none;
}

.sidebar-section {
  padding: 0.5rem 0 0.25rem;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ash);
}

.sidebar-section-header button {
  background: none;
  border: none;
  color: var(--ash);
  padding: 0.15rem;
  transition: color 0.15s;
}

.sidebar-section-header button:hover {
  color: var(--amber);
  background: none;
}

.sidebar ul {
  list-style: none;
}

.sidebar li {
  padding: 0.4rem 1rem;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--smoke);
  transition: all 0.1s;
  border-left: 2px solid transparent;
  font-family: var(--font-body);
  display: flex;
  align-items: center;
}

.sidebar li:hover {
  background: var(--amber-ghost);
  color: var(--text);
}

.sidebar li.active {
  background: var(--amber-ghost);
  color: var(--amber);
  border-left-color: var(--amber);
  font-weight: 500;
}

.sidebar li .channel-prefix {
  color: var(--amber-dim);
  font-family: var(--font-mono);
  font-weight: 500;
  margin-right: 0.1rem;
}

.sidebar li .channel-name,
.sidebar li .dm-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.sidebar li.has-unread {
  color: var(--text-bright);
  font-weight: 500;
}

.unread-badge {
  margin-left: auto;
  background: var(--amber);
  color: var(--black);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 9px;
  line-height: 1.3;
  min-width: 1.2rem;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-user {
  margin-top: auto;
  padding: 0 1rem;
  height: var(--footer-h);
  display: flex;
  align-items: center;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--smoke);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Chat Main
   ========================================================================== */

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--black);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-bright);
  background: var(--obsidian);
}

.chat-header-info {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  min-width: 0;
}

.chat-created-by {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--ash);
  white-space: nowrap;
}

.chat-header .danger-btn {
  font-size: 0.75rem;
  padding: 0.35rem 0.65rem;
}

/* Messages Area */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  flex-direction: column;
}

#btn-load-earlier {
  align-self: center;
  margin-bottom: 0.75rem;
  background: var(--charcoal);
  border: 1px solid var(--border-light);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--smoke);
  padding: 0.4rem 1rem;
}

#btn-load-earlier:hover {
  border-color: var(--amber-dim);
  color: var(--amber);
}

#message-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* Messages */
.msg {
  padding: 0.55rem 0.85rem;
  border-left: 2px solid var(--border-light);
  background: transparent;
  transition: background 0.1s;
}

.msg:hover {
  background: var(--amber-ghost);
}

.msg.own {
  border-left-color: var(--amber-dim);
}

.msg-header {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  margin-bottom: 0.15rem;
}

.msg-sender {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.82rem;
  color: var(--amber);
}

.msg-time {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ash);
}

.msg-content {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
  tab-size: 4;
  color: var(--text);
}

.msg-content a {
  color: var(--amber);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg-content a:hover {
  color: var(--amber-dim);
}

.msg-content a:visited {
  color: var(--amber-dim);
}

.read-receipt {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--smoke);
  margin-left: 0.5rem;
  letter-spacing: 0.04em;
}

/* Message Input */
.message-form {
  display: flex;
  gap: 0;
  padding: 0;
  min-height: var(--footer-h);
  max-height: 150px;
  border-top: 1px solid var(--border);
  background: var(--obsidian);
}

.message-form textarea {
  flex: 1;
  border: none;
  background: var(--obsidian);
  padding: 0.85rem 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  border-radius: 0;
  resize: none;
  line-height: 1.4;
  color: var(--text-bright);
  outline: none;
}

.message-form textarea:focus {
  box-shadow: none;
  border: none;
}

.message-form button {
  background: var(--amber);
  color: var(--black);
  border: none;
  padding: 0.85rem 1.25rem;
  border-radius: 0;
  transition: background 0.15s;
}

.message-form button:hover {
  background: var(--amber-dim);
}

/* ==========================================================================
   Emoji Picker
   ========================================================================== */

.emoji-btn-wrap {
  position: relative;
}

#btn-emoji {
  background: none;
  border: none;
  color: var(--amber);
  padding: 0.6rem 0.5rem;
  border-radius: 0;
  transition: color 0.15s;
}

#btn-emoji:hover,
#btn-emoji.active {
  color: var(--amber);
  background: none;
}

#emoji-picker {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  width: 380px;
  display: flex;
  flex-direction: column;
  background: var(--charcoal);
  border: 1px solid var(--border-light);
  z-index: 50;
}

.emoji-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.emoji-tabs::-webkit-scrollbar {
  display: none;
}

#emoji-picker .emoji-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.35rem 0;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  flex: 1 1 0;
  min-width: 0;
  border-radius: 0;
}

#emoji-picker .emoji-tab:hover {
  background: var(--steel);
}

#emoji-picker .emoji-tab.active {
  background: transparent;
  border-bottom-color: var(--amber);
}

.emoji-panel {
  height: 240px;
  overflow-y: auto;
  padding: 0.5rem;
  border-top: 1px solid var(--border-light);
}

.emoji-category-label {
  display: block;
  position: sticky;
  top: 0;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ash);
  padding: 0.25rem 0.15rem 0.35rem;
  background: var(--charcoal);
  z-index: 1;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(9, auto);
}

#emoji-picker .emoji-grid button {
  background: transparent;
  border: none;
  padding: 0.3rem;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.1s;
}

#emoji-picker .emoji-grid button:hover {
  background: var(--steel);
}

/* ==========================================================================
   Modals
   ========================================================================== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: var(--charcoal);
  border: 1px solid var(--border-light);
  max-width: 440px;
  width: 92%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--amber-dim), transparent);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-bright);
}

.modal-close {
  background: none !important;
  border: none !important;
  color: var(--ash);
  font-size: 1.3rem;
  padding: 0.2rem 0.4rem;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text) !important;
  background: none !important;
}

.modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.modal-body form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.modal-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.25rem 0;
}

/* Settings */
.settings-identity {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.settings-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ash);
}

.settings-identity strong {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--amber);
  font-weight: 500;
}

.settings-section h3 {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-bright);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.25rem;
}

.form-error {
  color: var(--red);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.form-success {
  color: var(--green);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.settings-danger h3 {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.25rem;
}

.settings-danger > p {
  font-size: 0.85rem;
  color: var(--smoke);
  margin-bottom: 0.75rem;
}

.confirm-warning {
  color: var(--red);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  margin-top: 0.5rem;
}

.confirm-actions {
  display: flex;
  gap: 0.5rem;
}

/* DM Contacts */
#dm-contacts-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#dm-contacts-list button {
  background: var(--obsidian);
  border: 1px solid var(--border);
  text-align: left;
  padding: 0.6rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text);
}

#dm-contacts-list button:hover {
  border-color: var(--amber-dim);
  color: var(--amber);
  background: var(--amber-ghost);
}

#dm-contacts-empty {
  color: var(--ash);
  font-size: 0.85rem;
  font-family: var(--font-mono);
  text-align: center;
  padding: 1rem 0;
}

/* ==========================================================================
   Online Users Panel
   ========================================================================== */

.users-panel {
  width: 180px;
  min-width: 180px;
  background: var(--obsidian);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.users-panel-header {
  display: flex;
  align-items: center;
  height: var(--header-h);
  padding: 0 1rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ash);
  border-bottom: 1px solid var(--border);
}

#online-users {
  list-style: none;
}

#online-users li {
  padding: 0.4rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--smoke);
}

#online-users li.clickable {
  cursor: pointer;
}

#online-users li.clickable:hover {
  background: var(--amber-ghost);
  color: var(--amber);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

.sidebar-toggle,
.users-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--smoke);
  padding: 0.3rem;
}

.sidebar-toggle:hover,
.users-toggle:hover {
  color: var(--amber);
  background: none;
}

.sidebar-overlay {
  display: none;
}

@media (max-width: 640px) {
  .sidebar-toggle,
  .users-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    min-width: 260px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 199;
  }

  .sidebar-overlay.open {
    display: block;
  }

  .users-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 220px;
    min-width: 220px;
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.2s ease;
  }

  .users-panel.open {
    transform: translateX(0);
  }

  .auth-card {
    padding: 2rem 1.5rem;
  }
}
