/* iseekyou — retro chunky chrome.
   Original styling inspired by late-90s desktop OS look. No third-party assets. */

:root {
  --bg-desktop: #008080;
  --gray-0: #ffffff;
  --gray-1: #dfdfdf;
  --gray-2: #c0c0c0;
  --gray-3: #808080;
  --gray-4: #404040;
  --gray-5: #000000;
  --accent: #000080;
  --accent-2: #1084d0;
  --text: #000000;
  --link: #0000a0;
  --danger: #b00000;
  --ok: #008000;
  --font-ui: "Tahoma", "Geneva", "MS Sans Serif", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Consolas", "Lucida Console", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-desktop);
  font: 12px/1.35 var(--font-ui);
  color: var(--text);
  overflow: hidden;
  user-select: none;
}

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

.hidden { display: none !important; }
.spacer { flex: 1; }
.row { display: flex; gap: 6px; align-items: center; }
.err { color: var(--danger); font-size: 11px; }
.hint { font-size: 11px; color: var(--gray-4); margin-top: 8px; }

/* --- screens --- */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
#app-screen { align-items: flex-start; justify-content: flex-start; }

/* --- window chrome (chunky bevel) --- */
.window {
  background: var(--gray-2);
  border: 2px solid;
  border-color: var(--gray-0) var(--gray-4) var(--gray-4) var(--gray-0);
  box-shadow: 1px 1px 0 var(--gray-5);
  padding: 2px;
  display: flex; flex-direction: column;
  min-width: 260px;
}
.window--login { width: min(380px, 100%); }
.window--main  { width: min(320px, 100%); height: min(620px, 92vh); }
.window--modal {
  position: fixed; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, 92vw); max-height: 80vh;
  z-index: 100;
}
.window--chat {
  position: absolute;
  width: min(380px, 92vw); height: min(440px, 80vh);
  display: flex; flex-direction: column;
  z-index: 10;
}

.title-bar {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff;
  padding: 3px 4px;
  display: flex; align-items: center; gap: 6px;
  font-weight: bold;
  cursor: default;
}
.title-bar-text { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.title-bar-text > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-icon { width: 16px; height: 16px; }
.title-bar-controls { display: flex; gap: 2px; }
.title-bar-controls button {
  width: 18px; height: 16px;
  background: var(--gray-2);
  border: 1px solid;
  border-color: var(--gray-0) var(--gray-4) var(--gray-4) var(--gray-0);
  color: var(--gray-5);
  font: bold 10px var(--font-ui);
  line-height: 14px; padding: 0;
  cursor: pointer;
}
.title-bar-controls button:active {
  border-color: var(--gray-4) var(--gray-0) var(--gray-0) var(--gray-4);
}

.window-body {
  padding: 8px;
  background: var(--gray-2);
  flex: 1; overflow: auto;
}
.status-bar {
  border-top: 1px solid var(--gray-3);
  padding: 2px 6px;
  display: flex; gap: 8px;
  font-size: 11px; color: var(--gray-4);
  background: var(--gray-2);
}

/* --- inputs --- */
.window-body input[type="text"],
.window-body input:not([type]),
.window-body input[type="email"],
.window-body input[type="password"],
.window-body input[type="search"],
.window-body textarea,
.window-body select {
  background: #fff;
  border: 2px solid;
  border-color: var(--gray-4) var(--gray-0) var(--gray-0) var(--gray-4);
  padding: 3px 4px;
  outline: none;
  width: 100%;
}
.window-body label {
  display: block; margin-bottom: 6px;
  font-size: 11px; color: var(--gray-4);
}
.window-body label input { margin-top: 2px; }

.btn {
  background: var(--gray-2);
  border: 2px solid;
  border-color: var(--gray-0) var(--gray-4) var(--gray-4) var(--gray-0);
  padding: 3px 12px;
  cursor: pointer;
  min-width: 70px;
}
.btn:active { border-color: var(--gray-4) var(--gray-0) var(--gray-0) var(--gray-4); padding: 4px 11px 2px 13px; }
.btn-primary { font-weight: bold; }
.btn:disabled { color: var(--gray-3); cursor: not-allowed; }

/* --- tabs (login) --- */
.tabs { display: flex; gap: 2px; margin-bottom: 8px; border-bottom: 1px solid var(--gray-4); }
.tab {
  background: var(--gray-2);
  border: 1px solid;
  border-color: var(--gray-0) var(--gray-4) transparent var(--gray-0);
  padding: 4px 10px; cursor: pointer; font-weight: normal;
}
.tab.is-active { font-weight: bold; background: var(--gray-1); }

.auth-form { display: none; }
.auth-form.is-active { display: block; }

/* --- toolbar / contact list --- */
.toolbar { display: flex; gap: 4px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 100px; }
.toolbar select { width: auto; }

.contact-list {
  flex: 1;
  background: #fff;
  border: 2px solid;
  border-color: var(--gray-4) var(--gray-0) var(--gray-0) var(--gray-4);
  overflow-y: auto;
  padding: 2px 0;
  min-height: 200px;
}
.contact-group { padding: 2px 6px; font-weight: bold; color: var(--gray-4); background: var(--gray-1); }
.contact {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 6px; cursor: pointer;
}
.contact:hover { background: var(--accent); color: #fff; }
.contact img { width: 14px; height: 14px; flex-shrink: 0; }
.contact .nick { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact .uin  { font-size: 10px; color: var(--gray-3); }
.contact:hover .uin { color: var(--gray-1); }
.contact.has-unread { font-weight: bold; }
.contact.has-unread .nick::after { content: " ✉"; color: var(--danger); }

/* --- chat window --- */
.chat-log {
  flex: 1;
  background: #fff;
  border: 2px solid;
  border-color: var(--gray-4) var(--gray-0) var(--gray-0) var(--gray-4);
  padding: 6px;
  overflow-y: auto;
  font-size: 12px;
}
.msg { margin-bottom: 6px; }
.msg .who { font-weight: bold; }
.msg.me .who { color: var(--accent); }
.msg.them .who { color: var(--danger); }
.msg .time { color: var(--gray-3); font-size: 10px; margin-left: 6px; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; }
.msg img.gif,
.msg img.chat-image {
  max-width: 240px; max-height: 240px;
  display: block; margin-top: 2px;
  border: 1px solid var(--gray-4);
  background: #fff;
}
.msg img.chat-image { cursor: zoom-in; }
.msg .read-tick { color: var(--ok); font-size: 10px; margin-left: 4px; }
.typing-indicator { color: var(--gray-3); font-style: italic; font-size: 11px; padding: 0 6px 4px; min-height: 14px; }

.composer {
  display: flex; gap: 4px; align-items: stretch;
  margin-top: 6px;
}
.composer textarea {
  flex: 1; resize: none; height: 50px; min-height: 50px;
  font: 12px var(--font-ui);
}
.composer .icon-btn { width: 28px; min-width: 0; padding: 2px; }

/* --- nudge (Stupsen) shake animation --- */
@keyframes iseekyou-shake {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-8px, 2px) rotate(-1deg); }
  30% { transform: translate(8px, -2px) rotate(1deg); }
  45% { transform: translate(-6px, 3px) rotate(-0.5deg); }
  60% { transform: translate(6px, -1px) rotate(0.5deg); }
  75% { transform: translate(-3px, 1px); }
  90% { transform: translate(3px, 0); }
}
.window--chat.shake { animation: iseekyou-shake 0.55s ease-in-out; }

/* --- giphy modal --- */
.giphy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px;
  margin-top: 8px;
  max-height: 60vh;
  overflow-y: auto;
  background: #fff;
  padding: 6px;
  border: 2px solid;
  border-color: var(--gray-4) var(--gray-0) var(--gray-0) var(--gray-4);
}
.giphy-grid img {
  width: 100%; height: 110px; object-fit: cover; cursor: pointer;
  border: 1px solid var(--gray-4);
}
.giphy-grid img:hover { outline: 2px solid var(--accent); }

/* --- emoji picker --- */
.emoji-picker {
  position: fixed; z-index: 200;
  width: 260px; max-height: 220px; overflow-y: auto;
  background: var(--gray-2);
  border: 2px solid;
  border-color: var(--gray-0) var(--gray-4) var(--gray-4) var(--gray-0);
  padding: 6px;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
}
.emoji-picker button {
  background: transparent; border: none; cursor: pointer;
  font-size: 18px; line-height: 1; padding: 2px;
}
.emoji-picker button:hover { background: var(--accent); color: #fff; }

/* --- mobile / touch tweaks ---
   Mobile users need bigger touch targets, taller inputs, and a chat composer
   that's actually usable with a thumb. Keep all the retro chrome — just
   inflate the bits you tap. */
@media (max-width: 640px) {
  body { font-size: 14px; }
  #app-screen, #login-screen { padding: 0; }

  /* Main window fills the viewport — including the dynamic-height fix for
     iOS Safari's collapsing bottom toolbar. */
  .window--main {
    width: 100%;
    height: 100dvh;
    border: none;
    box-shadow: none;
  }
  .window--login {
    width: 100%;
    min-height: 100dvh;
    border: none;
    box-shadow: none;
    display: flex; flex-direction: column;
  }
  .window--login .window-body { flex: 1; }

  /* Chat windows go full-screen, ignoring whatever inline position was set. */
  .window--chat {
    position: fixed !important;
    left: 0 !important; top: 0 !important;
    width: 100%; height: 100dvh;
    z-index: 50;
    border: none;
    box-shadow: none;
  }

  /* Title bars: 40px touch targets for close/min/max. */
  .title-bar { padding: 8px 8px; min-height: 44px; }
  .title-bar-controls button {
    width: 36px; height: 32px;
    font-size: 16px; line-height: 28px;
  }

  /* Toolbar: bigger inputs, comfortable spacing, items wrap cleanly. */
  .toolbar { gap: 6px; padding: 4px 0; }
  .toolbar > * { min-height: 40px; }
  .toolbar select, .toolbar input { font-size: 14px; padding: 8px 6px; }
  .toolbar .btn { padding: 8px 10px; min-width: 44px; }
  #contact-search { flex: 1 1 100%; order: 99; } /* push search to its own row */

  /* Buttons: 44px minimum target. */
  .btn {
    padding: 10px 14px;
    min-height: 44px;
    min-width: 56px;
    touch-action: manipulation;
  }
  .btn:active { padding: 11px 13px 9px 15px; }
  .btn.icon-btn { min-width: 44px; padding: 8px; }

  /* Login form fields: taller. */
  .window-body input[type="text"],
  .window-body input:not([type]),
  .window-body input[type="email"],
  .window-body input[type="password"],
  .window-body input[type="search"],
  .window-body textarea,
  .window-body select {
    padding: 10px 8px;
    font-size: 16px; /* prevents iOS auto-zoom on focus */
  }

  /* Tabs: tappable. */
  .tab { padding: 10px 14px; }

  /* Contact list: chunkier rows. */
  .contact-list { min-height: auto; }
  .contact { padding: 10px 12px; gap: 10px; }
  .contact img { width: 18px; height: 18px; }
  .contact .uin { font-size: 11px; }
  .contact-group { padding: 6px 12px; font-size: 12px; }

  /* Auth-request inline buttons inside contact rows. */
  .contact .btn { min-height: 36px; min-width: 56px; padding: 6px 10px; }

  /* Chat composer: taller text area + bigger send. */
  .composer { gap: 6px; padding: 6px 0; }
  .composer textarea {
    height: 72px; min-height: 72px;
    font-size: 16px; padding: 8px;
  }
  .composer .icon-btn { width: 44px; height: 44px; }
  .composer .js-send { min-width: 72px; }

  /* Chat log: roomier message bubbles. */
  .chat-log { padding: 10px; font-size: 14px; }
  .msg { margin-bottom: 10px; }
  .msg .time { font-size: 11px; }
  .msg img.gif { max-width: 100%; max-height: 280px; }

  /* Modals fill viewport on mobile. */
  .window--modal,
  .auth-popup, .profile-dialog, .theme-dialog {
    position: fixed !important;
    left: 0 !important; top: 0 !important;
    transform: none !important;
    width: 100%; height: 100dvh;
    max-height: 100dvh;
    border: none;
    box-shadow: none;
    display: flex; flex-direction: column;
  }
  .window--modal .window-body,
  .auth-popup .window-body,
  .profile-dialog .window-body,
  .theme-dialog .window-body { flex: 1; overflow-y: auto; }

  /* Emoji picker: wider, scrollable. */
  .emoji-picker {
    left: 6px !important; right: 6px;
    width: auto;
    max-height: 240px;
    grid-template-columns: repeat(7, 1fr);
  }
  .emoji-picker button { font-size: 22px; padding: 6px; min-height: 36px; }

  /* GIPHY thumbnails grow on small screens. */
  .giphy-grid { grid-template-columns: repeat(2, 1fr); }
  .giphy-grid img { height: 140px; }

  /* Context menu (right-click → long-press fallback) should be touch-friendly
     if it ever fires on mobile. */
  .contact-menu .cm-item { padding: 12px 16px !important; font-size: 14px; }
}

/* iOS Safari: respect the home-indicator safe area. */
@supports (padding: max(0px)) {
  @media (max-width: 640px) {
    .window--main, .window--chat, .window--login,
    .window--modal, .auth-popup, .profile-dialog, .theme-dialog {
      padding-bottom: env(safe-area-inset-bottom);
    }
  }
}

/* When app is installed (standalone PWA), drop the desktop padding */
@media (display-mode: standalone) {
  body { background: var(--gray-2); }
  #app-screen { padding: 0; }
  .window--main { box-shadow: none; }
}

/* --- PWA install banner --- */
.install-banner {
  position: fixed;
  left: 8px; right: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 9000;
  background: var(--gray-2);
  border: 2px solid;
  border-color: var(--gray-0) var(--gray-4) var(--gray-4) var(--gray-0);
  box-shadow: 1px 1px 0 var(--gray-5);
  padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13px;
}
.install-banner .ib-text { flex: 1; }
.install-banner .ib-text strong { display: block; margin-bottom: 2px; }
.install-banner button {
  background: var(--gray-2);
  border: 2px solid;
  border-color: var(--gray-0) var(--gray-4) var(--gray-4) var(--gray-0);
  padding: 8px 12px; cursor: pointer; min-height: 36px;
}
.install-banner button:active { border-color: var(--gray-4) var(--gray-0) var(--gray-0) var(--gray-4); }
.install-banner .ib-primary { font-weight: bold; }
