*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --primary: #007aff;
  --primary-dark: #0062cc;
  --danger: #ff3b30;
  --text: #1c1c1e;
  --text-secondary: #6e6e73;
  --border: #d1d1d6;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
}

body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); height: 100dvh; overflow: hidden; }

.page { height: 100dvh; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* Auth */
.auth-box { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 40px 36px; width: 360px; margin: auto; margin-top: 15vh; }
.auth-box h1 { font-size: 28px; font-weight: 700; text-align: center; }
.subtitle { text-align: center; color: var(--text-secondary); margin: 6px 0 24px; font-size: 14px; }
.tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tab { flex: 1; padding: 8px; border: none; background: var(--bg); border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--text-secondary); transition: all .15s; }
.tab.active { background: var(--primary); color: #fff; font-weight: 600; }
.auth-box input { width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; margin-bottom: 12px; outline: none; transition: border-color .15s; }
.auth-box input:focus { border-color: var(--primary); }
.auth-box button[type=submit] { width: 100%; padding: 12px; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; transition: background .15s; }
.auth-box button[type=submit]:hover { background: var(--primary-dark); }

/* Header */
header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 24px; height: 56px; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.header-left { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--text-secondary); }
.logo { font-size: 20px; font-weight: 700; color: var(--primary); }
.btn-back { background: none; border: 1px solid #34c759; border-radius: 8px; font-size: 14px; cursor: pointer; padding: 6px 12px; color: #34c759; font-weight: 600; transition: background .15s; }
.btn-back:hover { background: #e8f8ed; }
.salon-title { font-size: 17px; font-weight: 600; }
.member-count { font-size: 13px; color: var(--text-secondary); }

/* Buttons */
.btn-primary { background: var(--primary); color: #fff; border: none; border-radius: 8px; padding: 8px 16px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background .15s; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 7px 14px; font-size: 14px; cursor: pointer; color: var(--text); transition: background .15s; }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: none; border: 1px solid var(--danger); border-radius: 8px; padding: 7px 14px; font-size: 14px; cursor: pointer; color: var(--danger); transition: background .15s; }
.btn-danger:hover { background: #fff0ef; }

/* Join By Name */
.join-by-name { display: flex; gap: 8px; margin-bottom: 20px; }
.join-by-name input { flex: 1; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; outline: none; }
.join-by-name input:focus { border-color: var(--primary); }

/* Salon List */
.salons-main { flex: 1; overflow-y: auto; padding: 24px; max-width: 800px; width: 100%; margin: 0 auto; }
.salons-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.salons-toolbar h2 { font-size: 20px; font-weight: 700; }
.salon-list { display: flex; flex-direction: column; gap: 12px; }
.salon-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.salon-info { flex: 1; min-width: 0; }
.salon-name { font-size: 16px; font-weight: 600; }
.unread-badge { background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 6px; min-width: 18px; display: inline-block; text-align: center; vertical-align: middle; margin-left: 6px; line-height: 18px; }
.unread-dot { background: var(--danger); width: 8px; height: 8px; border-radius: 50%; display: inline-block; vertical-align: middle; margin-left: 6px; }
.at-badge { background: var(--danger); color: #fff; font-size: 10px; font-weight: 600; border-radius: 4px; padding: 1px 5px; display: inline-block; vertical-align: middle; margin-left: 4px; }
.salon-desc { font-size: 13px; color: var(--text-secondary); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.salon-meta { font-size: 12px; color: var(--text-secondary); margin-top: 6px; }
.salon-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* Chat */
.chat-messages { flex: 1; overflow-y: auto; padding: 16px 12px; display: flex; flex-direction: column; gap: 12px; background: var(--bg); }
.chat-input-bar { background: var(--surface); border-top: 1px solid var(--border); padding: 8px 12px; display: flex; align-items: center; justify-content: space-evenly; gap: 8px; flex-shrink: 0; }
.chat-input-bar textarea { width: 100%; box-sizing: border-box; padding: 10px 12px; border: 1px solid var(--border); border-radius: 14px; font-size: 16px; outline: none; transition: border-color .15s; height: 44px; resize: none; font-family: inherit; line-height: 1.5; }
.chat-input-bar .btn-primary { padding: 10px 12px; font-size: 14px; white-space: nowrap; }
.chat-input-bar textarea:focus { border-color: var(--primary); }
.input-wrapper { flex: 2; display: flex; position: relative; }
.at-list { position: absolute; bottom: 44px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; max-height: 160px; overflow-y: auto; box-shadow: 0 -2px 12px rgba(0,0,0,.08); z-index: 10; }
.at-item { padding: 8px 14px; cursor: pointer; font-size: 14px; border-bottom: 1px solid var(--bg); }
.at-item:last-child { border-bottom: none; }
.at-item:hover { background: var(--bg); }
.at-item .at-username { font-weight: 600; }
.mention { color: var(--primary); font-weight: 600; }
.msg-row.self .bubble .mention { color: #fff; text-decoration: underline; }
.msg-row.at-me .bubble { background: #fff3cd; }
.msg-row.at-me .avatar { background: #ff9800; }
.upload-btn { font-size: 20px; cursor: pointer; padding: 2px 4px; border-radius: 6px; transition: background .15s; user-select: none; }
.upload-btn:hover { background: var(--bg); }
.emoji-wrapper { position: relative; }
.emoji-btn { background: none; border: none; font-size: 20px; cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.emoji-btn:hover { background: var(--bg); }
.emoji-panel { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); width: 280px; max-width: 90vw; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px; display: flex; flex-wrap: wrap; gap: 4px; box-shadow: 0 4px 16px rgba(0,0,0,.15); z-index: 100; max-height: 200px; overflow-y: auto; }
.emoji-item { font-size: 22px; cursor: pointer; padding: 4px; border-radius: 4px; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
.emoji-item:hover { background: var(--bg); }

/* Messages */
.msg-row { display: flex; gap: 10px; align-items: flex-start; }
.msg-row.self { flex-direction: row-reverse; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; flex-shrink: 0; }
.msg-body { max-width: 65%; }
.msg-meta { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.msg-row.self .msg-meta { text-align: right; }
.bubble { background: var(--surface); border-radius: 12px; padding: 10px 14px; font-size: 15px; line-height: 1.5; box-shadow: var(--shadow); word-break: break-word; }
.msg-row.self .bubble { background: var(--primary); color: #fff; }
.bubble img { max-width: 240px; max-height: 240px; border-radius: 8px; display: block; cursor: pointer; }
.bubble video { max-width: 280px; border-radius: 8px; display: block; }
.file-link { display: flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; }
.file-link .file-icon { font-size: 24px; }
.msg-row.self .file-link { color: #fff; }
.system-msg { text-align: center; font-size: 12px; color: var(--text-secondary); padding: 4px 0; }
.time-sep { text-align: center; font-size: 11px; color: var(--text-secondary); padding: 12px 0; }

/* Requests Panel */
.requests-panel { background: var(--surface); border-top: 1px solid var(--border); padding: 12px 24px; max-height: 200px; overflow-y: auto; }
.requests-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.requests-header h4 { font-size: 14px; font-weight: 600; }
.requests-list { display: flex; flex-direction: column; gap: 8px; }
.request-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--bg); border-radius: 8px; }
.request-body { flex: 1; }
.request-username { font-size: 14px; font-weight: 500; }
.request-history { display: flex; gap: 12px; margin-top: 4px; font-size: 12px; color: var(--text-secondary); }
.history-label { display: inline-flex; align-items: center; gap: 2px; cursor: pointer; }
.days-input { border: 1px solid var(--border); border-radius: 4px; padding: 1px 4px; font-size: 12px; text-align: center; }
.request-actions { display: flex; gap: 8px; flex-shrink: 0; }
.invite-section { margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--bg); }
.invite-row { display: flex; gap: 8px; margin-bottom: 6px; }
.invite-row input { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none; }
.invite-row input:focus { border-color: var(--primary); }
.invite-row button { font-size: 13px; }
.members-sublist-header { font-size: 13px; font-weight: 600; margin: 12px 0 6px; color: var(--text-secondary); }
.member-tag { display: inline-block; background: var(--primary); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 10px; margin: 0 4px 4px 0; }

/* Error */
.error-msg { background: #fff0ef; color: var(--danger); border-radius: 8px; padding: 10px 14px; font-size: 14px; margin-bottom: 12px; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 28px; width: 400px; box-shadow: 0 8px 32px rgba(0,0,0,.18); }
.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 20px; }
.modal input, .modal textarea { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; margin-bottom: 12px; outline: none; font-family: inherit; resize: vertical; }
.modal input:focus, .modal textarea:focus { border-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.delete-btn { background: var(--danger); color: #fff; border: none; border-radius: 4px; cursor: pointer; font-size: 12px; margin-left: 6px; padding: 2px 8px; vertical-align: middle; }
.delete-btn:hover { opacity: 0.8; }
.quote-btn { background: none; color: var(--text-secondary); border: none; cursor: pointer; font-size: 12px; margin-left: 6px; padding: 2px 4px; vertical-align: middle; display: none; }
.msg-row:hover .quote-btn { display: inline; }
.quote-btn:hover { color: var(--primary); }

/* Quote / Reply */
.quote-bar { display: flex; align-items: center; gap: 8px; background: var(--bg); border-top: 1px solid var(--border); padding: 6px 24px; font-size: 13px; }
.quote-bar-text { flex: 1; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-bar-text b { color: var(--text); }
.quote-bar-close { background: none; border: none; cursor: pointer; color: var(--text-secondary); font-size: 13px; padding: 2px 6px; }
.quote-bar-close:hover { color: var(--danger); }
.reply-quote { font-size: 12px; color: var(--text-secondary); background: var(--bg); border-left: 3px solid var(--primary); border-radius: 4px; padding: 4px 8px; margin-bottom: 6px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.msg-row.self .reply-quote { background: rgba(255,255,255,.18); border-left-color: #fff; color: #f0f0f0; }
.msg-row.flash .bubble { animation: flash-highlight 1.5s ease; }
@keyframes flash-highlight { 0%, 60% { box-shadow: 0 0 0 3px rgba(24,144,255,.4); } 100% { box-shadow: var(--shadow); } }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
