@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root{
  --bg: #0d1117;
  --bg-raised: #141a24;
  --line: #232b38;
  --brass: #d9a441;
  --brass-dim: #8a6a2c;
  --text: #e7e9ee;
  --text-dim: #8b93a3;
  --danger: #e2645a;
  --radius: 14px;
  --font-body: 'Vazirmatn', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

*{ box-sizing: border-box; }

html, body{
  height: 100%;
  margin: 0;
}

body{
  background:
    radial-gradient(circle at 50% -10%, rgba(217,164,65,0.08), transparent 45%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.hidden{ display: none !important; }

button{ font-family: inherit; cursor: pointer; }
input, textarea{ font-family: inherit; }

/* ---------- Gate (login) ---------- */

.gate{
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card{
  width: 100%;
  max-width: 360px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 40px 32px 32px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  position: relative;
  overflow: hidden;
}

.gate-card::before{
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--brass), transparent);
  opacity: 0.6;
}

.gate-mark{
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brass);
  background: radial-gradient(circle, rgba(217,164,65,0.14), transparent 70%);
  border: 1px solid var(--brass-dim);
}

.gate h1{
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 6px;
  color: var(--text);
}

.gate-sub{
  color: var(--text-dim);
  font-size: 14px;
  margin: 0 0 26px;
}

#gate-form{
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#gate-password{
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 16px;
  color: var(--text);
  font-size: 15px;
  text-align: center;
  letter-spacing: 0.15em;
  outline: none;
  transition: border-color .15s;
}
#gate-password:focus{
  border-color: var(--brass);
}

#gate-form button{
  background: var(--brass);
  color: #1a1305;
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  transition: filter .15s, transform .05s;
}
#gate-form button:hover{ filter: brightness(1.08); }
#gate-form button:active{ transform: scale(0.98); }
#gate-form button:disabled{ opacity: 0.6; cursor: default; }

.gate-error{
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
  margin: 14px 0 0;
}

/* ---------- Chat shell + sidebar ---------- */

.chat{
  height: 100dvh;
  max-width: none;
  margin: 0;
}

.app-shell{
  height: 100%;
  display: flex;
}

.sidebar{
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-raised);
  border-inline-end: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.sidebar-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 14px;
  border-bottom: 1px solid var(--line);
}

.brand{
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
  color: var(--brass);
}

.new-chat-btn{
  background: transparent;
  border: 1px solid var(--brass-dim);
  color: var(--brass);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
  transition: background .15s;
}
.new-chat-btn:hover{
  background: rgba(217,164,65,0.1);
}

.conversation-list{
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conversation-item{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.conversation-item:hover{
  background: rgba(255,255,255,0.04);
  color: var(--text);
}
.conversation-item.active{
  background: rgba(217,164,65,0.12);
  color: var(--text);
}

.conversation-title{
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.conversation-delete{
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-dim);
  opacity: 0;
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  transition: opacity .12s, color .12s;
}
.conversation-item:hover .conversation-delete{
  opacity: 1;
}
.conversation-delete:hover{
  color: var(--danger);
}

.conversation-empty{
  color: var(--text-dim);
  font-size: 12.5px;
  padding: 14px 10px;
  text-align: center;
  line-height: 1.8;
}

.sidebar-overlay{
  display: none;
}

.chat-main{
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-toggle{
  display: none;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  padding: 4px 6px;
}

/* ---------- Chat ---------- */

.chat-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.chat-title{
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.03em;
  color: var(--text-dim);
}

.dot{
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brass);
  box-shadow: 0 0 8px var(--brass);
}

.header-actions{
  display: flex;
  align-items: center;
  gap: 10px;
}

.model-select{
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color .15s, color .15s;
}
.model-select:hover, .model-select:focus{
  color: var(--text);
  border-color: var(--brass-dim);
}

.logout-btn{
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  transition: border-color .15s, color .15s;
}
.logout-btn:hover{
  color: var(--text);
  border-color: var(--brass-dim);
}

.messages{
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.msg{
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.75;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user{
  align-self: flex-start;
  background: var(--bg-raised);
  border: 1px solid var(--line);
}

.msg.assistant{
  align-self: flex-end;
  background: linear-gradient(180deg, rgba(217,164,65,0.10), rgba(217,164,65,0.04));
  border: 1px solid rgba(217,164,65,0.25);
}

.msg.assistant.streaming::after{
  content: "▌";
  color: var(--brass);
  animation: blink 1s steps(1) infinite;
  margin-inline-start: 2px;
}

.msg.error{
  align-self: center;
  color: var(--danger);
  background: rgba(226,100,90,0.08);
  border: 1px solid rgba(226,100,90,0.3);
  font-family: var(--font-mono);
  font-size: 13px;
}

@keyframes blink{
  50%{ opacity: 0; }
}

.chat-form{
  display: flex;
  gap: 10px;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--line);
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

#chat-input{
  flex: 1;
  resize: none;
  max-height: 140px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}
#chat-input:focus{
  border-color: var(--brass-dim);
}

#send-btn{
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border: none;
  border-radius: 12px;
  background: var(--brass);
  color: #1a1305;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter .15s, transform .05s;
}
#send-btn:hover{ filter: brightness(1.08); }
#send-btn:active{ transform: scale(0.95); }
#send-btn:disabled{ opacity: 0.5; cursor: default; }

@media (max-width: 720px){
  .sidebar-toggle{
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .sidebar{
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
  }
  html[dir="rtl"] .sidebar{
    transform: translateX(100%);
  }
  .sidebar.open{
    transform: translateX(0);
  }
  .sidebar-overlay.open{
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 15;
  }
}

@media (max-width: 480px){
  .gate-card{ padding: 32px 22px 26px; }
  .messages{ padding: 18px 14px; }
  .chat-form{ padding: 12px 14px 16px; }
  .msg{ max-width: 90%; }
}

@media (prefers-reduced-motion: reduce){
  .msg.assistant.streaming::after{ animation: none; }
}
