:root {
  --primary: #007AFF;
  --success: #34C759;
  --warning: #FF9500;
  --danger: #FF3B30;
  --purple: #AF52DE;
  --gray1: #8E8E93;
  --gray2: #AEAEB2;
  --gray3: #C7C7CC;
  --gray4: #D1D1D6;
  --gray5: #E5E5EA;
  --gray6: #F2F2F7;
  --surface: #FFFFFF;
  --text: #000000;
  --text2: #3C3C43;
  --text3: #8E8E93;
  --sidebar-w: 256px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  background: var(--gray6);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ── Auth ── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(145deg, #1c1c3a 0%, #2d1b69 50%, #1a3a5c 100%);
}

.auth-container {
  background: var(--surface);
  border-radius: 22px;
  padding: 40px 36px;
  width: 420px;
  max-width: 92vw;
  box-shadow: 0 32px 80px rgba(0,0,0,.45);
}

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

.logo-icon {
  width: 72px; height: 72px;
  background: linear-gradient(135deg, #007AFF 0%, #34C759 100%);
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; color: white; font-weight: 800;
  margin: 0 auto 14px;
  box-shadow: 0 8px 24px rgba(0,122,255,.35);
}

.app-logo h1 { font-size: 22px; font-weight: 700; }
.app-logo p  { color: var(--text3); font-size: 13px; margin-top: 3px; }

.auth-form { display: none; }
.auth-form.active { display: block; }
.auth-form h2 { font-size: 18px; font-weight: 700; margin-bottom: 18px; text-align: center; }

.form-group { margin-bottom: 10px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text3); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .4px; }

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%; padding: 11px 13px;
  border: 1.5px solid var(--gray4);
  border-radius: 10px;
  font-size: 15px; font-family: inherit;
  background: var(--surface); color: var(--text);
  transition: border-color .18s; outline: none;
  resize: vertical;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus { border-color: var(--primary); }

.error-msg { color: var(--danger); font-size: 13px; min-height: 20px; margin-bottom: 4px; }

.btn-primary {
  width: 100%; padding: 13px;
  background: var(--primary); color: white;
  border: none; border-radius: 11px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: opacity .18s;
}
.btn-primary:hover { opacity: .85; }
.btn-primary:active { opacity: .7; }

.btn-secondary {
  padding: 10px 20px;
  background: var(--gray5); color: var(--text);
  border: none; border-radius: 10px;
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: opacity .18s;
}
.btn-secondary:hover { opacity: .8; }

.auth-switch { text-align: center; margin-top: 14px; font-size: 13px; color: var(--text3); }
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: 600; }

/* ── Layout ── */
#main-app { display: flex; height: 100vh; }
.hidden { display: none !important; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: rgba(242,242,247,.97);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--gray4);
  display: flex; flex-direction: column;
  overflow-y: auto; flex-shrink: 0;
}

.sidebar-header {
  padding: 18px 14px 16px;
  display: flex; align-items: center; gap: 9px;
  border-bottom: 1px solid var(--gray4);
}

.user-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800; color: white; flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-nickname { display: block; font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-uname    { display: block; font-size: 11px; color: var(--text3); }

.btn-icon {
  background: none; border: none; font-size: 17px;
  cursor: pointer; color: var(--text3); padding: 5px;
  border-radius: 7px; transition: all .18s; line-height: 1;
}
.btn-icon:hover         { background: var(--gray4); color: var(--primary); }
.btn-icon:last-of-type:hover { color: var(--danger); }

.sidebar-section { padding: 14px 8px 6px; }
.sidebar-section h3 {
  font-size: 11px; font-weight: 700; color: var(--text3);
  text-transform: uppercase; letter-spacing: .6px;
  padding: 0 8px; margin-bottom: 5px;
}

.filter-list, #user-list { list-style: none; }

.filter-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; border-radius: 10px;
  cursor: pointer; font-size: 13.5px; font-weight: 500;
  transition: background .14s; user-select: none;
}
.filter-item:hover  { background: var(--gray4); }
.filter-item.active { background: white; box-shadow: 0 1px 4px rgba(0,0,0,.1); }

.fi {
  width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: white; flex-shrink: 0;
}

.badge {
  margin-left: auto;
  background: var(--gray4); color: var(--text2);
  font-size: 11.5px; font-weight: 700;
  padding: 2px 7px; border-radius: 9px; min-width: 22px; text-align: center;
}

.user-list-item {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 9px; border-radius: 8px;
  font-size: 12.5px; color: var(--text2);
}
.mini-av {
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800; color: white; flex-shrink: 0;
}
.me-tag { font-size: 11px; color: var(--primary); font-weight: 600; margin-left: auto; }

/* ── Main ── */
.main-content {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}

.content-header {
  padding: 18px 24px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--gray4);
  background: var(--surface);
}
.content-header h2 { font-size: 22px; font-weight: 800; }

.btn-add {
  padding: 8px 16px;
  background: var(--primary); color: white;
  border: none; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: opacity .18s;
}
.btn-add:hover { opacity: .85; }

.messages-container { flex: 1; overflow-y: auto; padding: 14px 20px; }

/* ── Message Card ── */
.msg-card {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 13px 14px;
  background: var(--surface);
  border-radius: 13px;
  margin-bottom: 7px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  transition: opacity .3s;
  animation: slideIn .25s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-card.done { opacity: .5; }
.msg-card.done .msg-text { text-decoration: line-through; color: var(--text3); }

/* Circle checkbox */
.chk {
  width: 23px; height: 23px; border-radius: 50%;
  border: 2px solid var(--gray3);
  background: none; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: transparent; margin-top: 2px;
  transition: all .22s;
}
.chk:hover { border-color: var(--success); background: rgba(52,199,89,.1); color: var(--success); }
.chk.done  { background: var(--success); border-color: var(--success); color: white; }

/* Priority dot */
.pdot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-top: 8px; }
.p0 { background: transparent; }
.p1 { background: var(--gray2); }
.p2 { background: var(--warning); }
.p3 { background: var(--danger); }

.msg-body { flex: 1; min-width: 0; }
.msg-text  { font-size: 14.5px; line-height: 1.55; word-break: break-word; color: var(--text); }

.msg-meta {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 6px; margin-top: 5px;
}
.msg-author { font-size: 12px; color: var(--text3); }

.tag {
  font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 6px; white-space: nowrap;
}
.tag-assign { background: rgba(0,122,255,.1);  color: var(--primary); }
.tag-done   { background: rgba(52,199,89,.12); color: #1a8a3a; }
.tag-high   { background: rgba(255,59,48,.1);  color: var(--danger); }
.tag-med    { background: rgba(255,149,0,.1);  color: var(--warning); }

.msg-time { font-size: 11px; color: var(--text3); margin-left: auto; white-space: nowrap; }

.msg-del {
  width: 26px; height: 26px; border-radius: 8px; border: none;
  background: none; cursor: pointer; color: var(--gray3); font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: all .18s; flex-shrink: 0;
}
.msg-card:hover .msg-del { opacity: 1; }
.msg-del:hover { background: rgba(255,59,48,.1); color: var(--danger); }

/* Section divider */
.section-title {
  font-size: 11px; font-weight: 700; color: var(--text3);
  text-transform: uppercase; letter-spacing: .5px;
  padding: 10px 4px 5px; margin-top: 4px;
}

/* Empty state */
.empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 64px 24px; color: var(--text3); text-align: center;
}
.empty-icon { font-size: 56px; opacity: .45; margin-bottom: 14px; }
.empty h3   { font-size: 17px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }
.empty p    { font-size: 13px; }

.loading { text-align: center; padding: 48px; color: var(--text3); }

/* ── Modal ── */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.modal-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.42); backdrop-filter: blur(5px);
}
.modal-box {
  position: relative;
  background: var(--surface); border-radius: 18px;
  width: 460px; max-width: 92vw;
  box-shadow: 0 24px 64px rgba(0,0,0,.3);
  animation: popIn .26s ease;
}
@keyframes popIn {
  from { opacity: 0; transform: scale(.94) translateY(10px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}
.modal-header {
  padding: 20px 20px 0;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 17px; font-weight: 700; }
.btn-close {
  width: 28px; height: 28px; border-radius: 50%;
  border: none; background: var(--gray5);
  cursor: pointer; font-size: 13px; color: var(--text3);
  display: flex; align-items: center; justify-content: center;
  transition: background .18s;
}
.btn-close:hover { background: var(--gray4); }
.modal-body   { padding: 16px 20px; }
.modal-footer { padding: 0 20px 18px; display: flex; justify-content: flex-end; gap: 9px; }

.priority-row { display: flex; gap: 7px; }
.pri-btn {
  flex: 1; padding: 8px 4px;
  border: 1.5px solid var(--gray4); border-radius: 8px;
  background: none; cursor: pointer;
  font-size: 12.5px; font-weight: 600; color: var(--text3);
  transition: all .18s;
}
.pri-btn:hover  { border-color: var(--primary); color: var(--primary); }
.pri-btn.active { background: var(--primary); border-color: var(--primary); color: white; }

/* ── Admin Panel ── */
.admin-stats {
  display: flex; gap: 10px; margin-bottom: 14px;
}
.admin-stat-card {
  flex: 1; background: var(--gray6); border-radius: 10px;
  padding: 10px 14px; text-align: center;
}
.admin-stat-card .num  { font-size: 22px; font-weight: 700; color: var(--text); }
.admin-stat-card .lbl  { font-size: 11px; color: var(--text3); margin-top: 2px; }

.admin-user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 4px;
  border-bottom: 0.5px solid var(--gray5);
}
.admin-user-row:last-child { border-bottom: none; }

.admin-av {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: white;
}
.admin-user-info { flex: 1; min-width: 0; }
.admin-user-info .name {
  font-size: 14px; font-weight: 600; color: var(--text);
}
.admin-user-info .sub  { font-size: 11px; color: var(--text3); margin-top: 1px; }

.badge-admin {
  font-size: 10px; font-weight: 700; padding: 2px 8px;
  border-radius: 5px; background: rgba(0,122,255,.1); color: var(--primary);
  white-space: nowrap;
}
.badge-you {
  font-size: 10px; font-weight: 700; padding: 2px 8px;
  border-radius: 5px; background: var(--gray5); color: var(--text3);
}

.admin-actions { display: flex; gap: 6px; flex-shrink: 0; }

.btn-toggle-admin {
  padding: 5px 10px; border-radius: 7px; cursor: pointer;
  font-size: 11px; font-weight: 600; transition: all .18s;
  border: 1.5px solid var(--gray3); background: none; color: var(--text3);
}
.btn-toggle-admin:hover:not(:disabled) {
  border-color: var(--primary); color: var(--primary);
}
.btn-toggle-admin.is-admin {
  border-color: var(--primary); color: var(--primary);
  background: rgba(0,122,255,.08);
}
.btn-toggle-admin.is-admin:hover:not(:disabled) {
  background: rgba(0,122,255,.18);
}

.btn-del-user {
  padding: 5px 10px; border-radius: 7px; cursor: pointer;
  font-size: 11px; font-weight: 600; transition: all .18s;
  border: 1.5px solid var(--gray3); background: none; color: var(--text3);
}
.btn-del-user:hover:not(:disabled) {
  border-color: var(--danger); color: var(--danger);
  background: rgba(255,59,48,.06);
}

.btn-toggle-admin:disabled,
.btn-del-user:disabled { opacity: .35; cursor: not-allowed; }

.admin-empty { text-align: center; padding: 28px; color: var(--text3); font-size: 13px; }

/* ── Sidebar Footer ── */
.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--gray4);
}

.ext-download-link {
  display: block;
  padding: 8px 10px;
  font-size: 12px; font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  border-radius: 8px;
  transition: background .18s;
  text-align: center;
}
.ext-download-link:hover { background: rgba(0,122,255,.08); }

/* ── Admin Create Form ── */
.admin-create {
  margin-bottom: 14px;
  border: 1.5px solid var(--gray4);
  border-radius: 11px;
  overflow: hidden;
}

.btn-create-toggle {
  width: 100%; padding: 10px 14px;
  background: none; border: none;
  font-size: 13px; font-weight: 600;
  color: var(--primary); cursor: pointer;
  text-align: left; transition: background .18s;
}
.btn-create-toggle:hover { background: rgba(0,122,255,.05); }

.create-form {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--gray4);
  display: flex; flex-direction: column; gap: 8px;
}

.create-fields { display: flex; flex-direction: column; gap: 7px; }

.create-fields input {
  width: 100%; padding: 9px 11px;
  border: 1.5px solid var(--gray4); border-radius: 9px;
  font-size: 13.5px; font-family: inherit;
  background: var(--surface); color: var(--text);
  outline: none; transition: border-color .18s;
}
.create-fields input:focus { border-color: var(--primary); }

.create-btns { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Profile Modal ── */
.prof-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 14px 0 10px;
}
.prof-divider span {
  font-size: 11px; font-weight: 700; color: var(--text3);
  text-transform: uppercase; letter-spacing: .4px; white-space: nowrap;
}
.prof-divider::before,
.prof-divider::after { content: ''; flex: 1; border-top: 1px solid var(--gray5); }

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