/* ===========================================================================
   Interoffice
   One stylesheet. Light by default, dark when the machine asks for it.

   Availability is never shown by colour alone — each state has its own shape
   as well, and the directory spells it out in words. Nobody has to be able to
   tell a green dot from an amber one.
   =========================================================================== */

:root {
  --paper:        #FFFFFF;
  --surface:      #F5F6F8;
  --surface-2:    #EDEFF3;
  --line:         #DDE1E7;
  --line-strong:  #C3C9D2;
  --ink:          #16202E;
  --ink-soft:     #5A6676;
  --ink-faint:    #8A93A1;
  --accent:       #1F4E8C;
  --accent-ink:   #FFFFFF;
  --accent-soft:  #E7EEF8;
  --bubble-mine:  #1F4E8C;
  --bubble-their: #EDEFF3;
  --danger:       #9C2B2B;
  --danger-soft:  #F7E8E8;
  --good:         #1F5C4A;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 1px 2px rgba(22,32,46,.08), 0 4px 16px rgba(22,32,46,.06);
  --font:         "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:       #12161C;
    --surface:     #171C24;
    --surface-2:   #1E242E;
    --line:        #2A313C;
    --line-strong: #3A434F;
    --ink:         #E8ECF2;
    --ink-soft:    #A4AEBC;
    --ink-faint:   #76818F;
    --accent:      #4A86D6;
    --accent-ink:  #0B0E13;
    --accent-soft: #1C2938;
    --bubble-mine: #2C5FA0;
    --bubble-their:#232A35;
    --danger:      #D98A8A;
    --danger-soft: #2E1E1E;
    --good:        #6FBFA5;
    --shadow:      0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  --paper:       #12161C;
  --surface:     #171C24;
  --surface-2:   #1E242E;
  --line:        #2A313C;
  --line-strong: #3A434F;
  --ink:         #E8ECF2;
  --ink-soft:    #A4AEBC;
  --ink-faint:   #76818F;
  --accent:      #4A86D6;
  --accent-ink:  #0B0E13;
  --accent-soft: #1C2938;
  --bubble-mine: #2C5FA0;
  --bubble-their:#232A35;
  --danger:      #D98A8A;
  --danger-soft: #2E1E1E;
  --good:        #6FBFA5;
  --shadow:      0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }

/* Any rule that sets `display` outranks the hidden attribute's own
   display:none. One line here stops every future rule in this file from
   quietly un-hiding something. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; }

/* --------------------------------------------------------------------- */
/* Sign-in and setup                                                      */
/* --------------------------------------------------------------------- */

body.centred {
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  padding: 24px 16px;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px 26px;
}
.card.setup { max-width: 460px; }

.card h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.card .lead {
  margin: 2px 0 20px;
  color: var(--ink-soft);
  font-size: 13px;
}
.card hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 20px 0 16px;
}

label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}
label input, label select, label textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-weight: 400;
  color: var(--ink);
}
label input:focus, label select:focus, label textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
label small {
  display: block;
  margin-top: 4px;
  font-weight: 400;
  font-size: 12px;
  color: var(--ink-faint);
}

.btn {
  display: inline-block;
  padding: 9px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--line); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  width: 100%;
  padding: 11px 16px;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }

.notice {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin: 0 0 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.notice.bad  { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.notice.good { border-color: var(--good); color: var(--good); }
.notice.warn { border-color: var(--line-strong); }
.notice code { font-size: 12px; }

/* --------------------------------------------------------------------- */
/* App shell                                                              */
/* --------------------------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: 272px 1fr;
  height: 100vh;
  height: 100dvh;
}

/* Narrow window — the normal docked size. One pane at a time. */
@media (max-width: 719px) {
  .app { grid-template-columns: 1fr; }
  .app:not(.show-convo) .pane-convo { display: none; }
  .app.show-convo .pane-list { display: none; }
}
@media (min-width: 720px) {
  .back-btn { display: none !important; }
}

/* --------------------------------------------------------------------- */
/* Left pane                                                              */
/* --------------------------------------------------------------------- */

.pane-list {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand .company {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-faint);
}

.icon-btn {
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 5px 7px;
  cursor: pointer;
  color: var(--ink-soft);
  line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { display: block; width: 17px; height: 17px; }

/* My own row */
.me-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.me-row .who { flex: 1; min-width: 0; }
.me-row .who b { display: block; font-size: 13px; }
.me-row select {
  border: 1px solid var(--line-strong);
  background: var(--paper);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
  font-size: 12px;
  max-width: 100%;
}

.list-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 10px;
}

.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.row {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 14px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  position: relative;
}
.row:hover { background: var(--surface-2); }
.row.active { background: var(--accent-soft); }
.row.active::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
}
.row .main { flex: 1; min-width: 0; }
.row .name {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row.unread-row .name { font-weight: 700; }
.row .sub {
  display: block;
  font-size: 11.5px;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  flex: 0 0 auto;
  min-width: 19px;
  height: 19px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
  line-height: 19px;
  text-align: center;
}

/* Avatars */
.avatar {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  letter-spacing: .02em;
}
.avatar.lg { width: 56px; height: 56px; font-size: 19px; }
.avatar.hash {
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
}

/* ---- Availability -----------------------------------------------------
   Shape carries the meaning, not just the shade:
     online  solid disc
     away    hollow ring
     busy    disc with a bar through it
     offline faint hollow ring
   ---------------------------------------------------------------------- */
.dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--paper);
  box-sizing: content-box;
}
.pane-convo .dot { border-color: var(--paper); }
.dot.online  { background: var(--good); }
.dot.away    { background: var(--paper); border-color: var(--surface); box-shadow: inset 0 0 0 2.5px var(--ink-soft); }
.dot.busy    { background: var(--danger); }
.dot.busy::after {
  content: "";
  position: absolute;
  left: 1.5px; right: 1.5px; top: 4px;
  height: 2.5px;
  background: var(--paper);
  border-radius: 2px;
}
.dot.offline { background: var(--paper); box-shadow: inset 0 0 0 2px var(--line-strong); }

.state-word {
  font-size: 11.5px;
  color: var(--ink-faint);
}

/* --------------------------------------------------------------------- */
/* Right pane                                                             */
/* --------------------------------------------------------------------- */

.pane-convo {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--paper);
  position: relative;
}

.convo-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  min-height: 54px;
}
.convo-head .title { flex: 1; min-width: 0; }
.convo-head .title b {
  display: block;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.convo-head .title span {
  display: block;
  font-size: 11.5px;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msgs {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.day-sep {
  align-self: center;
  margin: 14px 0 8px;
  padding: 3px 11px;
  background: var(--surface-2);
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-soft);
}

.msg { display: flex; gap: 9px; margin-top: 10px; max-width: 100%; }
.msg.run { margin-top: 2px; }
.msg .gutter { flex: 0 0 30px; }
/* Both of these are spans, so they need telling to be blocks — left inline
   they flow alongside the bubble instead of sitting above it. */
.msg .body { display: block; min-width: 0; flex: 1; }
.msg .meta {
  display: block;
  font-size: 11.5px;
  color: var(--ink-faint);
  margin-bottom: 2px;
}
.msg .meta b { color: var(--ink); font-size: 12.5px; font-weight: 700; }

.bubble {
  display: inline-block;
  max-width: min(560px, 100%);
  padding: 7px 11px;
  border-radius: var(--radius);
  background: var(--bubble-their);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.mine { flex-direction: row-reverse; }
.msg.mine .body { text-align: right; }
.msg.mine .bubble {
  background: var(--bubble-mine);
  color: #fff;
  text-align: left;
}
.bubble a { color: inherit; }

.msg.system { justify-content: center; margin-top: 10px; }
.msg.system .bubble {
  background: transparent;
  border: 1px dashed var(--line-strong);
  color: var(--ink-faint);
  font-size: 12px;
}

.composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--paper);
}
.composer textarea {
  flex: 1;
  resize: none;
  min-height: 38px;
  max-height: 140px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  line-height: 1.4;
}
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.composer .send {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--radius);
  padding: 9px 14px;
  font-weight: 600;
  cursor: pointer;
  height: 38px;
}
.composer .send:disabled { opacity: .45; cursor: default; }

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--ink-faint);
  padding: 30px;
  text-align: center;
}
.empty b { color: var(--ink-soft); font-size: 15px; }

/* --------------------------------------------------------------------- */
/* Calls                                                                  */
/* --------------------------------------------------------------------- */

.call-layer {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: var(--paper);
  display: flex;
  flex-direction: column;
}
.call-layer[hidden] { display: none; }

.call-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #0B0E13;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#remoteVideo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #0B0E13;
}
#remoteVideo.hidden { display: none; }

#localVideo {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 112px;
  max-width: 34%;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,.25);
  background: #000;
  object-fit: cover;
  transform: scaleX(-1);   /* a mirror, the way people expect to see themselves */
}
#localVideo.hidden { display: none; }

.call-who {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #E8ECF2;
  text-align: center;
  padding: 20px;
}
.call-who.hidden { display: none; }
.call-who .avatar {
  background: #1E242E;
  border-color: #3A434F;
  color: #C3C9D2;
}
.call-who b { font-size: 18px; font-weight: 600; }
.call-who .state-line { font-size: 13px; color: #A4AEBC; }

.call-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: var(--paper);
  flex-wrap: wrap;
}
.call-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.call-btn:hover { background: var(--line); }
.call-btn svg { width: 20px; height: 20px; display: block; }
.call-btn.off {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}
.call-btn.hangup {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  width: 58px;
}
.call-btn.answer {
  background: var(--good);
  border-color: var(--good);
  color: #fff;
  width: 58px;
}
.call-label {
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: var(--ink-faint);
  order: 10;
}

/* Incoming call banner, shown wherever you are */
.ring {
  position: fixed;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  z-index: 60;
  width: min(360px, calc(100vw - 28px));
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 14px;
  display: flex;
  align-items: center;
  gap: 11px;
  animation: ringIn .18s ease-out;
}
.ring[hidden] { display: none; }
@keyframes ringIn { from { opacity: 0; transform: translate(-50%, -8px); } }
.ring .who { flex: 1; min-width: 0; }
.ring .who b { display: block; font-size: 14px; }
.ring .who span { font-size: 12px; color: var(--ink-faint); }
.ring .acts { display: flex; gap: 7px; }
.ring .acts button {
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  padding: 7px 11px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-2);
}
.ring .acts .yes { background: var(--good); border-color: var(--good); color: #fff; }
.ring .acts .no  { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

/* --------------------------------------------------------------------- */
/* Small bits                                                             */
/* --------------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 70;
  background: var(--ink);
  color: var(--paper);
  padding: 9px 15px;
  border-radius: 20px;
  font-size: 13px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10,14,19,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  overflow: auto;
}
.sheet[hidden] { display: none; }
.sheet .inner {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
  padding: 20px;
  max-height: 100%;
  overflow: auto;
}
.sheet h2 { margin: 0 0 4px; font-size: 16px; }
.sheet .muted { color: var(--ink-faint); font-size: 12.5px; margin: 0 0 16px; }
.sheet .acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.contact-lines { margin: 14px 0 0; font-size: 13px; }
.contact-lines div { display: flex; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); }
.contact-lines dt, .contact-lines .k {
  width: 86px;
  flex: 0 0 auto;
  color: var(--ink-faint);
  font-size: 12px;
  padding-top: 1px;
}
.contact-lines .v { flex: 1; overflow-wrap: anywhere; }
.contact-lines a { color: var(--accent); }

.offline-bar {
  flex: 0 0 auto;
  background: var(--danger-soft);
  color: var(--danger);
  border-bottom: 1px solid var(--danger);
  padding: 6px 14px;
  font-size: 12.5px;
  text-align: center;
  font-weight: 600;
}
.offline-bar[hidden] { display: none; }

/* Scrollbars that do not shout */
.list-scroll::-webkit-scrollbar, .msgs::-webkit-scrollbar { width: 10px; }
.list-scroll::-webkit-scrollbar-thumb, .msgs::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 6px;
  border: 3px solid transparent;
  background-clip: content-box;
}
.list-scroll::-webkit-scrollbar-track, .msgs::-webkit-scrollbar-track { background: transparent; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
