/* ============================================================
   Employee Connect — Design tokens
   Theme: dark "ops" workspace. Signal-teal = online/live state,
   amber = attention/notifications. Monospace used for status
   chips & timestamps to give it a control-room feel.
   ============================================================ */
:root {
  --bg: #11141a;
  --panel: #171b22;
  --panel-2: #1d222b;
  --border: #262c38;
  --text: #e7e9ee;
  --text-muted: #8b93a1;
  --accent: #3ddc97;          /* online / live / success */
  --accent-dim: #1f6e51;
  --amber: #e8a33d;            /* notifications / attention */
  --danger: #e8554d;
  --radius: 10px;
  --font-ui: -apple-system, "Segoe UI", "Inter", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", "Consolas", "Menlo", monospace;
}

/* Light theme - toggled via [data-theme="light"] on <html>, applied by theme.js
   before paint (reads localStorage) so there's no flash of the wrong theme. */
:root[data-theme="light"] {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #eef0f3;
  --border: #dde1e7;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --accent: #1ba673;
  --accent-dim: #d7f5e9;
  --amber: #b4790f;
  --danger: #c8362d;
}
:root[data-theme="light"] .msg.mine { color: #07140f; }
:root[data-theme="light"] button.primary { color: #ffffff; }
:root[data-theme="light"] .unread-badge { color: #ffffff; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
button {
  font-family: var(--font-ui);
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.08s ease, background 0.15s ease;
}
button:active { transform: scale(0.97); }
button.primary { background: var(--accent); color: #07140f; }
button.primary:hover { background: #4eeab0; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.ghost:hover { background: var(--panel-2); }
button.danger { background: var(--danger); color: #1a0504; }
input, select, textarea {
  font-family: var(--font-ui);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-dim); }

/* ---------- Auth screen ---------- */
.auth-wrap {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, #14241d 0%, var(--bg) 55%);
}
.auth-card {
  width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.auth-card h1 {
  font-size: 19px;
  margin: 0 0 4px;
  letter-spacing: 0.2px;
}
.auth-card .sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}
.auth-card .field { margin-bottom: 12px; }
.auth-card .field label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.auth-tabs button { flex: 1; background: var(--panel-2); color: var(--text-muted); }
.auth-tabs button.active { background: var(--accent); color: #07140f; }
.auth-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
  min-height: 16px;
}
.auth-msg {
  color: var(--accent);
  font-size: 13px;
  margin-top: 10px;
  min-height: 16px;
}
.auth-link { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 14px; }
.auth-link a { font-weight: 600; }

/* ---------- Dashboard shell ---------- */
.shell { display: grid; grid-template-columns: 280px 1fr; grid-template-rows: 100vh; height: 100vh; }
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.me-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.me-name { font-weight: 600; font-size: 14px; }
.me-role { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }
.sidebar-tabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.sidebar-tabs button {
  flex: 1; min-width: 64px; background: transparent; color: var(--text-muted); border-radius: 0;
  font-size: 11px; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.04em;
  padding: 9px 4px;
}
.sidebar-tabs button.active { color: var(--accent); border-bottom: 2px solid var(--accent); }
.tab-badge {
  position: absolute; top: 3px; right: 6px; background: var(--danger); color: #fff;
  font-family: var(--font-mono); font-size: 10px; font-weight: 700; min-width: 16px; height: 16px;
  border-radius: 9px; align-items: center; justify-content: center; padding: 0 4px;
}
.contact-list { flex: 1; min-height: 0; overflow-y: auto; }
.contact {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; cursor: pointer; border-bottom: 1px solid #1a1f28;
}
.contact:hover { background: var(--panel-2); }
.contact.active { background: var(--panel-2); border-left: 3px solid var(--accent); }
.contact .avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--panel-2);
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700;
  border: 1px solid var(--border); position: relative;
}
.contact .dot {
  width: 9px; height: 9px; border-radius: 50%; position: absolute; bottom: -1px; right: -1px;
  border: 2px solid var(--panel); background: var(--text-muted);
}
.contact .dot.online { background: var(--accent); }
.contact .info { flex: 1; min-width: 0; }
.contact .info .name { font-size: 13px; font-weight: 600; }
.contact .info .status { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }
.unread-badge {
  background: var(--accent); color: #07140f; font-family: var(--font-mono);
  font-size: 11px; font-weight: 700; min-width: 20px; height: 20px;
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  padding: 0 6px;
}

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.sidebar-footer button { width: 100%; }

/* ---------- Chat panel ---------- */
.main { display: flex; flex-direction: column; height: 100vh; min-height: 0; overflow: hidden; }
#view-chat, #chat-active, #view-directory, #view-admin { min-height: 0; }
.chat-header {
  height: 60px; border-bottom: 1px solid var(--border); display: flex; align-items: center;
  justify-content: space-between; padding: 0 18px; background: var(--panel);
}
.chat-header .who { display: flex; align-items: center; gap: 10px; }
.chat-header .actions { display: flex; gap: 8px; }
.chat-header .actions button { padding: 8px 12px; font-size: 13px; }

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 60%; padding: 10px 13px; border-radius: var(--radius); font-size: 14px; line-height: 1.4; }
.msg.mine { align-self: flex-end; background: var(--accent-dim); color: #eafff4; }
.msg.theirs { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--border); }
.msg .meta { font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); margin-top: 4px; }
.msg img, .msg video { max-width: 280px; border-radius: 8px; display: block; margin-top: 6px; }
.msg .file-chip { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,0.2); padding: 8px 10px; border-radius: 8px; margin-top: 4px; }

.composer { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; gap: 10px; background: var(--panel); }
.composer textarea { resize: none; height: 44px; }
.composer button { padding: 0 18px; }

.empty-state { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-muted); flex-direction: column; gap: 8px; }
.empty-state .big { font-size: 15px; }

/* ---------- Notifications (corner popups) ---------- */
#toast-stack {
  position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 9999;
}
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 12px 14px; width: 300px; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: slideIn 0.25s ease;
}
.toast.amber { border-left-color: var(--amber); }
.toast .t-title { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.toast .t-body { font-size: 12px; color: var(--text-muted); }
@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---------- Call overlay ---------- */
#call-overlay {
  position: fixed; inset: 0; background: rgba(8,10,14,0.92); display: none;
  align-items: center; justify-content: center; flex-direction: column; z-index: 9998; gap: 16px;
}
#call-overlay video { background: #000; border-radius: 12px; }
#call-overlay.active { display: flex; }
.call-controls { display: flex; gap: 12px; }
.call-controls button { padding: 10px 18px; font-size: 14px; border-radius: 8px; }
.incoming-call {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; text-align: center; width: 320px;
}
.incoming-call .who { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.incoming-call .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 18px; }
.incoming-call .row { display: flex; gap: 10px; }
.incoming-call .row button { flex: 1; }

/* ---------- Admin panel ---------- */
.admin-grid { padding: 18px; overflow-y: auto; flex: 1; min-height: 0; }
.admin-section { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.admin-section h3 { margin: 0 0 12px; font-size: 14px; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; }
.badge { font-family: var(--font-mono); font-size: 11px; padding: 2px 8px; border-radius: 20px; }
.badge.pending { background: rgba(232,163,61,0.15); color: var(--amber); }
.badge.approved { background: rgba(61,220,151,0.15); color: var(--accent); }
.badge.rejected { background: rgba(232,85,77,0.15); color: var(--danger); }
.row-actions { display: flex; gap: 6px; }
.row-actions button { padding: 5px 10px; font-size: 12px; }
.admin-form-row { display: flex; gap: 10px; margin-bottom: 10px; }
.scroll-x { overflow-x: auto; }

/* ---------- Directory (company address book) ---------- */
.directory-grid {
  flex: 1; overflow-y: auto; padding: 18px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px;
  align-content: start;
}
.directory-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.directory-card .top { display: flex; align-items: center; gap: 10px; }
.directory-card .avatar {
  width: 42px; height: 42px; border-radius: 50%; background: var(--panel-2);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
  border: 1px solid var(--border); position: relative; flex-shrink: 0;
}
.directory-card .avatar .dot {
  width: 10px; height: 10px; border-radius: 50%; position: absolute; bottom: -2px; right: -2px;
  border: 2px solid var(--panel); background: var(--text-muted);
}
.directory-card .avatar .dot.online { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.directory-card .name { font-size: 14px; font-weight: 700; }
.directory-card .dept { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }
.directory-card .presence { font-size: 12px; }
.directory-card .presence.online { color: var(--accent); }
.directory-card .presence.offline { color: var(--text-muted); }
.directory-card .row-actions { display: flex; gap: 6px; margin-top: 4px; }
.directory-card .row-actions button { flex: 1; padding: 7px 6px; font-size: 12px; }

/* ---------- Announcements inbox ---------- */
.announcement-card {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--amber);
  border-radius: var(--radius); padding: 14px 16px;
}
.announcement-card .a-title { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.announcement-card .a-body { font-size: 13px; color: var(--text); margin-bottom: 8px; }
.announcement-card .a-meta { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }

/* ---------- Modal (notification settings) ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: none;
  align-items: center; justify-content: center; z-index: 10000;
}
.modal-overlay.active { display: flex; }
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; width: 360px;
}
.modal-section { margin: 14px 0; }
.modal-section-title {
  font-family: var(--font-mono); font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px;
}
.modal-checkbox { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; margin-bottom: 8px; cursor: pointer; }
.modal-checkbox input { width: auto; margin-top: 2px; }

/* ---------- Multi-party call ---------- */
.call-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px;
  width: 100%; max-width: 1000px; flex: 1; align-content: center;
}
.call-tile {
  background: #000; border-radius: 12px; position: relative; aspect-ratio: 4/3;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  border: 1px solid var(--border);
}
.call-tile video { width: 100%; height: 100%; object-fit: cover; }
.call-tile-name {
  position: absolute; bottom: 6px; left: 8px; color: #fff; font-size: 12px;
  background: rgba(0,0,0,0.5); padding: 2px 8px; border-radius: 6px;
}
.call-local-pip {
  position: fixed; bottom: 90px; right: 24px; width: 150px; height: 112px;
  border-radius: 10px; border: 2px solid var(--accent); object-fit: cover; background: #000; z-index: 10001;
}
.call-picker-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid #1a1f28; font-size: 13px;
}
.call-picker-item input { width: auto; }
.call-picker-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.call-picker-item .dot.online { background: var(--accent); }

/* ---------- Group-call banner inside call-actions ---------- */
.live-call-banner {
  display: flex; align-items: center; gap: 10px; background: rgba(232,85,77,0.12);
  border: 1px solid var(--danger); border-radius: 8px; padding: 6px 12px; font-size: 13px;
}
.live-call-banner .pulse-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--danger);
  animation: pulseDot 1.4s infinite;
}
@keyframes pulseDot { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ---------- Message selection / delete ---------- */
.msg { position: relative; }
.msg .msg-select-box { position: absolute; top: -6px; left: -28px; width: 18px; height: 18px; }
.msg.theirs .msg-select-box { left: -28px; }
.msg.mine .msg-select-box { left: auto; right: -28px; }
.msg .msg-delete-btn {
  position: absolute; top: -8px; right: -8px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 50%; width: 20px; height: 20px; font-size: 11px; display: none; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-muted);
}
.msg.mine .msg-delete-btn { right: auto; left: -8px; }
.msg:hover .msg-delete-btn { display: flex; }
.msg-unsend-link {
  display: none; font-size: 10px; color: var(--text-muted); text-decoration: underline;
  cursor: pointer; margin-left: 8px;
}
.msg:hover .msg-unsend-link { display: inline; }
.messages.select-mode .msg { margin-left: 30px; }
.messages.select-mode .msg.mine { margin-right: 30px; margin-left: 0; }

/* ==============================================
   MOBILE RESPONSIVE - Complete Fix
   ============================================== */

/* Hide back button on desktop */
.mobile-back-btn { display: none; }

@media (max-width: 768px) {
  /* Fix body */
  html, body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    height: 100dvh;
  }

  /* Shell becomes single column */
  .shell {
    display: block;
    position: relative;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  /* Sidebar fills full screen */
  .sidebar {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    transform: translateX(0);
    transition: transform 0.28s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* Contact list scrollable */
  .contact-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
  }

  /* Sidebar footer always visible at bottom */
  .sidebar-footer {
    flex-shrink: 0;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    background: var(--panel);
  }
  .sidebar-footer button {
    width: 100%;
    margin-bottom: 6px;
    font-size: 13px;
  }

  /* Main panel hidden off right */
  .main {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    transform: translateX(100%);
    transition: transform 0.28s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
  }

  /* When chat opens - sidebar left, main shows */
  .shell.mobile-chat-open .sidebar { transform: translateX(-100%); }
  .shell.mobile-chat-open .main    { transform: translateX(0); }

  /* Back button shows on mobile */
  .mobile-back-btn {
    display: inline-flex;
    align-items: center;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 22px;
    cursor: pointer;
    padding: 0 8px 0 0;
    flex-shrink: 0;
    line-height: 1;
  }

  /* Chat header */
  .chat-header {
    flex-shrink: 0;
    min-height: 52px;
    height: auto;
    padding: 6px 10px;
  }
  .chat-header .who {
    flex: 1;
    min-width: 0;
    overflow: hidden;
  }
  .chat-header .actions {
    flex-shrink: 0;
    gap: 2px;
  }
  .chat-header .actions button {
    padding: 4px 6px;
    font-size: 10px;
  }

  /* Chat view fills remaining height */
  #view-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }
  #chat-active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  /* Messages scrollable */
  .messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px 12px;
  }

  /* Composer always at bottom */
  .composer {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: var(--panel);
    border-top: 1px solid var(--border);
    min-height: 52px;
  }
  .composer textarea {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    min-height: 36px;
    max-height: 80px;
    padding: 8px 10px;
    resize: none;
  }
  #btn-attach {
    flex-shrink: 0;
    padding: 0 8px;
    font-size: 18px;
  }
  #btn-send {
    flex-shrink: 0;
    padding: 0 14px;
    height: 38px;
  }

  /* Tabs */
  .sidebar-tabs button {
    padding: 10px 2px;
    font-size: 10px;
    min-height: 44px;
  }

  /* Messages width */
  .msg { max-width: 86%; }
  .msg img, .msg video { max-width: calc(100vw - 60px); }

  /* Modals */
  .modal-card {
    width: 95vw;
    max-width: 95vw;
    max-height: 88vh;
    overflow-y: auto;
  }

  /* Directory */
  .directory-grid { grid-template-columns: 1fr; padding: 10px; }

  /* Admin */
  .admin-form-row { flex-direction: column; }
  .admin-form-row input,
  .admin-form-row select,
  .admin-form-row button { width: 100%; }
  table { font-size: 11px; }
  th, td { padding: 5px 6px; }

  /* Toast */
  #toast-stack { left: 8px; right: 8px; max-width: 100%; }
}

@media (max-width: 768px) {
  .auth-wrap { align-items: flex-start; padding: 0; }
  .auth-card { width: 100%; max-width: 100%; min-height: 100vh; border-radius: 0; padding: 40px 24px 30px; border: none; }
  .auth-card h1 { font-size: 26px; }
  .auth-card input { font-size: 16px; padding: 12px 14px; }
  .auth-card button[type=submit] { width: 100%; padding: 14px; font-size: 16px; margin-top: 8px; }
}
