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

:root{
  --bg:#050814;
  --bg-2:#090f1f;
  --surface:#0d162d;
  --surface-2:#111d38;
  --stroke:rgba(148,163,184,.26);
  --stroke-soft:rgba(148,163,184,.16);
  --text:#dbe5f3;
  --text-soft:#9aadc8;
  --brand:#1d9bf0;
  --brand-2:#0ea5e9;
  --ok:#22c55e;
  --warning:#f59e0b;
  --danger:#ef4444;
  --bubble-in:#101a31;
  --bubble-out:linear-gradient(135deg,#0e7490 0%,#1d4ed8 100%);
  --radius:16px;
  --shadow:0 12px 40px rgba(1,6,20,.5);
  --font-ui:'IBM Plex Sans',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  --font-display:'Space Grotesk',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
}

html{font-size:16px;-webkit-text-size-adjust:100%}
body{
  font-family:var(--font-ui);
  color:var(--text);
  min-height:100dvh;
  background:radial-gradient(120% 80% at 50% -10%,#152848 0%,var(--bg) 62%);
  overflow:hidden;
}
.hidden{display:none!important}
.screen{height:100dvh;display:flex;position:relative}

#screen-auth{
  justify-content:center;
  align-items:center;
  padding:20px;
  overflow:hidden;
}
.auth-glow{position:absolute;border-radius:999px;filter:blur(52px);opacity:.35;pointer-events:none}
.auth-glow-a{width:260px;height:260px;background:#0ea5e9;top:-90px;left:-100px}
.auth-glow-b{width:280px;height:280px;background:#1d4ed8;right:-120px;bottom:-120px}
.auth-card{
  width:min(440px,100%);
  background:rgba(13,22,45,.86);
  border:1px solid var(--stroke);
  border-radius:24px;
  padding:24px;
  box-shadow:var(--shadow);
  backdrop-filter:blur(14px);
  z-index:2;
}
.auth-logo{display:flex;flex-direction:column;align-items:center;gap:8px;text-align:center;margin-bottom:18px}
.auth-tag{font-size:.72rem;letter-spacing:.12em;text-transform:uppercase;color:#67e8f9}
.auth-logo h1{font-family:var(--font-display);font-size:1.36rem;line-height:1.18}
.auth-form{display:flex;flex-direction:column;gap:12px}
.auth-form h2{font-family:var(--font-display);font-size:1.14rem}
.auth-subtitle,.info-text{font-size:.86rem;color:var(--text-soft);line-height:1.45}
.field{display:flex;flex-direction:column;gap:6px}
.field label{font-size:.82rem;font-weight:600;color:#c8d8ee}
.field input{
  border:1px solid var(--stroke);
  border-radius:12px;
  background:#0a1328;
  color:var(--text);
  padding:12px 14px;
  outline:none;
}
.field input:focus{border-color:#38bdf8;box-shadow:0 0 0 3px rgba(56,189,248,.2)}
.form-error{color:#fda4af;font-size:.82rem;min-height:1.1em}
.qr-container{display:flex;justify-content:center}

.btn-primary,.btn-secondary,.ghost-btn,.action-btn,.side-action,.side-nav-item{
  border:none;
  border-radius:11px;
  font-weight:600;
  cursor:pointer;
  transition:background .2s,opacity .15s,transform .15s,border-color .2s;
}
.btn-primary:active,.btn-secondary:active,.ghost-btn:active,.action-btn:active,.side-action:active,.side-nav-item:active{transform:translateY(1px)}
.btn-primary{
  background:linear-gradient(135deg,#0ea5e9 0%,#1d4ed8 100%);
  color:#fff;
  padding:11px 14px;
}
.btn-primary:disabled{opacity:.6;cursor:not-allowed}
.btn-secondary{
  background:#0d1831;
  border:1px solid var(--stroke);
  color:var(--text);
  padding:10px 12px;
}
.btn-link-inline{border:none;background:none;color:#67e8f9;text-decoration:underline;font-weight:600;cursor:pointer}
.block-btn{display:block;text-align:center;text-decoration:none}

#screen-app{background:linear-gradient(180deg,#070c19 0%,#050915 100%);overflow:hidden}
.workspace{display:flex;flex-direction:column;width:100%;height:100%;position:relative}

.side-overlay{
  position:fixed;
  inset:0;
  background:rgba(2,6,23,.55);
  z-index:50;
}
.side-panel{
  position:fixed;
  left:0;
  top:0;
  bottom:0;
  width:min(84vw,320px);
  background:#0a1225;
  border-right:1px solid var(--stroke);
  z-index:60;
  padding:14px 12px;
  display:flex;
  flex-direction:column;
  gap:14px;
  box-shadow:var(--shadow);
}
.side-head{display:flex;align-items:center;gap:10px;padding:2px 4px 8px;border-bottom:1px solid var(--stroke-soft)}
.side-kicker{font-size:.72rem;color:#67e8f9;letter-spacing:.1em;text-transform:uppercase}
.side-head h2{font-family:var(--font-display);font-size:1.02rem}
.side-nav{display:flex;flex-direction:column;gap:8px}
.side-nav-item{
  text-align:left;
  padding:10px 12px;
  background:#0f1a33;
  border:1px solid var(--stroke-soft);
  color:#c8d8ee;
}
.side-nav-item.active{background:#122449;border-color:#38bdf8;color:#e0f2fe}
.side-section{display:flex;flex-direction:column;gap:8px;margin-top:auto}
.side-action{
  text-align:left;
  padding:10px 12px;
  background:#0f1a33;
  border:1px solid var(--stroke-soft);
  color:var(--text);
}
.side-action.danger{color:#fecaca;border-color:rgba(239,68,68,.35)}

.app-header{
  position:sticky;
  top:0;
  z-index:10;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:10px 12px;
  border-bottom:1px solid var(--stroke-soft);
  background:rgba(7,13,28,.88);
  backdrop-filter:blur(14px);
}
.header-left{display:flex;align-items:center;gap:9px;min-width:0}
.header-avatar{border-radius:50%;border:1px solid var(--stroke-soft)}
.header-title{font-family:var(--font-display);font-size:.96rem}
.header-status{font-size:.72rem;color:var(--text-soft)}
.header-status.online{color:var(--ok)}
.ghost-btn{padding:8px 10px;font-size:.78rem;background:#0f1a34;border:1px solid var(--stroke-soft);color:#d3e2f7}

.link-banner{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:10px 12px;
  font-size:.82rem;
  color:#fde68a;
  border-bottom:1px solid rgba(245,158,11,.28);
  background:rgba(245,158,11,.1);
}

.view{display:flex;flex-direction:column;flex:1;min-height:0}
.active-view{display:flex}

.chat-messages{
  flex:1;
  min-height:0;
  overflow-y:auto;
  padding:12px;
  display:flex;
  flex-direction:column;
  gap:8px;
  scroll-behavior:smooth;
  -webkit-overflow-scrolling:touch;
}
.loading-placeholder{text-align:center;color:var(--text-soft);font-size:.85rem;margin-top:12px}
.history-loader{align-self:center;font-size:.78rem;color:#7dd3fc;background:#0f1f3c;border:1px solid var(--stroke-soft);padding:5px 8px;border-radius:999px}

.msg-row{display:flex;flex-direction:column;max-width:90%;animation:rise .2s ease}
.msg-row.outbound{align-self:flex-end;align-items:flex-end}
.msg-row.inbound{align-self:flex-start;align-items:flex-start}

.bubble{
  padding:10px 12px;
  border-radius:14px;
  border:1px solid var(--stroke-soft);
  line-height:1.42;
  font-size:.93rem;
  box-shadow:0 8px 20px rgba(2,8,24,.32);
  word-break:break-word;
}
.inbound .bubble{background:var(--bubble-in);color:#dce7f8}
.outbound .bubble{background:var(--bubble-out);color:#fff;border-color:transparent}
.msg-time{font-size:.67rem;color:var(--text-soft);padding:2px 4px 0}
.msg-status{font-size:.66rem;padding:2px 4px 0;color:#9fb4d6}
.msg-row.pending .msg-status{color:#facc15}
.msg-row.error .msg-status{color:#fca5a5}
.share-btn{margin-top:4px;font-size:.68rem;padding:4px 8px;border-radius:999px;border:1px solid var(--stroke-soft);background:#0f1f3c;color:#cfe0f8;cursor:pointer}
.retry-btn{margin-top:4px;font-size:.68rem;padding:4px 8px;border-radius:999px;border:1px solid rgba(239,68,68,.4);background:#2b1520;color:#fecdd3;cursor:pointer}

.audio-bubble{display:flex;align-items:center;gap:8px;min-width:170px}
.audio-play-btn{width:34px;height:34px;border:none;border-radius:999px;cursor:pointer;background:#0f1a33;color:#dbeafe;font-size:.74rem}
.outbound .audio-play-btn{background:rgba(15,23,42,.45)}
.audio-waveform{flex:1;height:10px;border-radius:999px;background:rgba(148,163,184,.28)}
.audio-duration{font-size:.74rem;opacity:.86}
audio.hidden-player{display:none}

.doc-bubble{display:flex;gap:8px;color:inherit;text-decoration:none;align-items:center}
.doc-icon{font-size:1.2rem;font-weight:700;color:#7dd3fc}
.doc-info{display:flex;flex-direction:column;gap:1px}
.doc-name{font-weight:600;font-size:.84rem;max-width:170px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.doc-size{font-size:.72rem;opacity:.8}
.img-bubble img{max-width:220px;max-height:220px;border-radius:11px;display:block;object-fit:cover;cursor:pointer}

.date-separator{display:flex;align-items:center;gap:8px;color:var(--text-soft);font-size:.73rem;margin:8px 0}
.date-separator:before,.date-separator:after{content:'';height:1px;flex:1;background:var(--stroke-soft)}

.chat-input-area{
  border-top:1px solid var(--stroke-soft);
  background:rgba(7,13,28,.9);
  backdrop-filter:blur(14px);
  padding:10px;
  padding-bottom:max(10px,env(safe-area-inset-bottom));
}
.input-row{display:flex;align-items:center;gap:8px}
#text-input{flex:1;min-width:0;background:#0a142b;border:1px solid var(--stroke);border-radius:999px;color:var(--text);padding:11px 14px;outline:none}
#text-input:focus{border-color:#38bdf8}
.action-btn{background:#0f1a34;border:1px solid var(--stroke-soft);padding:10px 11px;font-size:.78rem;color:#cfe0f8}
.send-btn{color:#7dd3fc}
.record-btn{color:#d8b4fe}

.recording-ui{display:flex;align-items:center;gap:8px;padding:4px 0}
.recording-indicator{display:flex;align-items:center;gap:8px;flex:1;font-size:.9rem}
.rec-dot{width:10px;height:10px;border-radius:50%;background:var(--danger);animation:pulse 1s infinite}
.rec-label{color:var(--text-soft)}

#view-ops{padding:12px;gap:10px;overflow:auto}
.panel-head{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:12px 12px 4px}
.panel-head{flex-wrap:wrap}
.panel-title-row{display:flex;align-items:center;justify-content:space-between;gap:8px;width:100%}
.panel-head h3{font-family:var(--font-display);font-size:1rem}
.panel-head-files{padding-bottom:8px}
.files-top-row .files-tabs{margin-left:auto}
.search-box{display:flex;align-items:center;gap:6px;background:#0f1a34;border:1px solid var(--stroke-soft);border-radius:12px;padding:7px 10px;min-width:150px}
.search-box-block{width:100%}
.search-icon{font-size:.8rem;opacity:.85}
.search-box input{background:transparent;border:none;outline:none;color:var(--text);font-size:.8rem;min-width:0;width:100%}
.files-tabs{display:flex;gap:6px}
.files-tabs .ghost-btn.active{border-color:#38bdf8;color:#e0f2fe;background:#122449}
.files-list{display:flex;flex-direction:column;gap:8px;padding:8px 12px 12px;overflow:auto;min-height:0;flex:1}
.file-row{display:flex;gap:10px;align-items:center;text-decoration:none;color:inherit;border:1px solid var(--stroke-soft);border-radius:12px;background:var(--surface);padding:10px}
.file-icon{width:44px;height:44px;display:flex;align-items:center;justify-content:center;border-radius:10px;background:#0b1832;color:#7dd3fc;font-weight:700;font-size:.74rem;flex-shrink:0}
.file-meta{min-width:0}
.file-name{font-size:.88rem;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.file-sub{font-size:.73rem;color:var(--text-soft);margin-top:2px}
.file-actions{margin-left:auto;display:flex;align-items:center}
.files-footer{padding:0 12px 12px}
.ops-head{display:flex;align-items:center;justify-content:space-between;gap:8px}
.ops-head h3{font-family:var(--font-display);font-size:1rem}
.ops-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.ops-card{border:1px solid var(--stroke-soft);border-radius:14px;background:var(--surface);padding:10px}
.ops-label{font-size:.74rem;color:var(--text-soft)}
.ops-value{font-size:1.05rem;font-weight:700;margin-top:4px}
.ops-foot{display:flex;flex-direction:column;gap:4px;border:1px solid var(--stroke-soft);background:var(--surface-2);border-radius:14px;padding:10px}
.ops-meta{font-size:.78rem;color:#c5d5ec}

.settings-panel{position:fixed;inset:0;z-index:100;background:rgba(2,6,23,.58);display:flex;align-items:flex-end}
.settings-content{width:100%;background:var(--surface);border:1px solid var(--stroke);border-radius:20px 20px 0 0;padding:16px;display:flex;flex-direction:column;gap:10px;max-height:74dvh;overflow:auto}
.settings-content h3{font-family:var(--font-display);font-size:1.06rem}
.settings-push{display:flex;flex-direction:column;gap:10px}
.settings-push h4{font-family:var(--font-display);font-size:.94rem}
.switch-row{display:flex;justify-content:space-between;align-items:center;gap:8px;font-size:.85rem}
.switch-row input{width:18px;height:18px}
.quiet-grid{display:grid;grid-template-columns:auto 1fr;gap:8px;align-items:center}
.quiet-grid input{background:#0a1328;border:1px solid var(--stroke);border-radius:10px;color:var(--text);padding:8px}
.settings-content hr{border:none;height:1px;background:var(--stroke-soft)}
.link-code-display{background:#0b1832;border:1px solid var(--stroke-soft);border-radius:12px;padding:10px;font-size:.84rem;line-height:1.5}
.link-code-display code{font-family:ui-monospace,Menlo,Consolas,monospace;color:#7dd3fc;font-weight:700}

.install-banner{
  position:fixed;
  left:10px;
  right:10px;
  bottom:max(10px,env(safe-area-inset-bottom));
  z-index:140;
  border:1px solid var(--stroke-soft);
  border-radius:12px;
  background:rgba(12,22,44,.96);
  color:var(--text);
  display:flex;
  align-items:center;
  gap:8px;
  padding:10px;
  font-size:.81rem;
}
.btn-icon-close{border:none;background:none;color:var(--text-soft);cursor:pointer;padding:4px}
#toast-msg{box-shadow:var(--shadow)}

.context-backdrop{
  position:fixed;
  inset:0;
  background:transparent;
  z-index:179;
}
.context-menu{
  position:fixed;
  min-width:180px;
  border:1px solid var(--stroke);
  border-radius:12px;
  background:#0f1a33;
  box-shadow:var(--shadow);
  padding:6px;
  z-index:180;
}
.context-item{
  width:100%;
  text-align:left;
  border:none;
  border-radius:8px;
  padding:9px 10px;
  background:transparent;
  color:var(--text);
  cursor:pointer;
}
.context-item:hover{background:#15284f}
.context-item.danger{color:#fecaca}
.context-item.danger:hover{background:#3b1620}

@keyframes pulse{0%,100%{opacity:1}50%{opacity:.35}}
@keyframes rise{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}

@media (min-width:980px){
  body{display:flex;justify-content:center;padding:18px}
  .screen{width:min(1180px,100%);height:calc(100dvh - 36px);border:1px solid var(--stroke-soft);border-radius:20px;overflow:hidden;box-shadow:var(--shadow)}
  #screen-auth{height:calc(100dvh - 36px)}
  #screen-app{display:grid;grid-template-columns:280px 1fr}
  .side-overlay{display:none!important}
  .side-panel{position:relative;width:auto;box-shadow:none;display:flex!important;z-index:1}
  .app-header{padding:10px 16px}
  .chat-messages{padding:14px 16px}
  .chat-input-area{padding:10px 16px}
  #view-ops{padding:14px 16px}
  .ghost-btn{font-size:.74rem}
}

@media (max-width:979px){
  .panel-head{gap:10px}
  .files-tabs{flex-shrink:0}
  .files-tabs .ghost-btn{padding:7px 9px}
}

#screen-admin{overflow:auto;padding:1rem}
.admin-section{margin-bottom:2rem}
.admin-section h2{font-size:1rem;margin-bottom:.75rem;color:#7dd3fc}
table{width:100%;border-collapse:collapse;font-size:.85rem}
th,td{padding:.5rem .75rem;border-bottom:1px solid var(--stroke-soft);text-align:left}
th{font-weight:600;background:#0b162e}
.badge{display:inline-block;padding:.15rem .4rem;border-radius:999px;font-size:.72rem;font-weight:600}
.badge-admin{background:#312e81;color:#c7d2fe}
.badge-active{background:#14532d;color:#bbf7d0}
.badge-inactive{background:#7f1d1d;color:#fecaca}
