/* ========== Global Styles ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #333;
  --accent: #888;
  --link: #06c;
  --border: #ddd;
  --bg: #fff;
  --light-bg: #fafafa;
  --font: 'Helvetica Neue', Arial, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --max-width: 900px;
}

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.8;
  color: var(--primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

a {
  color: var(--link);
  text-decoration: none;
  transition: color 0.2s;
}

a:hover {
  color: #004999;
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
}

/* ========== Header ========== */
.header {
  padding: 24px 90px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.header-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.header .site-title {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--primary);
  text-decoration: none;
  flex-shrink: 0;
}

.header img.site-subtitle {
  display: block;
  height: 18px;
  cursor: pointer;
  margin-top: 2px;
}

.header > .nav {
  margin-top: 4px;
  padding: 0;
}

/* ========== Navigation ========== */
.nav {
  padding: 16px 0 16px 24px;
  font-size: 14px;
}

.nav .nav-right {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.nav a {
  color: var(--accent);
  text-decoration: none;
  padding: 0;
  position: relative;
}

.nav a:hover,
.nav a.active {
  color: var(--primary);
}

.nav a.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: #ccc;
}

/* ========== Nav Dropdown ========== */
.nav-dropdown {
  position: relative;
  display: flex;
  align-items: center;
}

.nav-dropdown-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 14px;
  color: var(--accent);
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-dropdown-btn:hover,
.nav-dropdown.open .nav-dropdown-btn {
  color: var(--primary);
}

.nav-dropdown-arrow {
  font-size: 10px;
  transition: transform 0.2s;
}

.nav-dropdown.open .nav-dropdown-arrow {
  transform: rotate(180deg);
}

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  min-width: 160px;
  z-index: 100;
  overflow: hidden;
}

.nav-dropdown.open .nav-dropdown-menu {
  display: block;
}

.nav-dropdown-menu a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
  border: none;
  transition: background 0.15s;
}

.nav-dropdown-menu a:hover {
  background: #f5f5f5;
  color: var(--primary);
}

.nav-dropdown-menu .external-icon {
  font-size: 11px;
  opacity: 0.6;
  margin-left: 6px;
}

.nav-dropdown-empty {
  display: block;
  padding: 10px 16px;
  color: #999;
  font-size: 13px;
}

/* ========== Main Content ========== */
.main {
  padding: 0 90px;
}

/* ========== Post List ========== */
.post-list {
  padding: 40px 0;
}

.post-item {
  margin-bottom: 48px;
  padding-bottom: 48px;
  border-bottom: 1px solid var(--border);
}

.post-item:last-child {
  border-bottom: none;
}

.post-item .post-title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 16px;
  line-height: 1.4;
}

.post-item .post-title a {
  color: var(--primary);
  text-decoration: none;
}

.post-item .post-title a:hover {
  color: var(--link);
}

.post-item .post-meta {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 16px;
}

.post-item .post-meta a {
  color: var(--accent);
}

.post-item .post-meta a:hover {
  color: var(--link);
}

.post-item .post-preview {
  color: #666;
  font-size: 15px;
  line-height: 1.8;
}

.post-item .post-protected {
  color: #999;
  font-style: italic;
  font-size: 15px;
}

/* ========== Post Detail ========== */
.post-detail {
  padding: 40px 0;
}

.post-detail .post-title {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 16px;
  line-height: 1.4;
}

.post-detail .post-meta {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 32px;
}

.post-detail .post-content {
  font-size: 22px;
  line-height: 2;
  color: #333;
}

.post-detail .post-content h1,
.post-detail .post-content h2,
.post-detail .post-content h3 {
  margin: 32px 0 16px;
}

.post-detail .post-content p {
  margin-bottom: 16px;
}

.post-detail .post-content img {
  margin: 16px 0;
  border-radius: 4px;
}

.post-detail .post-content blockquote {
  border-left: 3px solid var(--border);
  padding-left: 16px;
  color: #666;
  margin: 16px 0;
}

.post-detail .post-content code {
  background: #f4f4f4;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 14px;
}

/* ========== Page (About, Link) ========== */
.page-content {
  padding: 40px 0;
  font-size: 22px;
  line-height: 2;
}

.page-content h1 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 24px;
}

.page-content p {
  margin-bottom: 16px;
  line-height: 2;
}

/* ========== Archive ========== */
.archive-list {
  padding: 40px 0;
}

.archive-group {
  margin-bottom: 40px;
}

.archive-group h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--accent);
}

.archive-item {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 8px 0;
}

.archive-item .date {
  font-size: 13px;
  color: var(--accent);
  min-width: 90px;
}

.archive-item a {
  color: var(--primary);
}

/* ========== Friends ========== */
.friends-list {
  padding: 40px 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
}

.friend-card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: box-shadow 0.2s;
}

.friend-card:hover {
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

.friend-card h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

.friend-card p {
  font-size: 13px;
  color: var(--accent);
}

/* ========== Comments ========== */
.comments-section {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.comments-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 24px;
}

.comment-item {
  padding: 16px 0;
  border-bottom: 1px solid #f0f0f0;
}

.comment-item:last-child {
  border-bottom: none;
}

.comment-meta {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 8px;
}

.comment-meta a {
  color: var(--link);
}

.comment-content {
  font-size: 15px;
  line-height: 1.6;
}

.comment-form {
  margin-top: 32px;
  padding: 24px;
  background: var(--light-bg);
  border-radius: 8px;
}

.comment-form h3 {
  font-size: 16px;
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: #666;
  margin-bottom: 4px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  font-family: var(--font);
}

.form-group textarea {
  min-height: 100px;
  resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--link);
}

.btn {
  padding: 8px 24px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  font-family: var(--font);
}

.btn:hover {
  background: #555;
}

.btn-secondary {
  background: #eee;
  color: #333;
}

.btn-secondary:hover {
  background: #ddd;
}

/* ========== Pagination ========== */
.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 32px 0 48px;
}

.pagination a,
.pagination span {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  color: var(--primary);
}

.pagination a:hover {
  background: var(--light-bg);
  text-decoration: none;
}

.pagination .current {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ========== Password Form ========== */
.password-form {
  max-width: 400px;
  margin: 40px auto;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: center;
}

.password-form h3 {
  margin-bottom: 16px;
}

.password-form input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 12px;
  font-size: 14px;
}

/* ========== Footer ========== */
.footer {
  border-top: 1px solid var(--border);
  padding: 24px;
  text-align: center;
  font-size: 12px;
  color: var(--accent);
  margin-top: auto;
}

.footer a {
  color: var(--accent);
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 8px;
}

/* ========== Admin Login ========== */
.login-container {
  max-width: 400px;
  margin: 100px auto;
  padding: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.login-container h2 {
  text-align: center;
  margin-bottom: 24px;
}

.login-error {
  color: #c00;
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}

/* ========== Dashboard ========== */
.dashboard-container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
  box-sizing: border-box;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.dashboard-header h2 {
  font-size: 20px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: center;
}

.stat-card .stat-number {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--accent);
  margin-top: 4px;
}

/* ========== Table ========== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.data-table th {
  background: var(--light-bg);
  font-weight: 600;
}

.data-table tr:hover td {
  background: #fafafa;
}

/* ========== Modal ========== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: #fff;
  padding: 32px;
  border-radius: 8px;
  min-width: 500px;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal h3 {
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ========== Responsive ========== */

/* Tablet */
@media (max-width: 900px) {
  .header {
    padding: 20px 50px 14px;
  }
  .main {
    padding: 0 50px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
    padding: 20px 16px 14px;
    gap: 0;
  }
  .header .site-title {
    font-size: 22px;
  }
  .header .site-subtitle {
    font-size: 12px;
  }
  .nav .nav-right {
    gap: 16px;
    font-size: 13px;
    flex-wrap: wrap;
  }
  .nav-dropdown-menu {
    position: static;
    box-shadow: none;
    border: none;
    border-top: 1px solid var(--border);
    border-radius: 0;
    min-width: unset;
    background: transparent;
    padding: 4px 0;
  }
  .nav-dropdown-menu a {
    padding: 8px 0;
    background: transparent;
  }
  .nav-dropdown-menu a:hover {
    background: transparent;
  }
  .nav-dropdown.open .nav-dropdown-menu {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
  }
  .main {
    padding: 0 16px;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .modal {
    min-width: auto;
    margin: 16px;
    max-width: calc(100vw - 32px);
  }
  /* Post list - reduce title size on mobile */
  .post-item .post-title {
    font-size: 20px;
  }
  .post-item {
    margin-bottom: 32px;
    padding-bottom: 32px;
  }
  /* Post detail */
  .post-detail .post-title {
    font-size: 22px;
  }
  /* Archive */
  .archive-item {
    flex-direction: column;
    gap: 4px;
  }
  .archive-item .date {
    min-width: unset;
  }
  /* Friends grid - 1 column on mobile */
  .friends-list {
    grid-template-columns: 1fr;
  }
  /* Pagination - smaller buttons */
  .pagination a,
  .pagination span {
    padding: 5px 10px;
    font-size: 13px;
  }
  /* Comment form */
  .comment-form {
    padding: 16px;
  }
  /* Password form */
  .password-form {
    margin: 24px 0;
    padding: 24px 16px;
  }
}

/* Small mobile */
@media (max-width: 480px) {
  .header .site-title {
    font-size: 20px;
  }
  .nav .nav-right {
    gap: 14px;
    font-size: 12px;
  }
  .post-item .post-title {
    font-size: 18px;
  }
  .page-content h1 {
    font-size: 22px;
  }
  .dashboard-container {
    padding: 16px;
  }
  .stat-card .stat-number {
    font-size: 26px;
  }
  /* Table scroll wrapper on mobile */
  .data-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
  .data-table th,
  .data-table td {
    padding: 10px 12px;
    font-size: 13px;
  }
}

/* ========== Back to Top ========== */
.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 50;
}

.back-to-top.visible {
  opacity: 1;
  pointer-events: auto;
}

.back-to-top::before {
  content: '';
  display: block;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 10px solid #ccc;
}

.back-to-top:hover::before {
  border-bottom-color: #999;
}

/* Scrollable table for tablet+ too */
@media (max-width: 900px) {
  .data-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}
