/* iOS 6 Safari — no flexbox/grid; float + absolute layout */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Helvetica Neue", Helvetica, "Apple SD Gothic Neo", "AppleGothic", Arial, sans-serif;
  font-size: 14px;
  color: #191919;
  background: #b2c7d9;
  -webkit-text-size-adjust: 100%;
}

* { -webkit-tap-highlight-color: rgba(0,0,0,0); }

.screen {
  position: absolute;
  left: 0; right: 0; top: 0; bottom: 0;
  overflow: hidden;
}

/* Login */
#screen-login { background: #fee500; }
.login-wrap {
  width: 86%;
  max-width: 320px;
  margin: 80px auto 0;
  text-align: center;
}
.login-logo {
  font-size: 28px;
  font-weight: bold;
  color: #3c1e1e;
}
.login-sub { font-size: 12px; color: #666; margin: 6px 0 24px; }
.field { text-align: left; margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: #555; margin-bottom: 4px; }
.field input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 16px; /* prevent iOS zoom */
}
.btn-primary {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  border: none;
  border-radius: 4px;
  background: #191919;
  color: #fee500;
  font-size: 16px;
  font-weight: bold;
}
.btn-small {
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 3px;
  background: #fff;
  font-size: 12px;
}
.err { color: #c00; font-size: 12px; margin-top: 10px; min-height: 16px; }
.login-hint { margin-top: 20px; font-size: 11px; color: #666; line-height: 1.4; }

/* Top / tabs */
.topbar {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 44px;
  background: #fee500;
  border-bottom: 1px solid #e6ce00;
  z-index: 5;
}
.topbar-title {
  text-align: center;
  line-height: 44px;
  font-weight: bold;
  font-size: 16px;
  margin: 0 64px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
#chat-title { cursor: pointer; }
.topbar-btn {
  position: absolute;
  left: 8px; top: 7px;
  height: 30px;
  padding: 0 10px;
  border: none;
  background: transparent;
  font-size: 15px;
  font-weight: bold;
  color: #191919;
  z-index: 2;
  cursor: pointer;
}
#btn-chat-back {
  font-size: 18px;
  line-height: 28px;
  padding: 0 8px;
}
#btn-logout,
.topbar-btn-right { left: auto; right: 8px; }
.topbar-btn-select { left: auto; right: 58px; font-size: 13px; }
#screen-chat.no-profile .topbar-btn-select { right: 8px; }
#screen-chat #chat-topbar-normal .topbar-title { margin: 0 100px 0 44px; }
#screen-chat.no-profile #chat-topbar-normal .topbar-title { margin: 0 64px 0 44px; }
#screen-chat #chat-topbar-select .topbar-title { margin: 0 76px; }
.topbar-btn-spacer { display: none; }

/* Avatars */
.avatar {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: #ddd url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48"><rect fill="%23e8e8e8" width="48" height="48"/><circle cx="24" cy="18" r="9" fill="%23bbb"/><ellipse cx="24" cy="42" rx="16" ry="12" fill="%23bbb"/></svg>') center center no-repeat;
  background-size: cover;
  overflow: hidden;
}
.avatar img {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
}

.me-card {
  padding: 14px;
  border-bottom: 8px solid #f0f0f0;
  background: #fff;
  cursor: pointer;
}
.me-avatar {
  float: left;
  width: 56px;
  height: 56px;
  border-radius: 16px;
}
.me-meta {
  margin-left: 70px;
  padding-top: 8px;
}
.me-meta .name { font-size: 16px; font-weight: bold; }
.me-meta .sub {
  font-size: 12px;
  color: #888;
  margin-top: 4px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.section-label {
  padding: 8px 14px 4px;
  font-size: 11px;
  color: #999;
  background: #fafafa;
  border-bottom: 1px solid #eee;
}
.list li .avatar {
  float: left;
  margin-right: 12px;
  width: 44px;
  height: 44px;
}
.list li .li-body { margin-left: 56px; }
.list li:after {
  content: "";
  display: block;
  clear: both;
  height: 0;
}

/* Profile screen */
#screen-profile { background: #b2c7d9; }
.profile-body {
  position: absolute;
  left: 0; right: 0;
  top: 44px; bottom: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.profile-hero {
  text-align: center;
  padding: 36px 20px 24px;
  background: #b2c7d9;
}
.profile-avatar {
  width: 96px;
  height: 96px;
  border-radius: 28px;
  margin: 0 auto 16px;
  border: 2px solid rgba(255,255,255,0.6);
}
.profile-nick {
  font-size: 22px;
  font-weight: bold;
  color: #191919;
}
.profile-phone {
  font-size: 13px;
  color: #555;
  margin-top: 6px;
}
.profile-status {
  font-size: 13px;
  color: #333;
  margin-top: 10px;
  padding: 0 16px;
  line-height: 1.4;
}
.profile-actions {
  padding: 16px;
  text-align: center;
}
.profile-actions .btn-primary {
  display: inline-block;
  width: auto;
  min-width: 160px;
  padding: 12px 24px;
}
.profile-edit-form {
  margin: 0 16px 24px;
  padding: 14px;
  background: #fff;
  border-radius: 8px;
}

.tabbar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 49px;
  background: #f7f7f7;
  border-top: 1px solid #ccc;
  z-index: 5;
}
.tab {
  float: left;
  width: 50%;
  height: 49px;
  border: none;
  background: transparent;
  font-size: 12px;
  color: #888;
}
.tab.active { color: #191919; font-weight: bold; }

.pane {
  position: absolute;
  left: 0; right: 0;
  top: 44px; bottom: 49px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
}
.toolbar {
  padding: 8px;
  border-bottom: 1px solid #eee;
  background: #fafafa;
}
.toolbar .btn-small { margin-right: 6px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  padding: 12px 14px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
}
.list li .name { font-weight: bold; }
.list li .sub { font-size: 12px; color: #888; margin-top: 3px; }
.list li .badge {
  float: right;
  background: #fa3e3e;
  color: #fff;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 10px;
  margin-top: 2px;
}

/* Chat */
#screen-chat { background: #b2c7d9; }
.chat-scroll {
  position: absolute;
  left: 0; right: 0;
  top: 44px; bottom: 52px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 8px;
}
.reply-bar {
  position: absolute;
  left: 0; right: 0;
  top: 44px;
  height: 36px;
  background: #fff8c4;
  border-bottom: 1px solid #e6ce00;
  z-index: 4;
}
.reply-bar-text {
  margin: 0 36px 0 10px;
  line-height: 36px;
  font-size: 12px;
  color: #555;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.btn-x {
  position: absolute;
  right: 4px; top: 4px;
  width: 28px; height: 28px;
  border: none;
  background: transparent;
  font-size: 20px;
}
#screen-chat.has-reply .chat-scroll { top: 80px; }

.composer {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 52px;
  background: #f5f5f5;
  border-top: 1px solid #ccc;
}
.btn-attach {
  display: block;
  position: absolute;
  left: 6px; top: 11px;
  width: 30px; height: 30px;
  border: 1px solid #bbb;
  border-radius: 4px;
  background: #fff;
  font-size: 18px;
  line-height: 28px;
  padding: 0;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}
.btn-attach .attach-input,
.btn-change-photo-label .attach-input {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  opacity: 0;
  filter: alpha(opacity=0);
  cursor: pointer;
  font-size: 80px;
  z-index: 2;
}
.btn-change-photo-label {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  position: relative;
  overflow: hidden;
  text-align: center;
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  cursor: pointer;
}
#chat-input {
  position: absolute;
  left: 42px; right: 70px;
  top: 10px;
  height: 32px;
  line-height: 20px;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 5px 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "AppleGothic", Arial, sans-serif;
  font-size: 16px;
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
}
.btn-send {
  position: absolute;
  right: 6px; top: 11px;
  width: 58px; height: 30px;
  border: none;
  border-radius: 4px;
  background: #fee500;
  font-weight: bold;
  font-size: 13px;
}
.upload-bar {
  position: absolute;
  left: 0; right: 0;
  bottom: 52px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  font-size: 11px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  z-index: 3;
}
#screen-chat.uploading .chat-scroll { bottom: 76px; }

/* Drag and Drop File Overlay */
#screen-chat.file-drop-active::after {
  content: '파일을 여기에 놓으면 전송됩니다';
  position: absolute;
  top: 44px;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 99;
  background: rgba(254, 229, 0, 0.78);
  border: 3px dashed #3a1d1d;
  color: #3a1d1d;
  font-size: 16px;
  font-weight: bold;
  text-align: center;
  padding-top: 140px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  pointer-events: none;
}

/* Selection Mode */
.chat-select-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 52px;
  background: #f7f7f8;
  border-top: 1px solid #c8c7cc;
  z-index: 10;
  text-align: center;
  line-height: 52px;
  box-sizing: border-box;
}
.select-bar-btn {
  display: inline-block;
  width: 45%;
  height: 38px;
  line-height: 38px;
  margin: 7px 2%;
  border: 1px solid #d0d0d5;
  border-radius: 6px;
  background: #ffffff;
  font-size: 14px;
  font-weight: bold;
  color: #333;
  text-align: center;
  cursor: pointer;
  vertical-align: middle;
  box-sizing: border-box;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}
.select-bar-btn:active {
  background: #e8e8ed;
}
.select-bar-btn[disabled] {
  opacity: 0.38;
  cursor: default;
}
.select-bar-btn.btn-danger {
  color: #d93025;
  border-color: #f2c0bc;
}
.select-bar-btn.btn-danger:active {
  background: #fce8e6;
}
.select-bar-btn .icon {
  margin-right: 4px;
  font-size: 14px;
  vertical-align: middle;
}

#screen-chat.select-mode .composer {
  display: none !important;
}
#screen-chat.select-mode #reply-bar {
  display: none !important;
}
#screen-chat.select-mode .chat-select-bar {
  display: block !important;
}
#screen-chat.select-mode #chat-topbar-normal {
  display: none !important;
}
#screen-chat.select-mode #chat-topbar-select {
  display: block !important;
}
#screen-chat.select-mode .chat-scroll {
  bottom: 52px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
#screen-chat.select-mode .msg-row {
  position: relative;
  padding-left: 36px;
  cursor: pointer;
  border-radius: 6px;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
#screen-chat.select-mode .bubble {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
#screen-chat.select-mode .msg-row:hover {
  background: rgba(255, 255, 255, 0.22);
}
#screen-chat.select-mode .msg-row.selected {
  background: rgba(254, 229, 0, 0.3);
}

.msg-select-check {
  display: none;
  position: absolute;
  left: 6px;
  top: 50%;
  margin-top: -11px;
  width: 22px;
  height: 22px;
  line-height: 18px;
  border-radius: 50%;
  border: 2px solid #a8b6c4;
  background: #ffffff;
  color: transparent;
  text-align: center;
  font-size: 13px;
  font-weight: bold;
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
}
#screen-chat.select-mode .msg-select-check {
  display: block;
}
#screen-chat.select-mode .msg-row.selected .msg-select-check {
  background: #fee500;
  border-color: #e5cc00;
  color: #111;
}

/* Toast */
.ui-toast {
  position: fixed;
  left: 50%;
  bottom: 68px;
  margin-left: -130px;
  width: 260px;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.85);
  color: #ffffff;
  font-size: 13px;
  text-align: center;
  border-radius: 20px;
  z-index: 9999;
  opacity: 0;
  -webkit-transition: opacity 0.2s ease-in-out;
  transition: opacity 0.2s ease-in-out;
  pointer-events: none;
  box-sizing: border-box;
}
.ui-toast.ui-toast-show {
  opacity: 1;
}

/* Bubbles */
.msg-row { margin: 8px 0; clear: both; }
.msg-row.own { text-align: right; }
.msg-nick { font-size: 11px; color: #555; margin: 0 8px 2px; }
.bubble {
  display: inline-block;
  max-width: 72%;
  padding: 8px 10px;
  border-radius: 4px;
  background: #fff;
  text-align: left;
  word-wrap: break-word;
  vertical-align: bottom;
  cursor: pointer;
}
.msg-row.own .bubble { background: #fee500; }
.bubble .meta {
  font-size: 10px;
  color: #888;
  margin-top: 4px;
}
.bubble .reply-quote {
  font-size: 11px;
  color: #666;
  border-left: 2px solid #aaa;
  padding-left: 6px;
  margin-bottom: 4px;
}
.bubble img.chat-img {
  max-width: 180px;
  max-height: 180px;
  display: block;
  cursor: pointer;
}
.bubble img.chat-img:hover {
  opacity: 0.92;
}
.file-card {
  min-width: 120px;
  cursor: pointer;
  padding: 2px 0;
  -webkit-user-drag: none;
  user-drag: none;
}
.file-card a {
  color: #06c;
  display: inline-block;
  margin-top: 3px;
  text-decoration: underline;
  -webkit-user-drag: none;
  user-drag: none;
}
.file-card:hover a {
  color: #004499;
}
.date-sep {
  text-align: center;
  margin: 12px 0;
}
.date-sep span {
  display: inline-block;
  background: rgba(0,0,0,0.25);
  color: #fff;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 10px;
}
.sys-msg {
  text-align: center;
  font-size: 11px;
  color: #555;
  margin: 8px 0;
}

/* Modal */
.modal-overlay {
  position: absolute;
  left: 0; right: 0; top: 0; bottom: 0;
  background: rgba(0,0,0,0.45);
  z-index: 50;
}
.modal {
  position: absolute;
  left: 10%; right: 10%;
  top: 20%;
  background: #fff;
  border-radius: 6px;
  padding: 14px;
}
.modal-title { font-weight: bold; margin-bottom: 10px; }
.modal input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 4px;
}
.modal-actions { margin-top: 12px; text-align: right; }
.modal-actions button { margin-left: 6px; }

.action-sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: #fff;
  z-index: 60;
  border-top: 1px solid #ccc;
}
.action-sheet button {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-bottom: 1px solid #eee;
  background: #fff;
  font-size: 15px;
  text-align: center;
}
.action-sheet button.danger { color: #c00; }

/* Paste image modal */
.paste-image-modal {
  max-width: 360px;
  margin: 0 auto;
  box-sizing: border-box;
}
.paste-image-hint {
  font-size: 12px;
  color: #666;
  margin-bottom: 10px;
}
.paste-image-preview {
  max-height: 220px;
  overflow-y: auto;
  text-align: center;
  background: #f8f8f8;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 8px;
  margin-bottom: 8px;
  box-sizing: border-box;
}
.paste-image-item {
  margin-bottom: 6px;
}
.paste-image-item:last-child {
  margin-bottom: 0;
}
.paste-image-item img {
  max-width: 100%;
  max-height: 160px;
  display: block;
  margin: 0 auto 4px;
  border-radius: 4px;
  border: 1px solid #ddd;
  background: #fff;
}
.paste-image-meta {
  font-size: 11px;
  color: #888;
  word-break: break-all;
}

/* Image viewer modal */
.image-viewer-overlay {
  position: absolute;
  left: 0; right: 0; top: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 100;
  text-align: center;
  overflow: hidden;
}
.image-viewer-bar {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 44px;
  background: rgba(0, 0, 0, 0.65);
  z-index: 102;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}
.image-viewer-title {
  text-align: center;
  line-height: 44px;
  font-size: 15px;
  font-weight: bold;
  color: #fff;
  margin: 0 120px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.image-viewer-btn {
  position: absolute;
  left: 8px; top: 7px;
  height: 30px;
  min-width: 30px;
  padding: 0 10px;
  line-height: 30px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 16px;
  text-decoration: none;
  cursor: pointer;
  box-sizing: border-box;
}
.image-viewer-btn-copy {
  left: auto;
  right: 68px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  text-align: center;
}
.image-viewer-btn-right {
  left: auto;
  right: 8px;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  text-align: center;
}
.image-viewer-body {
  position: absolute;
  left: 0; right: 0;
  top: 44px; bottom: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  text-align: center;
  white-space: nowrap;
}
.image-viewer-body:before {
  content: "";
  display: inline-block;
  height: 100%;
  vertical-align: middle;
  margin-right: -0.25em;
}
.image-viewer-img {
  display: inline-block;
  vertical-align: middle;
  max-width: 95%;
  max-height: 95%;
  border-radius: 2px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.6);
  cursor: pointer;
}

/* PC / Desktop Version Support */
@media screen and (min-width: 600px) {
  body {
    background: #8aa4be;
  }
  .screen,
  #screen-chat,
  #screen-main,
  #screen-login,
  #screen-profile {
    left: 50% !important;
    right: auto !important;
    width: 440px !important;
    margin-left: -220px !important;
    box-shadow: 0 4px 24px rgba(0,0,0,0.25);
    border-left: 1px solid rgba(0,0,0,0.1);
    border-right: 1px solid rgba(0,0,0,0.1);
  }
  .modal-overlay,
  .action-sheet {
    left: 50% !important;
    right: auto !important;
    width: 440px !important;
    margin-left: -220px !important;
  }
  .image-viewer-overlay {
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    margin-left: 0 !important;
    z-index: 1000;
  }
  .image-viewer-img {
    max-width: 90vw;
    max-height: 85vh;
  }
  .btn-primary:hover,
  .btn-send:hover {
    opacity: 0.92;
    cursor: pointer;
  }
  .btn-small:hover,
  .btn-attach:hover {
    background: #eee;
    cursor: pointer;
  }
  .topbar-btn:hover {
    opacity: 0.8;
    cursor: pointer;
  }
  .list li:hover {
    background: #f7f7f7;
  }
  .tab:hover {
    background: #efefef;
    cursor: pointer;
  }
}
