
:root {
  --bg-body: #f3f4f6;
  --bg-main: #fff;
  --text-main: #172033;
  --border-color: #ddd;
  --border-light: #eee;
  --bg-hover: #eef6f4;
  --text-muted: #888;
  --text-dark-muted: #555;
  --bg-input: #f0f0f0;
  --bg-login: #075e54;
  --bg-msg-me: #d9fdd3;
  --bg-msg-other: #fff;
  --bg-settings: #f9f9f9;
  --bg-chat: #efeae2;
  --border-input: #ccc;
  --text-light-muted: #999;
  --text-mid-muted: #777;
  --text-dark: #333;
  --shadow-color: #0002;
  --bg-overlay: #0007;
  --bg-composer: #f7f7f7;
  --chat-text-size: 14px;
}

body.dark-mode {
  --bg-body: #111b21;
  --bg-main: #202c33;
  --text-main: #e9edef;
  --border-color: #2a3942;
  --border-light: #222e35;
  --bg-hover: #2a3942;
  --text-muted: #8696a0;
  --text-dark-muted: #aebac1;
  --bg-input: #2a3942;
  --bg-login: #111b21;
  --bg-msg-me: #005c4b;
  --bg-msg-other: #202c33;
  --bg-settings: #111b21;
  --bg-chat: #0b141a;
  --border-input: #2a3942;
  --text-light-muted: #8696a0;
  --text-mid-muted: #8696a0;
  --text-dark: #e9edef;
  --shadow-color: #00000040;
  --bg-overlay: #0009;
  --bg-composer: #202c33;
}

    * {
      box-sizing: border-box
    }

    html,
    body {
      margin: 0;
      width: 100%;
      height: 100%;
      font-family: Arial, sans-serif;
      background: var(--bg-body);
      color: var(--text-main);
      overflow: hidden
    }

    .app {
      width: 100%;
      height: 100dvh;
      display: flex;
      background: var(--bg-main);
      overflow: hidden
    }

    .sidebar {
      width: 300px;
      flex: 0 0 300px;
      border-right: 1px solid var(--border-color);
      background: var(--bg-main);
      display: flex;
      flex-direction: column;
      position: relative
    }

    .sideTop {
      padding: 12px;
      border-bottom: 1px solid var(--border-light)
    }

    .brand {
      font-size: 19px;
      font-weight: 700;
      margin-bottom: 10px
    }

    .newBtn {
      width: 100%;
      border: 0;
      background: #075e54;
      color: #fff;
      padding: 11px;
      border-radius: 9px;
      cursor: pointer;
      font-size: 14px
    }
    .dashboardNavBtn {
      width: 100%;
      border: 1px solid var(--border-color);
      background: transparent;
      color: var(--text-main);
      padding: 9px 11px;
      border-radius: 9px;
      cursor: pointer;
      font-size: 13px;
      margin-top: 6px;
      text-align: left;
      transition: background .18s;
    }
    .dashboardNavBtn:hover { background: var(--bg-hover); }
    .dashboardNavBtn.active { background: #075e54; color: #fff; border-color: #075e54; }

    .history {
      flex: 1;
      overflow-y: auto;
      padding: 7px
    }

    .historyItem {
      padding: 11px;
      border-radius: 9px;
      margin-bottom: 3px;
      cursor: pointer;
      display: flex;
      justify-content: space-between;
      gap: 8px
    }

    .historyItem:hover {
      background: var(--bg-hover)
    }
    .historyItem.active {
      background: #075e54;
      color: #fff;
    }
    .historyItem.active .hpreview,
    .historyItem.active .hdate {
      color: rgba(255, 255, 255, 0.85);
    }
    .historyItem.active .unread {
      background: #fff;
      color: #075e54;
    }

    .hrow {
      display: flex;
      align-items: center;
      gap: 6px
    }

    .unread {
      min-width: 20px;
      height: 20px;
      padding: 0 6px;
      border-radius: 10px;
      background: #075e54;
      color: #fff;
      font-size: 10px;
      font-weight: 700;
      display: inline-flex;
      align-items: center;
      justify-content: center
    }

    .hmain {
      min-width: 0
    }

    .hname {
      font-weight: 700;
      font-size: 14px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis
    }

    .hpreview {
      font-size: 11px;
      color: var(--text-mid-muted);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin-top: 4px
    }

    .hdate {
      font-size: 9px;
      color: var(--text-light-muted);
      white-space: nowrap
    }

    .chatArea {
      flex: 1;
      min-width: 0;
      display: flex;
      flex-direction: column;
      height: 100%
    }

    .header {
      flex: 0 0 auto;
      background: #075e54;
      color: #fff;
      padding: 10px 13px;
      display: flex;
      align-items: center;
      justify-content: space-between
    }

    .person {
      display: flex;
      align-items: center;
      gap: 9px;
      min-width: 0
    }

    .avatar {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      background: transparent;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: bold;
      flex: 0 0 auto
    }

    .title {
      font-size: 16px;
      font-weight: 700;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis
    }

    .sub {
      font-size: 11px;
      opacity: .8;
      margin-top: 3px
    }

    .actions {
      display: flex;
      gap: 7px
    }

    .iconbtn {
      border: 0;
      background: transparent;
      color: #fff;
      width: 40px;
      height: 40px;
      font-size: 22px;
      border-radius: 50%;
      cursor: pointer
    }

    .mobileBack {
      display: none
    }

    .sideHead {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 10px
    }

    .sideClose {
      display: none;
      border: 0;
      background: var(--border-light);
      color: var(--text-dark);
      width: 34px;
      height: 34px;
      border-radius: 50%;
      font-size: 22px;
      cursor: pointer
    }

    .sidebarOverlay {
      display: none
    }

    .chat {
      flex: 1;
      min-height: 0;
      overflow-y: auto;
      padding: 12px 10px;
      background: var(--bg-chat);
      overscroll-behavior: contain
    }

    .day {
      text-align: center;
      margin: 7px auto 12px;
      background: transparent;
      padding: 5px 10px;
      border-radius: 8px;
      width: max-content;
      font-size: 11px;
      color: var(--text-mid-muted)
    }

    .msg {
      display: flex;
      margin: 4px 0
    }

    .msg.me {
      justify-content: flex-end
    }

    .bubble {
      position: relative;
      max-width: min(78%, 520px);
      padding: 8px 10px;
      border-radius: 9px;
      background: var(--bg-main);
      box-shadow: 0 1px 2px var(--shadow-color);
      cursor: pointer;
      word-break: break-word
    }

    .me .bubble {
      background: var(--bg-msg-me)
    }

    .text {
      font-size: var(--chat-text-size);
      line-height: 1.35
    }

    .time {
      font-size: 9px;
      color: var(--text-mid-muted);
      text-align: right;
      margin-top: 4px
    }

    .ticks {
      font-size: 12px;
      margin-left: 3px;
      color: var(--text-mid-muted)
    }

    .ticks.read {
      color: #1687d9
    }

    .reply {
      border-left: 3px solid #075e54;
      background: #0000000b;
      padding: 6px 8px;
      margin-bottom: 6px;
      border-radius: 4px;
      font-size: 11px;
      color: var(--text-dark-muted)
    }

    .reply b {
      display: block;
      color: #075e54;
      margin-bottom: 2px
    }

    .photo {
      display: block;
      max-width: 270px;
      max-height: 320px;
      border-radius: 7px;
      cursor: pointer
    }

    .empty {
      text-align: center;
      color: var(--text-mid-muted);
      margin-top: 25vh;
      font-size: 13px
    }

    .composerWrap {
      flex: 0 0 auto;
      background: var(--bg-composer);
      border-top: 1px solid var(--border-color)
    }

    .replybar {
      display: none;
      align-items: center;
      justify-content: space-between;
      padding: 6px 10px;
      background: var(--bg-main);
      border-bottom: 1px solid var(--border-color)
    }

    .replybar.show {
      display: flex
    }

    .replyPreview {
      border-left: 3px solid #075e54;
      padding-left: 8px;
      font-size: 11px;
      color: var(--text-dark-muted);
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis
    }

    .cancel {
      border: 0;
      background: none;
      font-size: 22px;
      color: var(--text-mid-muted);
      cursor: pointer
    }

    .composer {
      position: relative;
      display: flex;
      gap: 7px;
      padding: 7px 9px;
      align-items: flex-end
    }

    .inputGroup {
      flex: 1;
      display: flex;
      align-items: flex-end;
      background: var(--bg-main);
      border: 1px solid var(--border-input);
      border-radius: 22px;
      padding: 0 14px;
      min-width: 0
    }

    .inputGroup textarea {
      flex: 1;
      border: none;
      background: transparent;
      color: var(--text-main);
      padding: 12px 0;
      font-size: var(--chat-text-size);
      outline: none;
      resize: none;
      max-height: 120px;
      font-family: inherit;
      line-height: 1.4;
      overflow-y: auto;
      box-sizing: border-box;
      margin: 0
    }

    .send,
    .emojiBtn {
      border: 0;
      width: 44px;
      height: 44px;
      border-radius: 50%;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0
    }

    .send {
      background: #075e54;
      color: #fff;
      font-size: 17px
    }

    .emojiBtn {
      background: var(--border-color);
      font-size: 22px
    }

    .attach {
      padding: 10px 0 10px 10px;
      color: var(--text-mid-muted);
      font-size: 20px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      position: relative
    }

    .attach.attached {
      color: #075e54
    }

    .attach.attached:after {
      content: '✓';
      position: absolute;
      right: -5px;
      bottom: 5px;
      background: #2e9b57;
      color: var(--bg-main);
      width: 14px;
      height: 14px;
      border-radius: 50%;
      font-size: 9px;
      display: flex;
      align-items: center;
      justify-content: center
    }

    .fileName {
      position: absolute;
      left: 9px;
      right: 9px;
      bottom: 58px;
      background: var(--bg-main);
      border: 1px solid var(--border-color);
      border-radius: 9px;
      padding: 8px;
      font-size: 11px;
      display: none;
      box-shadow: 0 3px 12px var(--shadow-color);
      z-index: 4
    }

    .fileName.show {
      display: block
    }

    .fileName button {
      float: right;
      border: 0;
      background: none;
      color: var(--text-mid-muted)
    }

    .emojiPicker {
      position: absolute;
      bottom: 58px;
      left: 7px;
      background: var(--bg-main);
      border: 1px solid var(--border-color);
      border-radius: 10px;
      padding: 8px;
      width: 260px;
      display: none;
      grid-template-columns: repeat(8, 1fr);
      gap: 4px;
      box-shadow: 0 5px 18px var(--shadow-color);
      z-index: 5
    }

    .emojiPicker.show {
      display: grid
    }

    .emojiPicker button {
      border: 0;
      background: var(--bg-input);
      border-radius: 6px;
      font-size: 21px;
      padding: 5px;
      cursor: pointer
    }

    .login {
      position: fixed;
      inset: 0;
      background: var(--bg-login);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      z-index: 20;
      padding: 20px
    }

    .loginbox {
      background: var(--bg-main);
      width: min(100%, 390px);
      padding: 26px;
      border-radius: 16px;
      box-shadow: 0 10px 40px var(--shadow-color)
    }

    .loginbox h2 {
      margin: 0 0 5px
    }

    .loginbox p {
      font-size: 13px;
      color: var(--text-mid-muted);
      margin: 0 0 18px
    }

    .loginbox input {
      width: 100%;
      padding: 12px;
      border: 1px solid var(--border-input);
      border-radius: 8px;
      margin: 6px 0 12px;
      font-size: 15px;
      background: transparent;
      color: var(--text-main);
      outline: none;
    }

    .loginbox button {
      width: 100%;
      padding: 12px;
      border: 0;
      border-radius: 8px;
      background: #075e54;
      color: #fff;
      font-size: 15px;
      cursor: pointer
    }

    .err {
      color: #b00020;
      font-size: 12px;
      min-height: 18px
    }

    .toast {
      position: fixed;
      right: 14px;
      top: 68px;
      background: #075e54;
      color: var(--bg-main);
      padding: 9px 12px;
      border-radius: 8px;
      display: none;
      z-index: 30;
      font-size: 12px;
      max-width: 80%
    }

    .renameBox {
      position: fixed;
      inset: 0;
      background: var(--bg-overlay);
      display: none;
      align-items: center;
      justify-content: center;
      z-index: 15
    }

    .renameBox.show {
      display: flex
    }

    .renameCard {
      background: var(--bg-main);
      padding: 20px;
      border-radius: 12px;
      width: min(90%, 350px)
    }

    .renameCard input {
      width: 100%;
      padding: 11px;
      border: 1px solid var(--border-input);
      border-radius: 7px;
      margin: 8px 0 12px;
      background: transparent;
      color: var(--text-main);
    }

    .renameCard button {
      padding: 9px 13px;
      border: 0;
      border-radius: 7px;
      background: #075e54;
      color: var(--bg-main)
    }

    .renameActions {
      text-align: right
    }

    input[type=file] {
      display: none
    }

    @media(max-width:700px) {
      .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(86%, 330px);
        z-index: 21;
        transform: translateX(-105%);
        transition: transform .2s;
        box-shadow: 8px 0 25px var(--shadow-color)
      }

      .sidebar.show {
        transform: translateX(0)
      }

      .sideClose {
        display: block
      }

      .sidebarOverlay {
        position: fixed;
        inset: 0;
        background: var(--bg-overlay);
        z-index: 20
      }

      .sidebarOverlay.show {
        display: block
      }

      .mobileBack {
        display: block
      }

      .chatArea {
        width: 100%
      }

      .bubble {
        max-width: 85%
      }
    }


.settingsBtn {
    width: calc(100% - 24px);
    margin: 12px;
    border: none;
    background: #075e54;
    color: #fff;
    padding: 12px;
    text-align: center;
    font-size: 15px;
    font-weight: bold;
    border-radius: 9px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 10px rgba(7, 94, 84, 0.3);
    transition: background 0.3s, transform 0.1s;
}
.settingsBtn:hover {
    background: #064c44;
}
.settingsBtn:active {
    transform: scale(0.98);
}
.settingsSidebar {
    position: absolute;
    bottom: 0;
    left: -300px;
    width: 300px;
    height: 100%;
    background: var(--bg-settings);
    z-index: 100;
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}
.settingsSidebar.open {
    left: 0;
}
.settingsHeader {
    padding: 16px 20px;
    background: #075e54;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 18px;
    font-weight: 500;
}
.settingsHeader button {
    border: none;
    background: transparent;
    font-size: 24px;
    cursor: pointer;
    color: #fff;
    padding: 0;
    line-height: 1;
}
.settingsBody {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}
.settingItem {
    margin-bottom: 24px;
}
.settingItem select option {
    background: var(--bg-main);
    color: var(--text-main);
}
.settingItem b {
    display: block;
    color: #075e54;
    font-size: 14px;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border-color);
  transition: .4s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
}
input:checked + .slider {
  background-color: #075e54;
}
input:checked + .slider:before {
  transform: translateX(20px);
}
.slider.round {
  border-radius: 24px;
}
.slider.round:before {
  border-radius: 50%;
}

/* ===== DASHBOARD ===== */
/* dashboardView is inline inside chatArea — no fixed overlay */
.dashInner {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}
.dashHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 24px;
}

.dashGreet {
  display: flex;
  align-items: center;
  gap: 14px;
}
.dashAvatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #075e54;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px #075e5455;
  flex-shrink: 0;
}
.dashWelcome {
  font-size: 13px;
  color: var(--text-muted);
}
.dashUsername {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-main);
}
.dashActions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.dashBtn {
  padding: 9px 16px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s, transform .15s;
  color: #fff;
}
.dashBtn:hover { opacity: .85; transform: translateY(-1px); }
.dashBtnSec { background: #075e54; }
.dashBtnDanger { background: #e53935; }

.dashStats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 30px;
}
.dashStatCard {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 18px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 2px 10px var(--shadow-color);
  transition: transform .2s;
}
.dashStatCard:hover { transform: translateY(-2px); }
.dashStatIcon { font-size: 26px; }
.dashStatNum {
  font-size: 20px;
  font-weight: 700;
  color: #075e54;
}
.dashStatLabel {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
#dashUnreadCard.has-unread .dashStatNum { color: #e53935; }

.dashSectionTitle {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.dashChatList {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 26px;
}
.dashLoading {
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px 0;
  text-align: center;
}
.dashChatCard {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: background .18s, transform .15s, box-shadow .18s;
  box-shadow: 0 2px 8px var(--shadow-color);
}
.dashChatCard:hover {
  background: var(--bg-hover);
  transform: translateX(3px);
  box-shadow: 0 4px 14px var(--shadow-color);
}
.dashChatIcon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #075e54;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.dashChatInfo { flex: 1; min-width: 0; }
.dashChatName {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-main);
}
.dashChatPreview {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dashChatRight {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}
.dashUnreadBadge {
  background: #e53935;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 2px 7px;
  min-width: 22px;
  text-align: center;
}
.dashChatArrow {
  font-size: 16px;
  color: var(--text-muted);
}
.dashOpenChatBtn {
  width: 100%;
  padding: 15px;
  background: #075e54;
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s, transform .15s;
  letter-spacing: .03em;
}
.dashOpenChatBtn:hover {
  background: #054d43;
  transform: translateY(-2px);
}
