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

:root{
  --bg:#15171b;
  --bg-alt:#1b1e23;
  --card:#1b1e23;
  --line:#2a2d33;
  --text:#ece9e2;
  --text-dim:#93979f;
  --accent:#a855f7;
  --accent-alt:#ec4899;
  --radius:4px;
}
*{ box-sizing:border-box; margin:0; padding:0; }
body{
  background:var(--bg);
  color:var(--text);
  font-family:'IBM Plex Sans', sans-serif;
  font-size:15px;
  height:100vh;
  overflow:hidden;
}
.hidden{ display:none !important; }
.mono{ font-family:'IBM Plex Mono', monospace; }
.dim{ color:var(--text-dim); font-size:.82rem; }
h1,h2{ font-family:'Sora', sans-serif; font-weight:700; }
input, textarea{
  font-family:inherit;
  background:var(--bg);
  border:1px solid var(--line);
  color:var(--text);
  border-radius:var(--radius);
  padding:10px 12px;
  outline:none;
}
input:focus, textarea:focus{ border-color:var(--accent); }

.btn{
  font-family:'IBM Plex Mono', monospace;
  font-size:.85rem;
  padding:9px 16px;
  border:1px solid var(--accent);
  border-radius:var(--radius);
  color:var(--accent);
  background:transparent;
  cursor:pointer;
  transition:background .15s, color .15s;
}
.btn:hover{ background:var(--accent); color:#fff; }
.btn.solid{ background:var(--accent); border-color:transparent; color:#fff; }
.btn.solid:hover{ background:var(--accent-alt); }
.btn.small{ padding:6px 12px; font-size:.78rem; }
.btn.danger{ border-color:#e05252; color:#e05252; }
.btn.danger:hover{ background:#e05252; color:#fff; }

/* AUTH */
.auth-screen{
  height:100vh; display:flex; align-items:center; justify-content:center;
}
.auth-card{
  width:360px; padding:36px; border:1px solid var(--line); border-radius:var(--radius); background:var(--card);
}
.auth-card h1{ font-size:1.6rem; margin-bottom:26px; }
.auth-card h1 span{ color:var(--accent-alt); }
.auth-card .sub{ color:var(--text-dim); font-size:.88rem; margin-bottom:22px; }
.tabs{ display:flex; gap:8px; margin-bottom:18px; }
.tab-btn{
  flex:1; padding:8px; background:transparent; border:1px solid var(--line); color:var(--text-dim);
  cursor:pointer; border-radius:var(--radius); font-family:'IBM Plex Mono', monospace; font-size:.8rem;
}
.tab-btn.active{ border-color:var(--accent); color:var(--accent); }
.auth-form{ display:flex; flex-direction:column; gap:12px; }
.auth-form .btn{ margin-top:6px; }
.error{ color:#e05252; font-size:.8rem; min-height:1em; }

/* APP SHELL */
.app-screen{ height:100vh; display:flex; flex-direction:column; }
.app-header{
  display:flex; align-items:center; gap:30px; padding:12px 22px;
  border-bottom:1px solid var(--line); background:#000;
}
.brand{ font-family:'Sora',sans-serif; font-weight:700; }
.brand span{ color:var(--accent-alt); }
.app-nav{ display:flex; gap:6px; flex:1; }
.nav-btn{
  background:transparent; border:none; color:var(--text-dim); padding:8px 14px;
  cursor:pointer; font-family:'IBM Plex Mono', monospace; font-size:.85rem; border-radius:var(--radius);
}
.nav-btn.active{ color:var(--text); background:var(--bg-alt); }
.user-box{ display:flex; align-items:center; gap:10px; }
.user-box .mono{ font-size:.8rem; color:var(--text-dim); }

.app-main{ flex:1; overflow:hidden; }
.view{ display:flex; height:100%; }
#view-files{ display:block; padding:26px; overflow:auto; }

/* CHAT */
.sidebar{
  width:220px; border-right:1px solid var(--line); background:var(--bg-alt); padding:18px 14px; overflow:auto;
}
.sidebar-group{ margin-bottom:22px; }
.sidebar-title{
  font-family:'IBM Plex Mono', monospace; font-size:.72rem; text-transform:uppercase; letter-spacing:.04em;
  color:var(--text-dim); margin-bottom:8px;
}
.room-list{ list-style:none; }
.room-list li{
  padding:7px 10px; border-radius:var(--radius); cursor:pointer; font-size:.9rem; color:var(--text-dim);
  margin-bottom:2px;
}
.room-list li:hover{ background:var(--bg); color:var(--text); }
.room-list li.active{ background:var(--accent); color:#fff; }

.chat-panel{ flex:1; display:flex; flex-direction:column; }
.chat-head{ padding:16px 22px; border-bottom:1px solid var(--line); font-family:'Sora',sans-serif; font-weight:700; }
.chat-messages{ flex:1; overflow:auto; padding:18px 22px; display:flex; flex-direction:column; gap:14px; }
.msg{
  max-width:65%;
  align-self:flex-start;
  display:flex;
  flex-direction:column;
}
.msg.own{ align-self:flex-end; align-items:flex-end; }
.msg .meta{
  font-family:'IBM Plex Mono', monospace;
  font-size:.7rem;
  color:var(--text-dim);
  margin-bottom:4px;
  padding:0 4px;
}
.msg .bubble{
  background:var(--bg-alt);
  border:1px solid var(--line);
  padding:10px 14px;
  border-radius:16px;
  border-bottom-left-radius:4px;
  font-size:.94rem;
  line-height:1.45;
  word-wrap:break-word;
  box-shadow:0 1px 3px rgba(0,0,0,.15);
}
.msg.own .bubble{
  background:linear-gradient(135deg, var(--accent), var(--accent-alt));
  border:none;
  color:#fff;
  border-radius:16px;
  border-bottom-right-radius:4px;
}
.chat-input{ display:flex; gap:10px; padding:16px 22px; border-top:1px solid var(--line); }
.chat-input input{ flex:1; }

/* FILES */
.panel-head{ display:flex; justify-content:space-between; align-items:center; margin-bottom:20px; }
.panel-head h2{ font-size:1.3rem; }
#upload-form{ display:flex; gap:10px; align-items:center; }
.data-table{ width:100%; border-collapse:collapse; }
.data-table th{
  text-align:left; font-family:'IBM Plex Mono', monospace; font-size:.72rem; text-transform:uppercase;
  color:var(--text-dim); padding:10px 8px; border-bottom:1px solid var(--line);
}
.data-table td{ padding:10px 8px; border-bottom:1px solid var(--line); font-size:.88rem; }

/* DOCS */
.doc-panel{ flex:1; display:flex; flex-direction:column; padding:20px 26px; }
.doc-title-input{ font-size:1.3rem; font-family:'Sora',sans-serif; border:none; background:transparent; padding:6px 0; margin-bottom:10px; }
.doc-textarea{ flex:1; resize:none; line-height:1.6; }
.doc-actions{ display:flex; gap:12px; align-items:center; margin-top:12px; }

/* ---------- MOBILE TOGGLE (hidden on desktop) ---------- */
.rooms-toggle-btn{
  display:none;
  background:transparent;
  border:1px solid var(--line);
  color:var(--text);
  font-size:1.1rem;
  line-height:1;
  padding:8px 11px;
  border-radius:var(--radius);
  cursor:pointer;
  flex-shrink:0;
}
.chat-head{ display:flex; align-items:center; gap:12px; }
.doc-panel-head{ display:none; }

.sidebar-overlay{ display:none; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 760px){

  /* Header: wrap nav onto its own row, keep it thumb-friendly */
  .app-header{
    flex-wrap:wrap;
    row-gap:10px;
    padding:12px 14px;
  }
  .brand{ font-size:1rem; }
  .app-nav{
    order:3;
    flex-basis:100%;
    width:100%;
    justify-content:space-between;
    gap:4px;
  }
  .nav-btn{
    flex:1;
    text-align:center;
    padding:10px 8px;
    font-size:.8rem;
  }
  .user-box{ gap:8px; }
  .user-box .mono{
    max-width:90px;
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
  }
  .btn.small{ padding:8px 12px; }

  /* 100vh doesn't account for mobile browser chrome/keyboard; 100dvh does */
  body{ height:100vh; height:100dvh; }
  .app-screen, .auth-screen{ height:100vh; height:100dvh; }

  /* Sidebar becomes a slide-out drawer instead of a fixed column */
  .view{ position:relative; overflow-x:hidden; min-height:0; }

  .sidebar{
    position:fixed;
    top:0;
    left:0;
    bottom:0;
    width:80%;
    max-width:300px;
    z-index:40;
    transform:translateX(-100%);
    transition:transform .22s ease;
    box-shadow:6px 0 24px rgba(0,0,0,.5);
    padding-top:70px; /* clear the sticky header */
  }
  .sidebar.open{ transform:translateX(0); }

  .sidebar-overlay{
    display:block;
    position:fixed;
    inset:0;
    top:0;
    background:rgba(0,0,0,.55);
    z-index:35;
    opacity:0;
    visibility:hidden;
    pointer-events:none;
    transition:opacity .22s ease, visibility 0s linear .22s;
  }
  .sidebar-overlay.open{
    opacity:1;
    visibility:visible;
    pointer-events:auto;
    transition:opacity .22s ease, visibility 0s linear 0s;
  }

  .rooms-toggle-btn{ display:inline-flex; align-items:center; justify-content:center; }

  .chat-panel, .doc-panel{ width:100%; min-height:0; }

  .chat-head{ flex-shrink:0; }
  .chat-messages{ padding:14px; min-height:0; }
  .msg{ max-width:88%; }
  .chat-input{ padding:10px 12px; gap:8px; flex-shrink:0; }
  /* 16px min font-size on inputs stops iOS Safari auto-zooming on focus */
  .chat-input input, input, textarea{ font-size:16px; }

  /* Files: let the table scroll horizontally instead of squashing */
  #view-files{ padding:16px; }
  .panel-head{
    flex-direction:column;
    align-items:stretch;
    gap:14px;
  }
  #upload-form{
    flex-wrap:wrap;
  }
  #upload-form input[type=file]{
    flex:1 1 100%;
    min-width:0;
  }
  .data-table{
    display:block;
    overflow-x:auto;
    white-space:nowrap;
    -webkit-overflow-scrolling:touch;
  }

  /* Docs: show the drawer toggle above the title */
  .doc-panel{ padding:14px 16px; }
  .doc-panel-head{
    display:flex;
    margin-bottom:10px;
  }
  .doc-title-input{ font-size:1.1rem; }
  .doc-actions{ flex-wrap:wrap; }
}
