/* WebIRC – classic mIRC / Windows 98 world. Tokens first, then components. */
:root {
  --face: #d4d0c8; --hi: #fff; --sh: #808080; --dk: #404040;
  --title: #0a246a; --title2: #a6caf0; --title-in: #808080; --title-in2: #c0c0c0;
  --bg: #fff; --fg: #000; --muted: #555; --desk: #3a6ea5;
  --c-join: #007a00; --c-part: #7f0000; --c-quit: #00007f; --c-notice: #7f007f;
  --c-action: #8a008a; --c-mode: #b35900; --c-err: #b00000; --c-info: #00007f; --c-self: #555;
  --hl-bg: #fff1c4; --sel: #0a246a; --sel-fg: #fff;
  --font: "Fixedsys Excelsior", "Consolas", "Cascadia Mono", "Courier New", monospace;
  --ui: Tahoma, "Segoe UI", "Noto Sans", sans-serif;
  --nicklist-w: 140px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --face: #2d2d30; --hi: #4a4a4f; --sh: #151517; --dk: #000;
    --title: #1f3b73; --title2: #3d6fb8; --title-in: #3a3a3e; --title-in2: #4a4a50;
    --bg: #141416; --fg: #e2e2e2; --muted: #a0a0a8; --desk: #18222d;
    --c-join: #5fd35f; --c-part: #ff7a7a; --c-quit: #8fb4ff; --c-notice: #e08ae0;
    --c-action: #e98ee9; --c-mode: #ffb35c; --c-err: #ff6b6b; --c-info: #9ab8ff; --c-self: #9a9aa2;
    --hl-bg: #4a3b12; --sel: #3d6fb8; --sel-fg: #fff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--face); color: var(--fg); font: 13px/1.35 var(--ui);
  caret-color: var(--fg);
}
body.dragging { user-select: none; cursor: grabbing; }
::selection { background: var(--sel); color: var(--sel-fg); }
* { scrollbar-color: var(--sh) var(--face); scrollbar-width: thin; }
::-webkit-scrollbar { width: 14px; height: 14px; }
::-webkit-scrollbar-track { background: var(--face); }
::-webkit-scrollbar-thumb { background: var(--face); border: 2px outset var(--face); }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ico { width: 14px; height: 14px; flex: none; vertical-align: -2px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: square; }
.ico.big { width: 44px; height: 44px; stroke-width: 1; }

/* ---------- controls ---------- */
button {
  font: inherit; color: var(--fg); background: var(--face); cursor: pointer;
  border: 1px solid; border-color: var(--hi) var(--dk) var(--dk) var(--hi);
  box-shadow: inset -1px -1px 0 var(--sh), inset 1px 1px 0 var(--face);
  padding: 3px 10px; min-height: 24px; display: inline-flex; align-items: center; gap: 5px;
}
button:hover:not(:disabled) { background: color-mix(in srgb, var(--face) 88%, var(--hi)); }
button:active:not(:disabled) { border-color: var(--dk) var(--hi) var(--hi) var(--dk); box-shadow: inset 1px 1px 0 var(--sh); }
button:disabled { color: var(--sh); cursor: default; text-shadow: 1px 1px 0 var(--hi); }
button.primary { font-weight: bold; outline: 1px solid var(--dk); outline-offset: -1px; }
:focus-visible { outline: 1px dotted var(--fg) !important; outline-offset: -4px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline-offset: 0; }
input, select, textarea {
  font: inherit; color: var(--fg); background: var(--bg);
  border: 2px inset var(--face); padding: 3px 4px; min-height: 24px; border-radius: 0;
}
input:disabled { background: var(--face); color: var(--sh); }
input:user-invalid { border-color: var(--c-err); }

/* ---------- menubar ---------- */
.menubar { display: flex; gap: 4px; align-items: center; padding: 3px 6px; border-bottom: 1px solid var(--sh); box-shadow: 0 1px 0 var(--hi); }
.logo { display: inline-flex; align-items: center; gap: 6px; font-weight: bold; margin-right: 10px; }
.mobile-only { display: none; }
.user { margin-left: auto; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; padding-right: 4px; }
.logout { margin: 0; }

/* ---------- layout ---------- */
.main { flex: 1; display: flex; min-height: 0; }
#treebar { width: 190px; flex: none; background: var(--bg); border: 2px inset var(--face); overflow: auto; }
.tree-title { padding: 3px 8px; background: var(--face); font-weight: bold; border-bottom: 1px solid var(--sh); }
#tree, #tree ul { list-style: none; margin: 0; padding: 2px 0; }
#tree ul { padding: 0 0 0 14px; }
#tree li > span { display: block; padding: 2px 8px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#tree li > span:hover { text-decoration: underline; }
#tree li > span.active { background: var(--title); color: #fff; }
#tree li > span.unread { color: var(--c-err); font-weight: bold; }
#tree li > span.highlight { color: var(--c-mode); font-weight: bold; }
#tree .net > span { font-weight: bold; }
#tree .net.offline > span { color: var(--sh); font-weight: normal; }
#tree .net.offline > span::after { content: " (offline)"; font-size: 11px; }

#mdi { flex: 1; position: relative; background: var(--desk); overflow: hidden; }

/* ---------- empty state ---------- */
.empty {
  position: absolute; inset: 0; margin: auto; width: min(360px, calc(100% - 32px)); height: fit-content;
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  padding: 22px 20px; background: var(--face); border: 2px outset var(--face); box-shadow: 2px 2px 0 var(--dk);
}
.empty[hidden] { display: none; }
.empty p { margin: 0; color: var(--fg); }

/* ---------- MDI windows ---------- */
.win {
  position: absolute; display: flex; flex-direction: column; min-width: 280px; min-height: 170px;
  background: var(--face); border: 2px outset var(--face); box-shadow: 1px 1px 0 var(--dk);
}
.win.minimized { display: none; }
.win.maximized { inset: 0 !important; width: auto !important; height: auto !important; }
.win.maximized .rz { display: none; }
.titlebar {
  display: flex; align-items: center; gap: 5px; padding: 2px 3px 2px 5px; color: #fff; cursor: grab;
  user-select: none; touch-action: none;
  background: linear-gradient(90deg, var(--title-in), var(--title-in2));
}
.win.maximized .titlebar { cursor: default; }
.win.focused .titlebar { background: linear-gradient(90deg, var(--title), var(--title2)); }
.titlebar .title { flex: 1; font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.titlebar .ctrl { display: flex; gap: 2px; }
.titlebar button { padding: 0; width: 18px; min-height: 16px; height: 16px; justify-content: center; font-size: 11px; font-weight: bold; line-height: 1; }
.topic { background: var(--bg); padding: 3px 6px; border-bottom: 1px solid var(--sh); font-family: var(--font); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topic:empty { display: none; }
.body { flex: 1; display: flex; min-height: 0; }
.log {
  flex: 1; min-width: 0; overflow-y: auto; background: var(--bg); padding: 3px 6px; border: 2px inset var(--face);
  font: 13px/1.4 var(--font); white-space: pre-wrap; overflow-wrap: anywhere;
}
.split { width: 5px; flex: none; cursor: col-resize; touch-action: none; }
.split:hover, .split:focus-visible { background: var(--sh); }
.win:not(.channel) .split, .win:not(.channel) .nicklist { display: none; }
.nicklist {
  width: var(--nicklist-w); flex: none; margin: 0; padding: 2px 6px; list-style: none; overflow-y: auto;
  background: var(--bg); border: 2px inset var(--face); font-family: var(--font);
}
.nicklist li { cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 2px; }
.nicklist li:hover { background: var(--sel); color: var(--sel-fg); }
.input input { width: 100%; font: 13px var(--font); padding: 4px 6px; }

/* resize handles: every edge and corner */
.rz { position: absolute; z-index: 2; touch-action: none; }
.rz.n, .rz.s { left: 8px; right: 8px; height: 6px; cursor: ns-resize; }
.rz.e, .rz.w { top: 8px; bottom: 8px; width: 6px; cursor: ew-resize; }
.rz.n { top: -4px; } .rz.s { bottom: -4px; } .rz.e { right: -4px; } .rz.w { left: -4px; }
.rz.ne, .rz.nw, .rz.se, .rz.sw { width: 12px; height: 12px; }
.rz.ne { top: -4px; right: -4px; cursor: nesw-resize; } .rz.sw { bottom: -4px; left: -4px; cursor: nesw-resize; }
.rz.nw { top: -4px; left: -4px; cursor: nwse-resize; } .rz.se { bottom: -4px; right: -4px; cursor: nwse-resize; }
.rz.se::after { /* classic size grip */
  content: ""; position: absolute; right: 5px; bottom: 5px; width: 10px; height: 10px; pointer-events: none;
  background: linear-gradient(135deg, transparent 45%, var(--sh) 45% 55%, transparent 55% 65%, var(--sh) 65% 75%, transparent 75%);
}

/* ---------- log line colors ---------- */
.ts { color: var(--muted); }
.l-join { color: var(--c-join); } .l-part { color: var(--c-part); } .l-quit { color: var(--c-quit); }
.l-notice { color: var(--c-notice); } .l-action { color: var(--c-action); } .l-mode { color: var(--c-mode); }
.l-error { color: var(--c-err); } .l-info, .l-server { color: var(--c-info); } .l-self .nick { color: var(--c-self); }
.l-highlight { background: var(--hl-bg); }
.b { font-weight: bold; } .i { font-style: italic; } .u { text-decoration: underline; text-underline-offset: 2px; }
.log .nick[data-nick] { cursor: pointer; }
.log .nick[data-nick]:hover { text-decoration: underline; }

/* ---------- switchbar ---------- */
#switchbar { display: flex; gap: 2px; padding: 3px; border-top: 1px solid var(--hi); overflow-x: auto; min-height: 31px; }
#switchbar button { max-width: 170px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
#switchbar button.active { border-color: var(--dk) var(--hi) var(--hi) var(--dk); box-shadow: inset 1px 1px 0 var(--sh); font-weight: bold; background: color-mix(in srgb, var(--face) 80%, var(--hi)); }
#switchbar button.unread { color: var(--c-err); }
#switchbar button.highlight { color: var(--c-mode); font-weight: bold; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 12px; bottom: 44px; z-index: 900; display: flex; flex-direction: column; gap: 6px; width: min(380px, calc(100vw - 24px)); }
.toast {
  display: flex; align-items: center; gap: 8px; padding: 8px 6px 8px 10px;
  background: var(--face); border: 2px outset var(--face); box-shadow: 2px 2px 0 var(--dk);
  animation: toast-in .18s cubic-bezier(.16, 1, .3, 1);
}
.toast span { flex: 1; overflow-wrap: anywhere; }
.toast.error span { color: var(--c-err); font-weight: bold; }
.toast .x { padding: 0; width: 20px; justify-content: center; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- dialogs ---------- */
dialog { background: var(--face); color: var(--fg); border: 2px outset var(--face); padding: 0; width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 32px); box-shadow: 2px 2px 0 var(--dk); }
dialog::backdrop { background: rgb(0 0 0 / .25); }
dialog h2, .welcome h1 {
  display: flex; align-items: center; gap: 6px; margin: 0; padding: 4px 8px; font-size: 13px; color: #fff;
  background: linear-gradient(90deg, var(--title), var(--title2));
}
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 36px); }
.dlg-body { overflow-y: auto; padding: 10px 12px 4px; display: flex; flex-direction: column; gap: 8px; }
dialog label, .welcome label { display: flex; flex-direction: column; gap: 3px; }
dialog small { color: var(--muted); font-weight: normal; }
fieldset { margin: 0; padding: 6px 10px 10px; border: 2px groove var(--face); display: flex; flex-direction: column; gap: 7px; }
legend { padding: 0 4px; }
.row { display: flex; gap: 8px; } .grow { flex: 1; min-width: 0; } .port { width: 88px; }
label.chk { flex-direction: row; align-items: center; gap: 6px; }
label.chk input { min-height: 0; margin: 0; }
label.warn { color: var(--c-mode); }
.hint { margin: 0; color: var(--muted); font-size: 12px; }
.buttons { display: flex; justify-content: flex-end; gap: 6px; padding: 8px 12px 10px; }
.buttons button { min-width: 76px; justify-content: center; }

/* ---------- nick context menu ---------- */
.ctxmenu { position: fixed; z-index: 1000; margin: 0; padding: 2px; list-style: none; min-width: 180px; background: var(--face); border: 2px outset var(--face); box-shadow: 2px 2px 0 var(--dk); }
.ctxmenu li { position: relative; }
.ctxmenu button { display: block; width: 100%; text-align: left; border: 0; box-shadow: none; padding: 3px 18px; white-space: nowrap; min-height: 22px; }
.ctxmenu button:hover:not(:disabled), .ctxmenu button:focus-visible { background: var(--title); color: #fff; outline: none !important; }
.ctxmenu .hdr { padding: 3px 8px; font-weight: bold; }
.ctxmenu .hdr.small { font-weight: normal; color: var(--muted); font-size: 11px; padding-top: 0; }
.ctxmenu .sep { height: 0; margin: 3px 2px; border-top: 1px solid var(--sh); border-bottom: 1px solid var(--hi); }
.ctxmenu .sub { display: none; position: absolute; left: 100%; top: -4px; }
.ctxmenu.flip .sub { left: auto; right: 100%; }
.ctxmenu .has-sub:hover > .sub, .ctxmenu .has-sub.open > .sub { display: block; }

/* ---------- login ---------- */
.login-page { align-items: center; justify-content: center; overflow: auto; background: var(--desk); padding: 16px; }
.welcome { width: min(380px, 100%); background: var(--face); border: 2px outset var(--face); box-shadow: 2px 2px 0 var(--dk); }
.hero { display: flex; gap: 12px; align-items: center; padding: 16px 16px 4px; }
.hero p { margin: 0; }
.hero strong { display: block; font-size: 16px; margin-bottom: 2px; }
.welcome form { display: flex; flex-direction: column; gap: 10px; padding: 10px 16px 0; }
.welcome .buttons { padding: 0 0 14px; }
.err { color: var(--c-err); min-height: 1.35em; margin: 0; font-weight: bold; }

/* ---------- small screens ---------- */
@media (max-width: 700px) {
  .mobile-only { display: inline-flex; }
  #btn-tile, #btn-cascade, .logo { display: none; }
  .menubar button { min-height: 36px; }
  #treebar { position: absolute; z-index: 50; top: 43px; bottom: 37px; left: 0; display: none; box-shadow: 2px 0 0 var(--dk); }
  #treebar.open { display: block; }
  #tree li > span { padding: 8px 10px; }
  .win { inset: 0 !important; width: auto !important; height: auto !important; min-width: 0; }
  .rz, .split { display: none; }
  .titlebar button { width: 30px; height: 26px; }
  .nicklist { width: 96px; }
  .toasts { bottom: 48px; right: 8px; }
}
