* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  color: #1a1a1a;
  background: #f7f7f8;
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-page { padding: 1.25rem; }
.login-box {
  background: #fff;
  padding: 2rem 2.5rem;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  width: 100%;
  max-width: 320px;
}
.login-box h1 { font-size: 1.3rem; margin-bottom: 1.2rem; }
.login-box label { display: block; margin-bottom: 0.9rem; font-size: 0.85rem; color: #555; }
.login-box input {
  display: block; width: 100%; margin-top: 0.3rem;
  padding: 0.6rem; border: 1px solid #ccc; border-radius: 6px; font-size: 16px;
}
.login-box button, .filters button, .actions button, .logout-form button,
.account-form button {
  cursor: pointer; border: none; border-radius: 6px; background: #1a1a1a; color: #fff;
  padding: 0.6rem 1rem; font-size: 0.9rem;
}
.login-box button { width: 100%; padding: 0.75rem; font-size: 1rem; }
.error { color: #c0392b; font-size: 0.85rem; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: #fff; padding: 0.8rem 1.5rem; border-bottom: 1px solid #e5e5e5;
}
.tabs a {
  text-decoration: none; color: #555; padding: 0.5rem 1rem; border-radius: 6px; margin-right: 0.5rem;
}
.tabs a.active { background: #1a1a1a; color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.account-link { color: #555; font-size: 0.85rem; text-decoration: none; }
.account-link:hover { text-decoration: underline; }
.logout-form { display: flex; align-items: center; gap: 0.6rem; }
.whoami { color: #888; font-size: 0.85rem; }

main { padding: 1.5rem; max-width: 1100px; margin: 0 auto; }
main.narrow { max-width: 420px; }
main.narrow h1 { font-size: 1.2rem; }

.account-form { display: flex; flex-direction: column; gap: 1rem; background: #fff; padding: 1.2rem; border-radius: 8px; }
.account-form label { font-size: 0.85rem; color: #555; display: flex; flex-direction: column; gap: 0.3rem; }
.account-form input { padding: 0.6rem; border: 1px solid #ccc; border-radius: 6px; font-size: 16px; }
.account-form button { align-self: flex-start; }

.generate-form {
  display: flex; gap: 0.6rem; align-items: center; margin-bottom: 1rem;
}
.generate-form select { padding: 0.5rem; border: 1px solid #ccc; border-radius: 6px; font-size: 16px; }
.generate-btn {
  cursor: pointer; border: none; border-radius: 6px; background: #2f6fed; color: #fff;
  padding: 0.6rem 1.1rem; font-size: 0.9rem; font-weight: 600;
}
.generate-btn:disabled { background: #9db8f2; cursor: wait; }

.flash { padding: 0.6rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem; }
.flash.success { background: #eafaf1; color: #1e8449; }
.flash.error { background: #fdecea; color: #c0392b; }

.filters {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: end;
  background: #fff; padding: 1rem; border-radius: 8px; margin-bottom: 1rem;
}
.filters label { font-size: 0.8rem; color: #555; display: flex; flex-direction: column; gap: 0.3rem; }
.filters input, .filters select { padding: 0.5rem; border: 1px solid #ccc; border-radius: 6px; font-size: 16px; }
.filters .reset { align-self: center; font-size: 0.85rem; color: #888; }

table.posts { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; }
table.posts th, table.posts td { padding: 0.7rem 0.9rem; border-bottom: 1px solid #eee; text-align: left; vertical-align: top; }
table.posts th { background: #fafafa; font-size: 0.8rem; color: #777; }
.post-text { white-space: pre-wrap; max-width: 420px; font-size: 0.9rem; }
.nowrap { white-space: nowrap; }
.empty { text-align: center; color: #999; padding: 2rem; }

.badge { padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.75rem; }
.badge.draft { background: #fff3cd; color: #856404; }
.badge.published { background: #d4edda; color: #155724; }

.view-btn {
  display: inline-flex; align-items: center; gap: 0.3rem;
  margin-top: 0.5rem; padding: 0.3rem 0.65rem;
  background: #eafaf1; color: #1e8449; border: 1px solid #bfe8cf;
  border-radius: 6px; font-size: 0.78rem; text-decoration: none; white-space: nowrap;
}
.view-btn:hover { background: #d4edda; }
.view-btn .arrow { font-size: 0.85em; }

.actions { display: flex; flex-direction: column; gap: 0.4rem; }
.inline-form { display: inline; }
.copy-btn { background: #eee; color: #1a1a1a; }
.delete-btn { background: #fdecea; color: #c0392b; }
.delete-btn:hover { background: #fadbd8; }

/* ============ 모바일 ============ */
@media (max-width: 700px) {
  .topbar {
    flex-wrap: wrap;
    gap: 0.6rem;
    padding: 0.7rem 1rem;
  }
  .tabs { display: flex; flex: 1 1 auto; }
  .tabs a { flex: 1; text-align: center; padding: 0.5rem 0.4rem; margin-right: 0.3rem; font-size: 0.85rem; }
  .topbar-right { flex: 0 0 auto; }

  main { padding: 1rem 0.75rem; }

  .generate-form { flex-wrap: wrap; }
  .generate-form select { flex: 1 1 auto; }
  .generate-btn { flex: 1 1 100%; padding: 0.75rem; font-size: 1rem; }

  .filters { flex-direction: column; align-items: stretch; padding: 0.9rem; }
  .filters label { width: 100%; }
  .filters input, .filters select { width: 100%; }
  .filters button { padding: 0.75rem; font-size: 1rem; }
  .filters .reset { align-self: center; }

  /* 표를 카드 목록으로 재구성 */
  table.posts, table.posts tbody, table.posts tr, table.posts td {
    display: block;
    width: 100%;
  }
  table.posts thead { display: none; }
  table.posts {
    border-radius: 0;
    background: transparent;
  }
  table.posts tr {
    background: #fff;
    border-radius: 10px;
    margin-bottom: 0.9rem;
    padding: 0.9rem 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  }
  table.posts td {
    border-bottom: none;
    padding: 0.3rem 0;
  }
  table.posts td.nowrap:not(.actions) {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    white-space: normal;
  }
  table.posts td.nowrap:not(.actions)::before {
    content: attr(data-label);
    font-size: 0.72rem;
    color: #999;
    flex: 0 0 auto;
  }
  td.post-text {
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
    max-width: none;
    border-top: 1px solid #f0f0f0;
    border-bottom: 1px solid #f0f0f0;
    margin: 0.4rem 0;
  }
  .actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding-top: 0.5rem;
  }
  .actions .copy-btn, .actions .inline-form {
    flex: 1 1 45%;
    min-width: 0;
  }
  .actions .inline-form { display: flex; }
  .actions button { width: 100%; padding: 0.7rem; }
  .view-btn { width: 100%; justify-content: center; padding: 0.5rem; }

  .account-form button { width: 100%; padding: 0.75rem; font-size: 1rem; }
}
