:root {
  --bg: #ffffff;
  --bg2: #f5f5f7;
  --bg3: #e8e8ed;
  --bg-card: #ffffff;
  --text: #1d1d1f;
  --text2: #6e6e73;
  --text3: #aeaeb2;
  --border: #d2d2d7;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --danger: #ff3b30;
  --success: #34c759;
  --warning: #ff9500;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 9999px;
  --transition: 0.2s ease;
  --nav-height: 56px;
  --bottom-nav-height: 64px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #000000;
  --bg2: #1c1c1e;
  --bg3: #2c2c2e;
  --bg-card: #1c1c1e;
  --text: #f5f5f7;
  --text2: #98989d;
  --text3: #636366;
  --border: #38383a;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Top Navigation */
.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.top-nav .logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  cursor: pointer;
}

.top-nav .nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--bg2);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background var(--transition);
}

.theme-toggle:hover {
  background: var(--bg3);
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  border: none;
  background: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 0.65rem;
  font-family: var(--font);
  transition: color var(--transition);
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.nav-item .nav-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.nav-item.active {
  color: var(--accent);
}

.nav-item:hover {
  color: var(--text);
}

.nav-badge {
  position: absolute;
  top: 2px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: var(--danger);
  border-radius: 50%;
}

/* Main Content */
.main-content {
  padding-top: var(--nav-height);
  padding-bottom: calc(var(--bottom-nav-height) + 16px);
  min-height: 100vh;
}

.page {
  display: none;
  animation: fadeIn 0.25s ease;
}

.page.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes checkStrike {
  from { text-decoration-color: transparent; }
  to { text-decoration-color: var(--text3); }
}

/* Container */
.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 20px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

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

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

/* Subject Block */
.subject-block {
  margin-bottom: 16px;
  animation: slideUp 0.3s ease;
  animation-fill-mode: both;
}

.subject-block:nth-child(1) { animation-delay: 0s; }
.subject-block:nth-child(2) { animation-delay: 0.05s; }
.subject-block:nth-child(3) { animation-delay: 0.1s; }
.subject-block:nth-child(4) { animation-delay: 0.15s; }
.subject-block:nth-child(5) { animation-delay: 0.2s; }

.subject-name {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
  margin-bottom: 8px;
  padding-left: 4px;
}

.hw-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.hw-item:hover {
  background: var(--bg3);
}

.hw-item:active {
  transform: scale(0.98);
}

.hw-checkbox {
  width: 22px;
  height: 22px;
  min-width: 22px;
  border-radius: 6px;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
  transition: all var(--transition);
  font-size: 0.8rem;
  color: transparent;
}

.hw-item.checked .hw-checkbox {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.hw-item.checked .hw-text {
  text-decoration: line-through;
  color: var(--text3);
  animation: checkStrike 0.3s ease;
}

.hw-text {
  font-size: 0.95rem;
  color: var(--text);
  word-break: break-word;
  transition: color var(--transition), text-decoration var(--transition);
}

/* Tab Switcher */
.tab-switcher {
  display: flex;
  gap: 4px;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 16px;
}

.tab-btn {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: none;
  color: var(--text2);
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

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

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

.btn-secondary {
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
}

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

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  opacity: 0.9;
}

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

.btn-full {
  width: 100%;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-full);
  border: none;
  background: var(--bg2);
  color: var(--text2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--bg3);
  color: var(--text);
}

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

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  transition: border-color var(--transition);
  outline: none;
}

.form-input:focus {
  border-color: var(--accent);
}

.form-input::placeholder {
  color: var(--text3);
}

.password-wrapper {
  position: relative;
}

.password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
}

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

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  padding: 20px;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
  transform: scale(0.95);
  transition: transform 0.2s;
}

.modal-overlay.active .modal {
  transform: scale(1);
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  justify-content: flex-end;
}

/* Chat */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--nav-height) - var(--bottom-nav-height));
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-message {
  padding: 10px 14px;
  background: var(--bg2);
  border-radius: var(--radius);
  max-width: 85%;
  animation: slideUp 0.2s ease;
  position: relative;
}

.chat-message.own {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
}

.chat-message.pinned {
  border-left: 3px solid var(--accent);
}

.chat-msg-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.chat-msg-name {
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.chat-msg-prefix {
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  font-weight: 500;
}

.chat-msg-content {
  font-size: 0.9rem;
  word-break: break-word;
}

.chat-msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.7rem;
  color: var(--text3);
}

.chat-message.own .chat-msg-meta {
  color: rgba(255,255,255,0.7);
}

.chat-msg-actions {
  display: none;
  position: absolute;
  top: -8px;
  right: 8px;
  gap: 4px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 4px;
  box-shadow: var(--shadow-md);
  z-index: 10;
}

.chat-message:hover .chat-msg-actions {
  display: flex;
}

.chat-input-area {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  background: var(--bg);
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg2);
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
  outline: none;
}

.chat-input:focus {
  border-color: var(--accent);
}

/* Profile */
.profile-header {
  text-align: center;
  padding: 24px 0;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 auto 12px;
}

.profile-name {
  font-size: 1.3rem;
  font-weight: 600;
}

.profile-username {
  font-size: 0.9rem;
  color: var(--text2);
  margin-top: 2px;
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.stat-item {
  background: var(--bg2);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 600;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text2);
  margin-top: 2px;
}

.profile-role {
  display: inline-flex;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 500;
  margin-top: 8px;
}

.role-user {
  background: var(--bg2);
  color: var(--text2);
}

.role-admin {
  background: var(--warning);
  color: #fff;
}

.role-owner {
  background: var(--accent);
  color: #fff;
}

/* Admin Panel */
.admin-section {
  margin-bottom: 20px;
}

.admin-section-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
  margin-bottom: 10px;
}

.user-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  cursor: pointer;
  transition: background var(--transition);
}

.user-list-item:hover {
  background: var(--bg3);
}

.user-list-avatar {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
}

.user-list-info {
  flex: 1;
  min-width: 0;
}

.user-list-name {
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.user-list-meta {
  font-size: 0.75rem;
  color: var(--text2);
}

.user-list-actions {
  display: flex;
  gap: 4px;
}

/* Status badges */
.badge {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.65rem;
  font-weight: 500;
}

.badge-frozen {
  background: #e8f0fe;
  color: #1967d2;
}

.badge-muted {
  background: #fef7e0;
  color: #ea8600;
}

.badge-banned {
  background: #fce8e6;
  color: #d93025;
}

[data-theme="dark"] .badge-frozen {
  background: #1a3a5c;
  color: #8ab4f8;
}

[data-theme="dark"] .badge-muted {
  background: #3d3200;
  color: #fdd663;
}

[data-theme="dark"] .badge-banned {
  background: #3c1010;
  color: #f28b82;
}

/* Frozen indicator */
.frozen-indicator {
  font-size: 0.75rem;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text3);
  border-radius: 3px;
}

/* Blur overlay for auth-required */
.auth-blur {
  position: relative;
}

.auth-blur-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg);
  opacity: 0.9;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.auth-blur-overlay p {
  font-size: 0.95rem;
  color: var(--text2);
  margin-bottom: 12px;
}

/* Menu */
.menu-day {
  margin-bottom: 16px;
}

.menu-day-name {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
  margin-bottom: 6px;
}

.menu-day-items {
  padding: 12px;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  white-space: pre-line;
}

/* Countdown */
.countdown-card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  margin-bottom: 12px;
}

.countdown-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.countdown-timer {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.countdown-unit {
  text-align: center;
}

.countdown-value {
  font-size: 1.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.countdown-label {
  font-size: 0.65rem;
  color: var(--text2);
  text-transform: uppercase;
}

/* User profile view modal */
.user-profile-view {
  text-align: center;
}

.user-profile-view .profile-avatar {
  width: 56px;
  height: 56px;
  font-size: 1.2rem;
}

.user-profile-view .profile-name {
  font-size: 1.1rem;
}

/* Color picker */
.color-picker-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.color-picker-row input[type="color"] {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  cursor: pointer;
  background: var(--bg2);
}

.color-picker-row .form-input {
  flex: 1;
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--bg3);
  border-radius: 12px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-switch.active {
  background: var(--accent);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
}

.toggle-switch.active::after {
  transform: translateX(20px);
}

/* Notification settings */
.notif-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}

.notif-setting-label {
  font-size: 0.9rem;
}

/* Privilege display in chat/profile */
.priv-prefix {
  display: inline-block;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  font-size: 0.65rem;
  font-weight: 600;
  margin-right: 4px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text3);
  font-size: 0.9rem;
}

/* Admin actions grid */
.admin-actions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.admin-action-btn {
  padding: 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  transition: all var(--transition);
  font-family: var(--font);
}

.admin-action-btn:hover {
  background: var(--bg3);
}

.admin-action-btn .action-icon {
  font-size: 1.5rem;
  margin-bottom: 4px;
  display: block;
}

/* Permissions checkboxes */
.perm-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.perm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg2);
  border-radius: var(--radius-sm);
}

.perm-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.perm-item label {
  font-size: 0.85rem;
  cursor: pointer;
}

/* Responsive */
@media (max-width: 480px) {
  .container {
    padding: 12px 16px;
  }

  .admin-actions-grid {
    grid-template-columns: 1fr;
  }

  .countdown-timer {
    gap: 8px;
  }

  .countdown-value {
    font-size: 1.4rem;
  }
}

@media (min-width: 768px) {
  .bottom-nav {
    max-width: 680px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: var(--radius) var(--radius) 0 0;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* Color picker input */
input[type="color"] {
  -webkit-appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

/* Section title */
.section-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 16px;
  letter-spacing: -0.3px;
}

/* Pinned messages header */
.pinned-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text2);
  cursor: pointer;
}

.pinned-count {
  font-weight: 600;
}

/* Edit mode indicator */
.edit-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text2);
}

.edit-indicator button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: var(--font);
}

/* HW admin controls */
.hw-admin-controls {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

/* Order controls */
.order-controls {
  display: flex;
  gap: 2px;
}

.order-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: var(--bg2);
  color: var(--text2);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
}

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