:root {
  --bg: #0b1020;
  --surface: #131a2e;
  --surface-2: #1b2440;
  --border: rgba(148, 163, 184, 0.16);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --good: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Segoe UI", sans-serif;
}

/* Skin 2: Chat Focus */
html[data-skin="chat"] {
  --bg: #111827;
  --surface: #1f2937;
  --surface-2: #283548;
  --accent: #38bdf8;
}

/* Skin 3: Retro 90s Windows/Terminal */
html[data-skin="retro"] {
  --bg: #008080;
  --surface: #c0c0c0;
  --surface-2: #dfdfdf;
  --border: #808080;
  --text: #111111;
  --text-muted: #333333;
  --accent: #000080;
  --accent-2: #0000a8;
  --good: #008000;
  --warn: #a85500;
  --danger: #a80000;
  --radius: 0px;
  --font: "Courier New", "DungGeunMo", monospace;
}

/* Skin 4: 3D Office */
html[data-skin="office3d"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #293548;
  --accent: #8b5cf6;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Lock Screen */
.lock-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, rgba(99, 102, 241, 0.22), transparent 60%), var(--bg);
}

.lock-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.lock-icon { font-size: 44px; margin-bottom: 10px; }
.lock-card h1 { margin: 0 0 8px; font-size: 22px; }
.lock-sub { margin: 0 0 20px; font-size: 14px; color: var(--text-muted); line-height: 1.5; }
.lock-form { display: flex; flex-direction: column; gap: 10px; }
.lock-form input {
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  text-align: center;
}
.lock-form button, .primary-btn {
  padding: 13px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.lock-error { min-height: 20px; color: var(--danger); font-size: 13px; margin: 10px 0 0; }
.lock-hint { font-size: 12px; color: var(--text-muted); margin: 8px 0 0; }

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

html[data-skin="retro"] .topbar,
html[data-skin="retro"] .dash-card,
html[data-skin="retro"] .sidebar,
html[data-skin="retro"] .modal-box {
  border: 2px outset #ffffff;
  box-shadow: none;
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; }
.brand { display: flex; align-items: center; gap: 9px; }
.brand-logo { font-size: 24px; }
.brand-title { font-size: 15px; font-weight: 700; }
.brand-sub { font-size: 11px; color: var(--good); }

.skin-switcher {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.skin-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 5px 8px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.skin-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 6px 9px;
  cursor: pointer;
  font-size: 15px;
}

/* 3D Office Stage */
.office3d-stage {
  display: none;
  background: linear-gradient(180deg, #0b132b, #16203c);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  flex-shrink: 0;
}
html[data-skin="office3d"] .office3d-stage { display: block; }

.office3d-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: #cbd5e1;
  margin-bottom: 10px;
}

.pill {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 600;
}

.office3d-floor {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  perspective: 900px;
}

.desk-3d {
  background: linear-gradient(145deg, #1e293b, #283548);
  border: 1px solid rgba(139, 92, 246, 0.35);
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
  transform: rotateX(8deg);
  transition: transform 0.2s ease, border-color 0.2s ease;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
}

.desk-3d:hover, .desk-3d.active {
  transform: rotateX(0deg) translateY(-3px);
  border-color: #a78bfa;
}

.desk-3d-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.desk-3d-avatar { font-size: 24px; }
.desk-3d-room { font-size: 13px; font-weight: 700; }
.desk-3d-role { font-size: 11px; color: #94a3b8; margin-top: 2px; }

/* Workspace Grid */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 240px 1fr 310px;
}

html[data-skin="chat"] .dashboard-pane { display: none; }
html[data-skin="chat"] .workspace { grid-template-columns: 240px 1fr; }

.sidebar, .dashboard-pane {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
}

.dashboard-pane {
  border-right: none;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.side-section { margin-bottom: 18px; }
.side-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.mini-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 7px;
  width: 24px;
  height: 24px;
  cursor: pointer;
}

.room-item, .agent-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 4px;
  font-size: 13px;
}

.room-item:hover, .agent-item:hover { background: var(--surface-2); }
.room-item.active { background: var(--accent); color: #fff; font-weight: 600; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); margin-left: auto; }

/* Center Chat */
.center-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.room-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.room-header h2 { margin: 0; font-size: 16px; }
.room-desc { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }
.room-actions { display: flex; align-items: center; gap: 8px; }
.hop-meter {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.hop-meter.blocked { background: rgba(239, 68, 68, 0.2); color: var(--danger); border-color: var(--danger); }

.chip-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}

.mention-bar {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.mention-chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}

.message-feed {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.5;
}
.msg.boss {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}
.msg.system {
  align-self: center;
  max-width: 95%;
  font-size: 12px;
  background: var(--surface-2);
  color: var(--text-muted);
  text-align: center;
}
.msg-meta { display: flex; justify-content: space-between; gap: 10px; font-size: 11px; opacity: 0.8; margin-bottom: 4px; }
.msg-img { max-width: 100%; border-radius: 10px; margin-top: 8px; display: block; }
.msg-file {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  color: inherit;
  font-size: 12px;
  text-decoration: none;
}

.attach-preview {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 14px;
  background: var(--surface-2);
  font-size: 12px;
  border-top: 1px solid var(--border);
}

.chat-composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
}

.chat-composer input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 14px;
}

.send-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 0 16px;
  font-weight: 700;
  cursor: pointer;
}

/* Dashboard Cards */
.dash-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.dash-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dash-header h3 { margin: 0; font-size: 14px; }

.inline-form { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.inline-form input {
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
}
.inline-form button {
  padding: 7px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.dash-list, .quota-list { display: flex; flex-direction: column; gap: 7px; }
.dash-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  padding: 7px 9px;
  background: var(--surface);
  border-radius: 9px;
  border: 1px solid var(--border);
}
.dash-row.done { opacity: 0.55; text-decoration: line-through; }
.dash-row-left { display: flex; align-items: center; gap: 7px; min-width: 0; }
.dday-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(245, 158, 11, 0.2);
  color: var(--warn);
  white-space: nowrap;
}
.dday-badge.urgent { background: rgba(239, 68, 68, 0.22); color: var(--danger); }

.quota-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 12px;
}
.quota-top { display: flex; justify-content: space-between; margin-bottom: 5px; font-weight: 600; }
.progress-track { height: 7px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--good); transition: width 0.3s ease; }
.progress-fill.warn { background: var(--warn); }
.progress-fill.danger { background: var(--danger); }
.quota-sub { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}
.modal-box {
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.close-modal { border: none; background: transparent; color: var(--text); font-size: 18px; cursor: pointer; }
.setting-block { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; font-size: 13px; }
.setting-block input {
  padding: 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.divider { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.small-muted { font-size: 12px; color: var(--text-muted); margin: 4px 0 10px; }
.token-row {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px;
  margin-bottom: 8px;
  font-size: 12px;
}
.token-code {
  display: block;
  font-family: monospace;
  font-size: 11px;
  word-break: break-all;
  margin: 5px 0;
  color: #a5b4fc;
}

.mobile-only { display: none; }

@media (max-width: 900px) {
  .mobile-only { display: flex; }
  .skin-btn span { display: none; }
  .workspace { display: block; position: relative; }
  .sidebar, .center-pane, .dashboard-pane {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
  }
  .sidebar, .dashboard-pane { display: none; }
  .app-shell[data-mobile-tab="rooms"] .sidebar { display: block; }
  .app-shell[data-mobile-tab="rooms"] .center-pane { display: none; }
  .app-shell[data-mobile-tab="dash"] .dashboard-pane { display: flex; }
  .app-shell[data-mobile-tab="dash"] .center-pane { display: none; }

  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mnav-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    padding: 10px 4px;
    font-size: 13px;
    font-weight: 600;
  }
  .mnav-btn.active { color: var(--accent); }
}
