/**
 * Mac Chat — Platinum-styled IRC client.
 *
 * The page shell (menubar/header/footer) and the base `.window` / `.btn`
 * chrome come from the platinum theme (platinum.css). This file adds the
 * AIM-style chat app: Buddy List window + tabbed chat window.
 * Design language adapted from bridge/static/client.html.
 */

:root {
  --plat-window: #dddddd;
  --plat-window-deep: #cccccc;
  --plat-chrome: #cccccc;
  --plat-chrome-light: #e0e0e0;
  --plat-bevel-light: #ffffff;
  --plat-bevel-dark: #808080;
  --plat-border: #000000;
  --plat-text: #000000;
  --plat-text-muted: #555555;
  --plat-accent: #312f9a;
  --plat-accent-hover: #4744c0;
  --plat-online: #15a015;
  --plat-away: #c8a800;
  --plat-offline: #888888;
  --plat-error: #b30000;
  --plat-self: #003a8c;
  --plat-other: #8c0026;
  --plat-highlight: #ccccff;
}

/* ===== Page layout ===== */

.mac-chat {
  display: flex;
  gap: 12px;
  align-items: stretch;
  height: calc(100vh - 320px);
  min-height: 480px;
  max-width: 1100px;
  margin: 0 auto;
}

.mac-chat .window {
  margin-bottom: 0; /* platinum.css windows carry a drop margin */
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.mac-chat__buddy {
  width: 270px;
  flex-shrink: 0;
}

.mac-chat__main {
  flex: 1 1 auto;
  min-width: 0;
}

.mac-chat__buddy-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 0;
  padding: 10px;
}

.mac-chat__main-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  padding: 10px;
  gap: 8px;
}

.mac-chat__main-title {
  position: relative;
}

.mac-chat__drawer-toggle {
  display: none;
  position: absolute;
  left: 6px;
  top: 2px;
  padding: 0 8px;
  font-size: 13px;
  line-height: 17px;
  z-index: 2;
}

/* ===== Buddy List ===== */

.buddy-identity {
  border: 1px solid var(--plat-border);
  background: var(--plat-window);
  box-shadow: inset 1px 1px 0 var(--plat-bevel-light), inset -1px -1px 0 var(--plat-bevel-dark);
  padding: 8px 10px;
}

.buddy-identity__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.buddy-nick {
  flex: 1 1 auto;
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.buddy-nick:hover {
  color: var(--plat-accent);
  text-decoration: underline;
}

.buddy-status-text {
  margin-top: 4px;
  font-size: 12px;
  color: var(--plat-text-muted);
  min-height: 15px;
}

.status-dot {
  width: 11px;
  height: 11px;
  border: 1px solid var(--plat-border);
  border-radius: 50%;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  flex-shrink: 0;
}

.status-online { background: var(--plat-online); }
.status-offline { background: var(--plat-offline); }
.status-away { background: var(--plat-away); }
.status-error { background: var(--plat-error); }

.buddy-sound {
  padding: 1px 8px;
  font-size: 12px;
}

.buddy-sound.is-muted {
  opacity: 0.45;
}

.buddy-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.buddy-section--grow {
  flex: 3 1 0;
}

.buddy-section--rooms {
  flex: 2 1 0;
  min-height: 110px;
}

.buddy-section--rooms .buddy-list {
  flex: 1 1 auto;
  min-height: 60px;
}

.buddy-section__label {
  font-weight: bold;
  font-size: 13px;
  padding: 2px 4px;
  margin-bottom: 4px;
  background: linear-gradient(to bottom, #f0f0f0, #d8d8d8);
  border: 1px solid var(--plat-border);
  border-radius: 3px;
}

.buddy-section__count {
  font-weight: normal;
  color: var(--plat-text-muted);
}

.buddy-list {
  background: #fff;
  border: 1px solid var(--plat-border);
  box-shadow: inset 1px 1px 0 #888, inset -1px -1px 0 var(--plat-bevel-light);
  overflow-y: auto;
  min-height: 0;
}

.buddy-list--scroll {
  flex: 1 1 auto;
  min-height: 80px;
}

.room-row,
.member-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}

.room-row:hover,
.member-row:hover {
  background: var(--plat-accent);
  color: #fff;
}

.room-row.is-joined .room-name { font-weight: bold; }

.room-row .room-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--plat-text-muted);
}

.room-row:hover .room-count { color: #fff; }

.room-icon {
  width: 10px;
  height: 10px;
  border: 1px solid var(--plat-border);
  border-radius: 2px;
  background: #fff;
  flex-shrink: 0;
}

.room-row.is-joined .room-icon {
  background: var(--plat-online);
}

.member-prefix {
  width: 14px;
  text-align: center;
  font-weight: bold;
  flex-shrink: 0;
}

.member-prefix.p-op { color: #1a7a1a; }
.member-prefix.p-voice { color: #8a5a00; }
.member-row:hover .member-prefix { color: #fff; }

.member-row.is-away .member-name {
  font-style: italic;
  color: var(--plat-text-muted);
}

.member-row.is-away:hover .member-name { color: #fff; }

.member-row.is-self .member-name { font-weight: bold; color: var(--plat-self); }
.member-row.is-self:hover .member-name { color: #fff; }

.member-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.buddy-empty {
  padding: 12px 10px;
  text-align: center;
  color: var(--plat-text-muted);
  font-style: italic;
  font-size: 13px;
}

.buddy-join-row input {
  width: 100%;
  margin-top: 6px;
  font-size: 13px;
}

.buddy-footer {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  border-top: 1px solid #b0b0b0;
  box-shadow: 0 1px 0 #fff inset;
  padding-top: 8px;
}

/* ===== Tabs ===== */

.tabs-row {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  flex-shrink: 0;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 10px;
  font-size: 13px;
  border: 1px solid var(--plat-border);
  border-radius: 3px 3px 0 0;
  background: linear-gradient(to bottom, #f2f2f2, #d8d8d8);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  position: relative;
}

.tab:hover {
  background: linear-gradient(to bottom, #fafafa, #e4e4e4);
}

.tab.is-active {
  background: var(--plat-accent);
  color: #fff;
  font-weight: bold;
}

.tab.is-active:hover {
  background: var(--plat-accent-hover);
}

.tab-close {
  border: none;
  background: transparent;
  padding: 0 2px;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  color: inherit;
  opacity: 0.7;
}

.tab-close:hover { opacity: 1; }

.tab-badge {
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--plat-error);
  color: #fff;
  font-size: 11px;
  font-weight: bold;
  line-height: 16px;
  text-align: center;
  display: none;
}

.tab.has-unread .tab-badge { display: inline-block; }

/* ===== Chat pane ===== */

.chat-pane {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  gap: 8px;
}

.chat-log {
  flex: 1 1 auto;
  min-height: 0;
  background: #fff;
  border: 1px solid var(--plat-border);
  box-shadow: inset 1px 1px 0 #aaa, inset -1px -1px 0 var(--plat-bevel-light);
  overflow-y: auto;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.45;
  user-select: text;
}

.chat-log__stuck {
  position: sticky;
  bottom: 0;
  margin: 6px auto 0;
  width: max-content;
}

.chat-log__stuck .btn {
  font-size: 12px;
  padding: 2px 12px;
}

.msg {
  margin-bottom: 5px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg-time {
  font-family: Monaco, "Andale Mono", "Lucida Console", monospace;
  font-size: 11px;
  color: var(--plat-text-muted);
  margin-right: 4px;
}

.msg .msg-from {
  font-weight: bold;
  margin-right: 5px;
  cursor: pointer;
}

.msg .msg-from:hover { text-decoration: underline; }

.msg.self .msg-from { color: var(--plat-self); }
.msg.other .msg-from { color: var(--plat-other); }

.msg.system {
  color: var(--plat-text-muted);
  font-style: italic;
}

.msg.action { font-style: italic; }

.msg.notice .msg-text { color: #6a4a00; }

.msg.kind-notice::before {
  content: "[notice] ";
  font-size: 11px;
  color: var(--plat-text-muted);
  font-style: normal;
}

.msg a {
  color: #0000cc;
}

.msg a:visited { color: #551a8b; }

.chat-walkthrough {
  border: 1px solid var(--plat-border);
  background: #f4f4ee;
  box-shadow: inset 1px 1px 0 var(--plat-bevel-light), inset -1px -1px 0 var(--plat-bevel-dark);
  padding: 10px 14px;
  margin-bottom: 10px;
  font-style: normal;
}

.chat-walkthrough h3 {
  font-size: 13px;
  margin: 8px 0 2px;
}

.chat-walkthrough ul {
  margin: 2px 0 6px 18px;
  padding: 0;
}

.chat-walkthrough li { margin-bottom: 2px; }

.chat-walkthrough code {
  font-family: Monaco, "Andale Mono", "Lucida Console", monospace;
  font-size: 12px;
  background: #e8e8e8;
  border: 1px solid #b8b8b8;
  border-radius: 2px;
  padding: 0 3px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-shrink: 0;
}

.chat-input-row textarea {
  flex: 1 1 auto;
  resize: none;
  max-height: 90px;
  overflow-y: auto;
  font-size: 14px;
  font-family: inherit;
}

.chat-input-row .btn {
  flex-shrink: 0;
  padding: 0 18px;
}

/* ===== Help modal ===== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal-overlay .window {
  width: min(560px, 92vw);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
}

.chat-help-body {
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.5;
}

.chat-help-body h3 {
  font-size: 13px;
  margin: 10px 0 3px;
}

.chat-help-body ul {
  margin: 3px 0 8px 18px;
  padding: 0;
}

.chat-help-body li { margin-bottom: 3px; }

.chat-help-body code {
  font-family: Monaco, "Andale Mono", "Lucida Console", monospace;
  font-size: 12px;
  background: #e8e8e8;
  border: 1px solid #b8b8b8;
  border-radius: 2px;
  padding: 0 3px;
}

.chat-modal-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 14px 12px;
}

/* ===== Rooms browser modal ===== */

.chat-rooms-modal {
  width: min(560px, 92vw);
}

.chat-rooms-hint {
  color: var(--plat-text-muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.chat-rooms-list {
  max-height: 55vh;
}

/* ===== Sign-on window ===== */

.chat-signon {
  width: min(480px, 92vw);
}

.chat-signon__intro {
  margin-bottom: 6px;
}

.chat-signon__hint {
  color: var(--plat-text-muted);
  font-size: 12px;
  margin-bottom: 10px;
}

.chat-signon__label {
  display: block;
  font-weight: bold;
  margin-bottom: 4px;
}

.chat-signon input {
  font-size: 15px;
}

/* ===== Custom scrollbars (Platinum) ===== */

.chat-log::-webkit-scrollbar,
.buddy-list::-webkit-scrollbar,
.chat-help-body::-webkit-scrollbar {
  width: 16px;
  background: #d4d4d4;
}

.chat-log::-webkit-scrollbar-track,
.buddy-list::-webkit-scrollbar-track,
.chat-help-body::-webkit-scrollbar-track {
  background: repeating-linear-gradient(45deg, #d4d4d4 0 2px, #c4c4c4 2px 4px);
  border-left: 1px solid var(--plat-border);
}

.chat-log::-webkit-scrollbar-thumb,
.buddy-list::-webkit-scrollbar-thumb,
.chat-help-body::-webkit-scrollbar-thumb {
  background: linear-gradient(to right, #f0f0f0, #c0c0c0);
  border: 1px solid var(--plat-border);
  box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.7);
}

/* ===== Mobile (site switches below 720px) ===== */

@media (max-width: 720px) {
  .mac-chat {
    height: auto;
    min-height: 0;
    flex-direction: column;
  }

  .mac-chat__buddy {
    display: none;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(300px, 85vw);
    z-index: 900;
    height: 100%;
  }

  .mac-chat__buddy.open {
    display: flex;
  }

  .mac-chat__drawer-toggle {
    display: inline-block;
  }

  .chat-pane {
    /* fill the remaining viewport so the input sits above the keyboard */
    height: calc(100vh - 260px);
    min-height: 380px;
  }

  .tabs-row { -webkit-overflow-scrolling: touch; }
}
