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

:root {
  --bg: #f3efe6;
  --card: #fff;
  --primary: #2c5f4e;
  --soft: #e4eee9;
  --text: #1c2724;
  --muted: #6b7a75;
  --line: #e2d9c9;
  --danger: #9b3a3a;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Vazirmatn, Tahoma, sans-serif;
}
[hidden] { display: none !important; }
#appShell { display: none !important; }
body.is-app { background: var(--bg); height: 100%; overflow: hidden; }
body.is-app #loginGate { display: none !important; }
body.is-app #appShell { display: grid !important; height: 100%; overflow: hidden; }
body.is-login,
body.is-login html {
  background: #16352c;
  height: 100%;
  overflow: hidden;
}
.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.side {
  background: var(--card);
  border-left: 1px solid var(--line);
  padding: 0.7rem 0.8rem;
  overflow: hidden;
}
main {
  padding: 0.55rem 0.8rem 0.6rem;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
h1 { margin: 0 0 0.2rem; font-size: 1.05rem; }
.muted { color: var(--muted); font-size: 0.78rem; }
.pills { display: flex; flex-wrap: wrap; gap: 0.28rem; margin: 0.4rem 0; }
.pills span { background: var(--soft); color: var(--primary); border-radius: 999px; padding: 0.12rem 0.45rem; font-size: 0.68rem; }
button { background: var(--primary); color: #fff; border: 0; border-radius: 10px; padding: 0.45rem 0.75rem; cursor: pointer; font-family: inherit; font-weight: 700; }
button:disabled { opacity: 0.6; cursor: wait; }
.disclaimer { font-size: 0.68rem; color: var(--muted); margin-top: 0.45rem; }
.tabs { display: flex; gap: 0.3rem; flex-wrap: nowrap; margin-bottom: 0.4rem; flex-shrink: 0; }
.tab { background: var(--card); color: var(--text); border: 1px solid var(--line); padding: 0.4rem 0.65rem; font-size: 0.8rem; }
.tab.on { background: var(--primary); color: #fff; }
.panel { display: none; }
.panel.on {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.error { color: var(--danger); background: #fdeeee; padding: 0.4rem 0.6rem; border-radius: 10px; flex-shrink: 0; }
.messages { background: var(--card); border: 1px solid var(--line); border-radius: 14px; flex: 1; min-height: 0; overflow: auto; padding: 0.7rem; }
.bubble { max-width: 80%; margin: 0.4rem 0; padding: 0.55rem 0.75rem; border-radius: 14px; line-height: 1.6; }
.bubble.user { background: var(--primary); color: #fff; margin-right: auto; }
.bubble.assistant { background: #fff; border: 1px solid var(--line); margin-left: auto; }
.bubble b { display: block; font-size: 0.72rem; opacity: 0.8; margin-bottom: 0.15rem; }
.composer { display: flex; gap: 0.5rem; margin-top: 0.45rem; flex-shrink: 0; }
textarea, input[type="range"] { width: 100%; }
textarea { border: 1px solid var(--line); border-radius: 10px; padding: 0.5rem; font-family: inherit; }
.composer textarea { flex: 1; min-height: 42px; max-height: 42px; }
label { display: block; margin: 0.25rem 0 0.05rem; font-size: 0.82rem; }
.check { display: flex; align-items: center; gap: 0.5rem; }
#logList, #forecast { margin-top: 0.4rem; min-height: 0; overflow: auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 0.55rem; margin-bottom: 0.4rem; }
pre, code, .deep-eval, #deepBox {
  font-family: Vazirmatn, Tahoma, sans-serif !important;
  direction: rtl;
  text-align: right;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 2;
  font-size: 0.98rem;
  letter-spacing: 0;
}

.deep-eval {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  margin-top: 0.55rem;
}

.login-gate {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(201, 162, 94, 0.28), transparent 55%),
    radial-gradient(900px 500px at -10% 110%, rgba(90, 158, 132, 0.35), transparent 50%),
    linear-gradient(160deg, #10251f 0%, #1b3d33 42%, #24473c 100%);
}
.login-bg { position: absolute; inset: 0; pointer-events: none; }
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(8px);
  opacity: 0.45;
}
.orb-a {
  width: 280px; height: 280px; top: 8%; right: 12%;
  background: radial-gradient(circle, #d4b483, transparent 68%);
}
.orb-b {
  width: 340px; height: 340px; bottom: -8%; left: -4%;
  background: radial-gradient(circle, #3f8f74, transparent 70%);
}
.orb-c {
  width: 140px; height: 140px; top: 42%; left: 18%;
  background: radial-gradient(circle, rgba(255,255,255,0.35), transparent 70%);
}
.login-card {
  position: relative;
  width: min(430px, 100%);
  background: rgba(255, 251, 245, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 28px;
  padding: 2.1rem 1.8rem 1.6rem;
  box-shadow: 0 30px 70px rgba(8, 20, 16, 0.35);
  backdrop-filter: blur(16px);
  text-align: right;
}
.login-mark {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  margin: 0 auto 1rem;
  background: linear-gradient(145deg, #2c5f4e, #1a3d33);
  color: #f6e7c8;
  font-size: 1.7rem;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(28, 79, 62, 0.35);
}
.login-kicker {
  margin: 0;
  text-align: center;
  color: #8a7452;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
}
.login-card h2 {
  margin: 0.35rem 0 0.4rem;
  text-align: center;
  font-size: 1.7rem;
  color: #17352d;
}
.login-lead {
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.8;
  margin: 0 0 1.3rem;
}
.field { display: block; margin: 0.7rem 0; }
.field span {
  display: block;
  margin-bottom: 0.35rem;
  color: #3e534c;
  font-size: 0.86rem;
  font-weight: 600;
}
.login-card input {
  width: 100%;
  border: 1px solid #e4d9c6;
  background: #fffdf8;
  border-radius: 14px;
  padding: 0.85rem 0.95rem;
  font-family: inherit;
  font-size: 1rem;
  text-align: right;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.login-card input:focus {
  border-color: #2c5f4e;
  box-shadow: 0 0 0 4px rgba(44, 95, 78, 0.12);
}
.login-card .error { margin: 0.6rem 0; }
.login-card button[type="submit"] {
  width: 100%;
  margin-top: 0.9rem;
  border-radius: 14px;
  padding: 0.95rem 1rem;
  background: linear-gradient(135deg, #2c5f4e, #1f4a3d);
  box-shadow: 0 12px 22px rgba(31, 74, 61, 0.28);
  font-size: 1rem;
}
.login-card button[type="submit"]:hover { filter: brightness(1.06); }
.linkish {
  width: 100%;
  margin-top: 0.7rem;
  background: transparent;
  color: #2c5f4e;
  font-weight: 600;
  box-shadow: none;
  padding: 0.4rem;
}
.ghost { background: var(--soft); color: var(--primary); }
.userbar { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.45rem; }
.userbar button { padding: 0.28rem 0.55rem; font-size: 0.75rem; background: var(--soft); color: var(--primary); }
.side #resetBtn { width: 100%; }

.live-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: nowrap;
  align-items: center;
  margin-bottom: 0.4rem;
  flex-shrink: 0;
}
.live-clock { font-size: 1.35rem; font-weight: 700; color: var(--primary); line-height: 1.1; }
.live-actions { display: flex; gap: 0.35rem; flex-wrap: nowrap; align-items: center; }
.live-actions select, .live-actions button { font-size: 0.75rem; padding: 0.35rem 0.5rem; }
.live-actions select {
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.twin-grid {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) minmax(0, 1.1fr);
  grid-template-rows: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 0.45rem;
  flex: 1;
  min-height: 0;
}
.twin-stage { grid-column: 1; grid-row: 1 / span 2; }
.twin-gauges { grid-column: 2; grid-row: 1; min-height: 0; overflow: hidden; }
.twin-event { grid-column: 3; grid-row: 1; min-height: 0; overflow: hidden; }
.twin-chart { grid-column: 2; grid-row: 2; min-height: 0; overflow: hidden; }
.twin-radar { grid-column: 3; grid-row: 2; min-height: 0; overflow: hidden; }
.cardish {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.5rem 0.65rem;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.cardish h3 { margin: 0 0 0.3rem; font-size: 0.82rem; flex-shrink: 0; }
.cardish canvas { flex: 1; min-height: 0; max-height: 100%; }
.twin-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  background: radial-gradient(circle at 50% 20%, #edf5f1, #f7f3ea 70%);
}
.twin-svg { width: min(140px, 78%); z-index: 1; transition: transform 0.6s ease; }
.twin-svg.is-tired { transform: translateY(8px) scale(0.98); }
.twin-svg.is-tense #twinBody { filter: saturate(0.8); }
.pulse-ring {
  position: absolute;
  width: 110px; height: 110px;
  border-radius: 50%;
  border: 2px solid rgba(44, 95, 78, 0.25);
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  from { transform: scale(0.8); opacity: 0.7; }
  to { transform: scale(1.25); opacity: 0; }
}
.hr-badge {
  margin-top: 0.25rem;
  background: #2c5f4e;
  color: #f6e7c8;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.75rem;
}
.gauges { display: grid; gap: 0.22rem; }
.gauge-row { display: grid; grid-template-columns: 78px 1fr 30px; gap: 0.35rem; align-items: center; }
.gauge-row span { font-size: 0.72rem; }
.bar {
  height: 7px;
  background: #efe7d8;
  border-radius: 99px;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2c5f4e, #c4a574);
  border-radius: 99px;
  transition: width 0.4s ease;
}
.live-event { line-height: 1.55; margin: 0 0 0.3rem; font-size: 0.82rem; }
.live-voice {
  margin: 0;
  color: #8a7452;
  font-style: italic;
  line-height: 1.5;
  font-size: 0.78rem;
}
.live-feed { flex: 1; min-height: 0; overflow: hidden; display: grid; gap: 0.28rem; }
.live-feed .item {
  background: #f7f3ea;
  border-radius: 8px;
  padding: 0.28rem 0.45rem;
  font-size: 0.72rem;
  line-height: 1.45;
}
.daily-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.15rem 0.8rem;
  flex-shrink: 0;
}
#daily textarea { min-height: 48px; max-height: 48px; }
#logList { flex: 1; }
#eval {
  overflow: hidden;
}
#eval #quickBox {
  flex: 0 1 auto;
  max-height: 28%;
  margin-top: 0.2rem;
  min-height: 0;
  overflow: auto;
}
#eval #deepBtn {
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 0.45rem;
}
#deepBox {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
#chart, #liveChart, #liveRadar { width: 100% !important; }

@media (max-width: 860px) {
  html, body, body.is-app, body.is-app #appShell { height: auto; overflow: auto; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .side { border-left: 0; border-bottom: 1px solid var(--line); }
  .twin-grid { grid-template-columns: 1fr; grid-template-rows: auto; }
  .twin-stage, .twin-gauges, .twin-event, .twin-chart, .twin-radar { grid-column: auto; grid-row: auto; }
}
