/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242836;
  --border: #2e3345;
  --text: #e4e6ed;
  --text-muted: #8b8fa3;
  --primary: #6c63ff;
  --primary-hover: #5a52e0;
  --green: #34d399;
  --me-bubble: #6c63ff;
  --other-bubble: #242836;
  --radius: 12px;
  --radius-sm: 8px;
}

html,
body {
  height: 100%;
  font-family: "Helvetica Neue", "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

/* ===== Lobby ===== */
.lobby-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  padding-top: calc(24px + var(--sat));
  padding-bottom: calc(24px + var(--sab));
}

.lobby-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px;
  max-width: 420px;
  width: 100%;
}

.logo {
  text-align: center;
  margin-bottom: 28px;
}

.logo-icon {
  font-size: 48px;
  display: block;
  margin-bottom: 8px;
}

.logo h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

/* Tabs */
.tab-group {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 24px;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.tab.active {
  background: var(--primary);
  color: #fff;
}

/* Forms */
.form {
  display: none;
}

.form.active {
  display: block;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  transition: border 0.2s;
}

.field input:focus {
  border-color: var(--primary);
}

.field input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

/* Buttons */
.btn {
  display: block;
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover {
  background: var(--primary-hover);
}

.btn.outline {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.btn.outline:hover {
  border-color: var(--text-muted);
}

.btn.small {
  padding: 8px 16px;
  font-size: 13px;
}

.error {
  color: #f87171;
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
}

.hidden {
  display: none !important;
}

/* ===== Chat Layout ===== */
.chat-layout {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 20px 18px 12px;
  padding-top: calc(20px + var(--sat));
  font-weight: 700;
  font-size: 15px;
}

.logo-icon-sm {
  font-size: 22px;
}

.room-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px 16px;
  border-bottom: 1px solid var(--border);
}

.room-code-label {
  font-size: 11px;
  color: var(--text-muted);
}

.room-code {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 1px;
}

.btn-copy {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.btn-copy:hover {
  opacity: 1;
}

.member-section {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
}

.member-section h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.member-section ul {
  list-style: none;
}

.member-section li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
}

.member-section li.me {
  font-weight: 600;
}

.member-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 18px;
  padding-bottom: calc(16px + var(--sab));
  border-top: 1px solid var(--border);
}

/* Main chat */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  padding-top: calc(14px + var(--sat));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.chat-header h2 {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
}

.header-members {
  font-size: 13px;
  color: var(--text-muted);
}

.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text);
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.welcome-message {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.welcome-message p {
  background: var(--surface);
  padding: 16px 24px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  max-width: 400px;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}

.message.me {
  align-self: flex-end;
  align-items: flex-end;
}

.message.other {
  align-self: flex-start;
  align-items: flex-start;
}

.message-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 3px;
  padding: 0 4px;
}

.message.me .message-sender {
  display: none;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
  display: inline-flex;
  align-items: flex-end;
  gap: 8px;
}

.message.me .message-bubble {
  background: var(--me-bubble);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.message.other .message-bubble {
  background: var(--other-bubble);
  border-bottom-left-radius: 6px;
}

.message-time {
  font-size: 10px;
  opacity: 0.5;
  white-space: nowrap;
  flex-shrink: 0;
}

.system-message {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 0;
}

/* Typing indicator */
.typing-indicator {
  padding: 4px 20px 8px;
  font-size: 13px;
  color: var(--text-muted);
}

/* Message form */
.message-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--sab));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.message-form input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 12px 18px;
  font-size: 15px;
  outline: none;
  transition: border 0.2s;
}

.message-form input:focus {
  border-color: var(--primary);
}

.message-form input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}

.btn-send:hover {
  background: var(--primary-hover);
}

/* ===== Mobile ===== */
@media (max-width: 640px) {
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: left 0.25s ease;
    box-shadow: none;
  }

  .sidebar.open {
    left: 0;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }

  .hamburger {
    display: block;
  }

  .message {
    max-width: 88%;
  }

  .lobby-card {
    padding: 28px 20px;
  }
}

/* ===== AIrffic ID（共通ログイン・任意） ===== */
.airffic-login {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 20px;
  min-width: 0;
}

.airffic-login > div {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.airffic-login .btn {
  max-width: 100%;
}

.airffic-login-title {
  font-size: 13px;
  color: var(--text-muted);
}

.airffic-email {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.airffic-email input {
  flex: 1 1 180px;
  width: 0;
  min-width: 0;
  padding: 10px 12px;
  font-size: 15px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border 0.2s;
}

.airffic-email input:focus {
  border-color: var(--primary);
}

.airffic-email input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.airffic-email .btn {
  flex: 1 0 auto;
  width: auto;
  white-space: nowrap;
}

#airffic-signed-in .btn {
  align-self: flex-start;
  width: auto;
}

.airffic-login-note {
  font-size: 12px;
  color: var(--text-muted);
}

.airffic-id {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--green);
  border: 1px solid var(--green);
  border-radius: 4px;
  padding: 0 4px;
  margin-left: 4px;
  vertical-align: middle;
}

.field input[readonly] {
  opacity: 0.75;
}
