:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --ink: #1e1d1a;
  --muted: #6e6a63;
  --accent: #80613d;
  --accent-soft: #e9ddcf;
  --danger: #9a2a2a;
  --success: #1f7a4d;
  --border: #dfd5c9;
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}
body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  background: radial-gradient(circle at top, #fffaf1, var(--bg));
  color: var(--ink);
  min-height: 100dvh;
}
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; display: block; }

.app-shell {
  width: min(100%, 980px);
  max-width: 980px;
  margin: 0 auto;
  padding: clamp(10px, 2.2vw, 20px);
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px;
  gap: 10px;
}
.brand { margin: 0; font-size: 1.1rem; }
.muted { color: var(--muted); margin: 0.2rem 0 0.6rem; }

.tabs {
  margin-top: 10px; display: flex; gap: 8px; overflow-x: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 8px;
}
.tabs a { padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); white-space: nowrap; color: var(--ink); font-size: 0.9rem; }
.tabs a.active { background: var(--accent); color: #fff; }

.content { margin-top: 12px; display: grid; gap: 12px; min-width: 0; }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px;
  min-width: 0;
  overflow: hidden;
}
.narrow { max-width: 560px; margin: 0 auto; }

.grid { display: grid; gap: 12px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.metric { margin: 0; font-size: 1.5rem; font-weight: 700; }
.post-grid { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.login-shell {
  display: grid;
  gap: 12px;
  align-items: stretch;
}
.login-brand {
  background: linear-gradient(160deg, #3d2b18, #6b4b2b);
  color: #fff;
  border-color: transparent;
  display: grid;
  align-content: center;
  min-height: 240px;
}
.login-brand .muted {
  color: rgba(255, 255, 255, 0.86);
  margin: 0;
}
.kicker {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  opacity: 0.84;
}
.login-brand h2 {
  margin: 0 0 10px;
  font-size: clamp(1.4rem, 2.8vw, 1.85rem);
}
.login-card h2 {
  margin: 0 0 6px;
}
.field {
  font-size: 0.85rem;
  color: #4b463f;
  font-weight: 600;
  gap: 6px;
}
.login-card input {
  border-color: #d6cdc1;
  border-radius: 12px;
  padding: 11px 12px;
}
.login-card input:focus {
  outline: none;
  border-color: #8b6a44;
  box-shadow: 0 0 0 3px rgba(128, 97, 61, 0.18);
}
.login-btn {
  margin-top: 4px;
  border-radius: 12px;
  padding: 11px 14px;
}

.stack { display: grid; gap: 10px; }
label { font-size: 0.9rem; display: grid; gap: 4px; }
input, textarea, select {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; font: inherit; background: #fff;
}
textarea { min-height: 90px; resize: vertical; }

.btn {
  border: 0; border-radius: 10px; padding: 10px 12px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600;
}
.btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--ink);
}
.actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.alert { border-radius: 10px; padding: 10px; margin: 10px 0; }
.alert {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.alert.error { background: #ffe6e6; color: var(--danger); }
.alert.success { background: #e8f7ee; color: var(--success); }

.badge {
  display: inline-block; padding: 4px 8px; border-radius: 999px;
  background: var(--accent-soft); font-size: 0.8rem;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td {
  text-align: left; border-bottom: 1px solid var(--border); padding: 8px 6px;
  font-size: 0.85rem; vertical-align: top; word-wrap: break-word; overflow-wrap: anywhere;
}

.thumb { aspect-ratio: 1 / 1; object-fit: cover; border-radius: 12px; margin-bottom: 8px; }
.hero { border-radius: 14px; max-height: 460px; object-fit: cover; margin-bottom: 10px; width: 100%; }
.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mobile-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: none;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  backdrop-filter: blur(10px);
}
.mobile-nav a {
  text-decoration: none;
  color: var(--ink);
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 6px 2px;
  border-radius: 10px;
}
.mobile-nav a.active {
  background: var(--accent-soft);
}
.icon-wrap {
  position: relative;
  width: 24px;
  height: 24px;
}
.icon-wrap svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}
.nav-label {
  font-size: 0.72rem;
  line-height: 1.1;
}
.badge-dot {
  position: absolute;
  top: -6px;
  right: -9px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  font-weight: 700;
  color: #fff;
  background: #d92d20;
  border: 1px solid #fff;
}

@media (max-width: 520px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .btn, .btn-ghost { width: 100%; }
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tabs a { flex: 0 0 auto; }
  .login-brand { min-height: 180px; }
}

@media (max-width: 760px) {
  .tabs { display: none; }
  .mobile-nav { display: grid; }
  .content { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  .responsive-table { overflow: hidden; }
  .responsive-table table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }
  .responsive-table thead {
    display: none;
  }
  .responsive-table tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 8px;
    margin-bottom: 8px;
    background: #fff;
  }
  .responsive-table td {
    border: 0;
    padding: 6px 2px;
    font-size: 0.9rem;
  }
  .responsive-table td::before {
    content: attr(data-label) ": ";
    font-weight: 700;
    color: var(--ink);
  }
}

@media (min-width: 768px) {
  .stats { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .post-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .app-shell { padding: 20px; }
  .login-shell { grid-template-columns: minmax(280px, 1fr) minmax(360px, 1.2fr); }
}
