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

:root {
  --bg: #f0f4fb;
  --surface: #ffffff;
  --surface2: #e8eef8;
  --border: #d0d9ee;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 8px;
  --shadow: 0 1px 4px #1e293b14;
}

body { background: var(--bg); color: var(--text); font-family: 'Segoe UI', system-ui, sans-serif; min-height: 100vh; }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; }
.login-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 2.5rem; width: 100%; max-width: 400px; margin: 2rem;
  box-shadow: 0 4px 24px #2563eb18;
}
.login-box h1 { text-align: center; margin-bottom: 2rem; font-size: 1.4rem; color: var(--accent); }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.4rem; font-weight: 500; }
.form-group input {
  width: 100%; padding: 0.65rem 0.9rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.95rem; outline: none; transition: border-color .2s, box-shadow .2s;
}
.form-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #2563eb18; }

button { cursor: pointer; border: none; border-radius: var(--radius); font-size: 0.9rem; transition: background .15s, box-shadow .15s, opacity .15s; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
#loginBtn { width: 100%; padding: 0.75rem; background: var(--accent); color: #fff; font-size: 1rem; margin-top: 0.5rem; font-weight: 600; }
#loginBtn:hover:not(:disabled) { background: var(--accent-hover); box-shadow: 0 2px 8px #2563eb44; }

.error-msg { color: var(--red); font-size: 0.85rem; margin: 0.5rem 0; }
.hidden { display: none !important; }

/* Dashboard */
.dashboard { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem; position: sticky; top: 0; z-index: 10;
  box-shadow: var(--shadow);
}
.topbar .title { font-weight: 700; font-size: 1.05rem; color: var(--accent); }
.topbar .user-info { display: flex; align-items: center; gap: 1rem; font-size: 0.85rem; color: var(--text-muted); }
.topbar .user-info .name { color: var(--text); font-weight: 500; }
.badge { padding: 0.2rem 0.6rem; border-radius: 99px; font-size: 0.75rem; font-weight: 600; }
.badge-manager { background: #ede9fe; color: #6d28d9; }
.badge-member  { background: #e0f2fe; color: #0369a1; }
.badge-admin   { background: #fef3c7; color: #b45309; }
.logout-btn { padding: 0.4rem 0.9rem; background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.logout-btn:hover { border-color: var(--red); color: var(--red); }

.main { display: flex; flex: 1; }

/* Status dot */
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; transition: background .3s; }
.dot-active   { background: var(--green); box-shadow: 0 0 6px #16a34a66; }
.dot-inactive { background: #cbd5e1; }

/* Content */
.content { flex: 1; padding: 1.5rem; overflow-y: auto; background: var(--bg); }
.section { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; margin-bottom: 1.25rem; box-shadow: var(--shadow); }
.section h2 { font-size: 0.82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 1rem; font-weight: 600; }

/* Session toggle */
.session-card { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; }
.session-status { display: flex; align-items: center; gap: 0.75rem; }
.session-status .dot { width: 12px; height: 12px; }
.session-label { font-size: 1rem; font-weight: 500; }
.toggle-btn { padding: 0.55rem 1.4rem; background: var(--accent); color: #fff; font-weight: 600; }
.toggle-btn:hover:not(:disabled) { background: var(--accent-hover); box-shadow: 0 2px 8px #2563eb44; }
.toggle-btn.stop { background: #fee2e2; border: 1px solid #fca5a5; color: var(--red); font-weight: 600; }
.toggle-btn.stop:hover:not(:disabled) { background: #fecaca; }

/* Auth request */
.auth-form { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.auth-form input {
  flex: 1; min-width: 200px; padding: 0.6rem 0.9rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); outline: none; font-size: 0.9rem;
  transition: border-color .2s, box-shadow .2s;
}
.auth-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #2563eb18; }
.auth-form button { padding: 0.6rem 1.2rem; background: var(--accent); color: #fff; font-weight: 500; }
.auth-form button:hover:not(:disabled) { background: var(--accent-hover); }
.auth-result { margin-top: 1rem; padding: 0.9rem 1.1rem; background: #dcfce7; border: 1px solid #86efac; border-radius: var(--radius); font-size: 0.9rem; }
.auth-result .code { font-family: monospace; font-size: 1.1rem; color: #15803d; font-weight: 700; letter-spacing: .05em; }

/* Manager table */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th { text-align: left; padding: 0.6rem 0.75rem; color: var(--text-muted); border-bottom: 2px solid var(--border); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
.data-table td { padding: 0.75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }
.url-cell { max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.url-cell a { color: var(--accent); text-decoration: none; }
.url-cell a:hover { text-decoration: underline; }
.code-input-row { display: flex; gap: 0.5rem; align-items: center; }
.code-input-row input {
  flex: 1; padding: 0.45rem 0.7rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.85rem; outline: none;
  transition: border-color .2s;
}
.code-input-row input:focus { border-color: var(--accent); }
.code-input-row button { padding: 0.45rem 0.9rem; background: var(--green); color: #fff; font-size: 0.85rem; font-weight: 500; }
.code-input-row button:hover:not(:disabled) { background: #15803d; }
.delete-btn { padding: 0.35rem 0.65rem; background: transparent; border: 1px solid var(--border); color: var(--text-muted); font-size: 0.8rem; }
.delete-btn:hover { border-color: var(--red); color: var(--red); background: #fee2e2; }
.edit-btn { padding: 0.35rem 0.65rem; background: transparent; border: 1px solid var(--border); color: var(--text-muted); font-size: 0.8rem; }
.edit-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); background: var(--surface2); }
.code-set { font-family: monospace; color: #15803d; font-weight: 600; }
.empty-msg { color: var(--text-muted); font-size: 0.9rem; text-align: center; padding: 1.5rem 0; }

/* Change password button */
.change-pwd-btn {
  padding: 0.4rem 0.9rem; background: transparent;
  border: 1px solid var(--border); color: var(--text-muted); font-size: 0.85rem;
}
.change-pwd-btn:hover { border-color: var(--accent); color: var(--accent); background: #eff6ff; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: #1e293b55;
  display: flex; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 2rem; width: 100%; max-width: 380px; margin: 1rem;
  box-shadow: 0 8px 32px #1e293b22;
}
.modal h3 { margin-bottom: 1.25rem; font-size: 1.05rem; color: var(--text); font-weight: 700; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.25rem; }
.modal-cancel { padding: 0.55rem 1.1rem; background: var(--surface2); border: 1px solid var(--border); color: var(--text-muted); }
.modal-cancel:hover { border-color: var(--red); color: var(--red); background: #fee2e2; }
.modal-submit { padding: 0.55rem 1.2rem; background: var(--accent); color: #fff; font-weight: 600; }
.modal-submit:hover:not(:disabled) { background: var(--accent-hover); }

/* Topic group header in admin view */
.topic-group-header {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-muted); padding: 0.75rem 0 0.4rem;
  border-top: 1px solid var(--border); margin-top: 0.5rem; font-weight: 600;
}
.topic-group-header:first-of-type { margin-top: 0; border-top: none; padding-top: 0; }

/* Admin resource section */
.resource-section { margin-bottom: 1.5rem; }
.resource-header {
  display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1rem;
  padding-bottom: 0.75rem; border-bottom: 1px solid var(--border);
}
.resource-title { display: flex; align-items: center; gap: 0.6rem; }
.resource-id-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 7px;
  background: var(--accent); color: #fff; font-size: 0.9rem; font-weight: 700; flex-shrink: 0;
}
.resource-name { font-size: 1.05rem; font-weight: 700; }
.resource-manager-label { font-size: 0.8rem; color: var(--text-muted); }

.subsection-label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); margin-bottom: 0.6rem; font-weight: 600;
}

/* Admin compact member row */
.admin-member-list { display: flex; flex-direction: column; gap: 0.3rem; }
.admin-member-row {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: nowrap;
  padding: 0.4rem 0.65rem; border-radius: var(--radius);
  background: var(--surface2); border: 1px solid var(--border);
  font-size: 0.83rem; min-width: 0;
}
.admin-member-row .amr-name {
  font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 6rem; flex-shrink: 0;
}
.admin-member-row .amr-status { color: var(--text-muted); font-size: 0.78rem; flex-shrink: 0; }
.admin-member-row .row-actions { display: flex; gap: 0.3rem; flex-shrink: 0; margin-left: auto; }

.section-header-row { display: flex; align-items: center; justify-content: space-between; }
.topic-badge {
  display: inline-block; padding: 0.1rem 0.4rem; border-radius: 4px;
  background: #eff6ff; border: 1px solid #bfdbfe;
  font-size: 0.68rem; color: #1d4ed8; vertical-align: middle; font-weight: 500;
}
.mgr-tag {
  display: inline-block; padding: 0.1rem 0.35rem; border-radius: 4px;
  background: #ede9fe; color: #6d28d9; font-size: 0.68rem; vertical-align: middle; font-weight: 600;
}

/* Assign manager button */
.assign-btn {
  padding: 0.3rem 0.65rem; background: #eff6ff;
  border: 1px solid #bfdbfe; color: var(--accent);
  font-size: 0.75rem; white-space: nowrap; flex-shrink: 0; font-weight: 500;
}
.assign-btn:hover:not(:disabled) { background: var(--accent); color: #fff; border-color: var(--accent); }
.assign-btn.demote { background: var(--surface2); border-color: var(--border); color: var(--text-muted); }
.assign-btn.demote:hover:not(:disabled) { border-color: var(--red); color: var(--red); background: #fee2e2; }

/* Session toggle button on admin cards */
.session-toggle-btn {
  padding: 0.3rem 0.65rem;
  background: #f0fdf4; border: 1px solid #86efac; color: var(--green);
  font-size: 0.75rem; white-space: nowrap; font-weight: 500;
}
.session-toggle-btn:hover:not(:disabled) { background: var(--green); color: #fff; border-color: var(--green); }
.session-toggle-btn.stop { background: #fee2e2; border: 1px solid #fca5a5; color: var(--red); }
.session-toggle-btn.stop:hover:not(:disabled) { background: var(--red); color: #fff; border-color: var(--red); }

/* Card action buttons column */
.card-actions { display: flex; flex-direction: column; gap: 0.3rem; flex-shrink: 0; }

/* Add member button */
.add-member-btn {
  padding: 0.35rem 0.85rem;
  background: #f0fdf4; border: 1px solid #86efac; color: var(--green);
  font-size: 0.82rem; font-weight: 600; white-space: nowrap;
}
.add-member-btn:hover:not(:disabled) { background: var(--green); color: #fff; border-color: var(--green); }

/* Modal select */
.modal-select {
  width: 100%; padding: 0.6rem 0.8rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); font-size: 0.95rem; outline: none;
}
.modal-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #2563eb18; }

@media (max-width: 700px) {
  .content { padding: 1rem; }
}

/* Team note (admin-only) */
.team-note-input {
  flex: 1; min-width: 0; padding: .3rem .6rem;
  border: 1px dashed var(--border); border-radius: var(--radius);
  background: #fffef0; color: var(--text); font-size: .85rem;
  outline: none; font-family: inherit; transition: border-color .15s;
}
.team-note-input:focus { border-color: #d97706; border-style: solid; box-shadow: 0 0 0 3px #d9770618; }
.note-saved-hint {
  font-size: .75rem; color: var(--green); flex-shrink: 0; white-space: nowrap;
}
