/* ===== CSS Variables & Theme ===== */
:root {
  --bg-primary: #f5f7fa;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #5a5a7a;
  --text-muted: #8a8aaa;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --blue: #0066cc;
  --blue-light: #e8f0fe;
  --green: #10b981;
  --green-light: #d1fae5;
  --orange: #f59e0b;
  --orange-light: #fef3c7;
  --red: #ef4444;
  --red-light: #fee2e2;
  --purple: #8b5cf6;
  --purple-light: #ede9fe;
  --cyan: #06b6d4;
  --cyan-light: #cffafe;
  --black: #1a1a2e;
  --black-light: #e8e8f0;
}

[data-theme="dark"] {
  --bg-primary: #0f1729;
  --bg-secondary: #1a2340;
  --bg-card: #1a2340;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #2d3a56;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
  --blue-light: #1e3a5f;
  --green-light: #064e3b;
  --orange-light: #451a03;
  --red-light: #450a0a;
  --purple-light: #2e1065;
  --cyan-light: #083344;
  --black-light: #1e293b;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans SC', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* ===== Header ===== */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  flex-wrap: nowrap;
  gap: 12px;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

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

.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
  width: fit-content;
}

.mode-badge.guest { background: var(--green-light); color: var(--green); }
.mode-badge.viewer { background: var(--blue-light); color: var(--blue); }
.mode-badge.editor { background: var(--orange-light); color: var(--orange); }

.mode-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.mode-badge.guest .dot { background: var(--green); }
.mode-badge.viewer .dot { background: var(--blue); }
.mode-badge.editor .dot { background: var(--orange); }

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-btn {
  padding: 6px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-btn:hover { border-color: var(--blue); color: var(--blue); }

.header-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); }

.header-btn.request {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.header-btn.request:hover { opacity: 0.9; }

.header-btn.exit {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.header-btn.exit:hover { opacity: 0.9; }

.theme-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  border-radius: var(--radius-sm);
}

.lang-btn {
  padding: 6px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

/* ===== Container ===== */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px;
}

/* ===== Dashboard Cards ===== */
.dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.dash-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  text-align: center;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
}

.dash-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.dash-card .number {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}

.dash-card .label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.dash-card.col-blue .number { color: var(--blue); }
.dash-card.col-black .number { color: var(--text-primary); }
.dash-card.col-red .number { color: var(--red); }
.dash-card.col-orange .number { color: var(--orange); }
.dash-card.col-green .number { color: var(--green); }
.dash-card.col-purple .number { color: var(--purple); }
.dash-card.col-cyan .number { color: var(--cyan); }

.dash-card.full-width {
  grid-column: 1 / -1;
}

/* ===== Section ===== */
.section {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 8px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.section-time {
  font-size: 12px;
  color: var(--text-muted);
}

.section-actions {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.btn:hover { border-color: var(--blue); color: var(--blue); }

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

.btn-primary:hover { opacity: 0.9; color: #fff; }

.btn-danger {
  color: var(--red);
  border-color: transparent;
  background: transparent;
}

.btn-danger:hover { background: var(--red-light); }

.btn-sm {
  padding: 3px 10px;
  font-size: 12px;
}

/* ===== Table ===== */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead { background: var(--bg-primary); }

th {
  padding: 10px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-color);
}

td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  vertical-align: top;
}

tbody tr:hover { background: var(--bg-primary); }

.empty-row td {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

/* ===== Status Tag ===== */
.status-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.status-tag .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-tag.red { background: var(--red-light); color: var(--red); }
.status-tag.red .dot { background: var(--red); }
.status-tag.orange { background: var(--orange-light); color: var(--orange); }
.status-tag.orange .dot { background: var(--orange); }
.status-tag.purple { background: var(--purple-light); color: var(--purple); }
.status-tag.purple .dot { background: var(--purple); }
.status-tag.green { background: var(--green-light); color: var(--green); }
.status-tag.green .dot { background: var(--green); }

/* ===== Autocomplete ===== */
.autocomplete-wrapper {
  position: relative;
}

.autocomplete-input {
  width: 100%;
}

.autocomplete-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 100;
  margin-top: 2px;
}

.autocomplete-dropdown.show { display: block; }

.autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  transition: background 0.15s;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: var(--blue-light);
  color: var(--blue);
}

.autocomplete-item mark {
  background: none;
  color: var(--blue);
  font-weight: 700;
}

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

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover { background: var(--bg-primary); }

.modal-body { padding: 20px; }
.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ===== Form ===== */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-label .optional {
  color: var(--text-muted);
  font-weight: 400;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color 0.2s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--blue);
}

.form-textarea { min-height: 80px; resize: vertical; }

.form-error {
  color: var(--red);
  font-size: 12px;
  margin-top: 4px;
  display: none;
}

.form-error.show { display: block; }

/* ===== Access Type Cards ===== */
.access-type-card {
  padding: 16px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 10px;
}

.access-type-card:hover { border-color: var(--blue); }
.access-type-card.selected { border-color: var(--blue); background: var(--blue-light); }

.access-type-card .card-icon { font-size: 20px; margin-bottom: 4px; }
.access-type-card .card-title { font-weight: 600; font-size: 14px; color: var(--text-primary); }
.access-type-card .card-desc { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ===== Lockout Banner ===== */
.lockout-banner {
  background: var(--red-light);
  color: var(--red);
  padding: 12px 20px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  display: none;
}

.lockout-banner.show { display: block; }

/* ===== Password Input ===== */
.password-wrapper {
  position: relative;
}

.password-wrapper .form-input {
  padding-right: 40px;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .dashboard { grid-template-columns: repeat(2, 1fr); }
  .container { padding: 16px; }
  .header { padding: 10px 16px; }
}

@media (max-width: 600px) {
  .dashboard { grid-template-columns: 1fr; }
}

/* ===== Loading ===== */
.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-color);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Refresh indicator ===== */
.refresh-indicator {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ===== Delete confirmation ===== */
.confirm-text {
  font-size: 15px;
  color: var(--text-primary);
  margin-bottom: 4px;
}

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

/* ===== Error message in modal ===== */
.modal-error {
  color: var(--red);
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
  padding: 8px 12px;
  background: var(--red-light);
  border-radius: var(--radius-sm);
}

.modal-error.show { display: block; }
