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

:root {
  --bg: #0f0f12;
  --bg-card: #1a1a22;
  --bg-input: #252530;
  --border: #2e2e3a;
  --text: #f0f0f5;
  --text-muted: #9898a8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --danger: #ef4444;
  --success: #22c55e;
  --pin: #f59e0b;
  --meta-blue: #1d9bf0;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

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

.screen {
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* ========== AUTH ========== */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at top, #1a1a2e 0%, #0f0f12 70%);
}

.auth-container {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 28px;
  box-shadow: var(--shadow);
}

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

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

.logo h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}

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

.tabs {
  display: flex;
  background: var(--bg-input);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 24px;
}

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

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

.auth-form {
  display: none;
}

.auth-form.active {
  display: block;
}

.form-group {
  margin-bottom: 16px;
}

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

.checkbox-group {
  margin-bottom: 20px;
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px !important;
  color: var(--text) !important;
  margin-bottom: 0 !important;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--meta-blue);
  cursor: pointer;
}

/* Meta Blue Badge */
.meta-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background: var(--meta-blue);
  color: white;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  vertical-align: middle;
  margin: 0 2px;
  box-shadow: 0 0 0 1.5px rgba(29, 155, 240, 0.3);
}

.meta-badge-lg {
  width: 18px;
  height: 18px;
  font-size: 11px;
}

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

input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: white;
  width: 100%;
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 8px 14px;
}

.btn-ghost:hover {
  background: var(--bg-input);
  color: var(--text);
}

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

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

.btn-pin.pinned {
  background: rgba(245, 158, 11, 0.15);
  color: var(--pin);
  border-color: var(--pin);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

.form-hint {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 16px;
}

.message {
  margin-top: 16px;
  padding: 12px;
  border-radius: 10px;
  font-size: 14px;
  text-align: center;
  display: none;
}

.message.error {
  display: block;
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

.message.success {
  display: block;
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
}

.security-note {
  margin-top: 20px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ========== APP ========== */
#app-screen {
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-small {
  font-size: 24px;
}

.header-left h1 {
  font-size: 18px;
  font-weight: 700;
}

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

.user-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-input);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-muted);
}

.security-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.2);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 24px;
  font-size: 13px;
  color: #86efac;
}

.app-main {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 20px 60px;
  width: 100%;
}

section {
  margin-bottom: 32px;
}

section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.section-header h2 {
  margin-bottom: 0;
}

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

.badge {
  background: var(--bg-input);
  color: var(--pin);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
}

.add-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.form-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.form-row input {
  flex: 1;
}

.form-row .btn {
  width: auto;
  white-space: nowrap;
}

/* Image Upload */
.image-upload-area {
  margin-top: 12px;
}

.upload-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px dashed var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all 0.2s;
}

.upload-label:hover {
  border-color: var(--primary);
  color: var(--text);
}

.upload-icon {
  font-size: 18px;
}

.image-preview {
  position: relative;
  margin-top: 12px;
  display: inline-block;
}

.image-preview img {
  max-width: 200px;
  max-height: 150px;
  border-radius: 10px;
  border: 1px solid var(--border);
  object-fit: cover;
}

.btn-remove-img {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-box input {
  width: 180px;
  padding: 8px 12px;
  font-size: 13px;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 14px;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.msg-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color 0.2s;
}

.msg-card:hover {
  border-color: #3f3f50;
}

.msg-card.pinned-card {
  border-color: rgba(245, 158, 11, 0.4);
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.06), transparent);
}

.msg-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.msg-title {
  font-size: 15px;
  font-weight: 600;
  word-break: break-word;
}

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

.msg-content {
  font-size: 14px;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 10px;
  line-height: 1.55;
}

.msg-image {
  margin: 10px 0;
}

.msg-image img {
  max-width: 100%;
  max-height: 280px;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
  object-fit: cover;
  transition: opacity 0.2s;
}

.msg-image img:hover {
  opacity: 0.9;
}

.msg-meta {
  font-size: 12px;
  color: #666;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.lock-icon {
  font-size: 11px;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.lightbox img {
  max-width: 95%;
  max-height: 90vh;
  border-radius: 8px;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  font-size: 18px;
  cursor: pointer;
}

.lightbox-close:hover {
  background: rgba(255,255,255,0.25);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #2a2a35;
  color: white;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 1000;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Responsive */
@media (max-width: 600px) {
  .app-header {
    padding: 12px 16px;
  }

  .header-left h1 {
    font-size: 16px;
  }

  .user-badge {
    display: none;
  }

  .form-row {
    flex-direction: column;
  }

  .form-row .btn {
    width: 100%;
  }

  .search-box input {
    width: 100%;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .security-banner {
    font-size: 12px;
  }
}

/* ========== LOADING SCREEN (Documents style) ========== */
.loading-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, #0f0f12 0%, #16162a 50%, #0f0f12 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-screen.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-content {
  text-align: center;
  max-width: 280px;
  width: 90%;
}

.loading-logo {
  margin-bottom: 24px;
}

.loading-icon-wrap {
  position: relative;
  width: 80px;
  height: 80px;
  margin: 0 auto;
}

.loading-icon {
  font-size: 40px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  animation: pulse-icon 1.8s ease-in-out infinite;
}

.loading-ring {
  position: absolute;
  inset: 0;
  border: 3px solid transparent;
  border-top-color: var(--primary);
  border-right-color: var(--meta-blue);
  border-radius: 50%;
  animation: spin-ring 1.2s linear infinite;
}

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

@keyframes pulse-icon {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  50% { transform: translate(-50%, -50%) scale(1.08); opacity: 0.85; }
}

.loading-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.3px;
}

.loading-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.loading-bar-track {
  height: 4px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 10px;
}

.loading-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--meta-blue));
  border-radius: 4px;
  transition: width 0.15s ease;
}

.loading-percent {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
