:root {
  --bg: #f7f6f4;
  --bg-card: #ffffff;
  --border: #e7e4df;
  --text: #1c1c1a;
  --text-muted: #6f6b64;
  --accent: #d9531e;
  --accent-dark: #b84316;
  --ok: #2f7a4f;
  --danger: #c0392b;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 2px 10px rgba(28, 28, 26, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--accent); }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px;
  width: 100%;
  max-width: 380px;
}
.login-card h1 {
  font-size: 1.3rem;
  margin: 0 0 4px;
}
.login-card .subtitle {
  color: var(--text-muted);
  font-size: .9rem;
  margin: 0 0 24px;
}
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .95rem;
  outline: none;
}
.field input:focus { border-color: var(--accent); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 600;
  font-size: .95rem;
  border: none;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  width: 100%;
}
.btn:hover { background: var(--accent-dark); }
.btn:disabled { opacity: .6; cursor: default; }
.error-text {
  color: var(--danger);
  font-size: .85rem;
  margin: 10px 0 0;
  display: none;
}
.error-text.show { display: block; }

/* ---------- Panel shell ---------- */
.panel-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-header .logo { font-weight: 800; font-size: 1.1rem; }
.panel-header .logo span { color: var(--accent); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: .85rem;
  cursor: pointer;
  font-weight: 600;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.panel-main { max-width: 1200px; margin: 0 auto; padding: 28px 24px 60px; }
.panel-section { margin-bottom: 40px; }
.panel-section h2 { font-size: 1.15rem; margin: 0 0 16px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
}
.stat-card .num { font-size: 1.7rem; font-weight: 800; display: block; }
.stat-card .label { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }

.chart-card, .table-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
  margin-bottom: 16px;
}
.chart-card h3, .table-card h3 { margin: 0 0 14px; font-size: .95rem; }

.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; }
.bar-chart .bar {
  flex: 1;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  position: relative;
}
.bar-chart .bar:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  font-size: .7rem;
  padding: 3px 6px;
  border-radius: 4px;
  white-space: nowrap;
  margin-bottom: 4px;
}

.mini-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.mini-table td { padding: 7px 4px; border-bottom: 1px solid var(--border); }
.mini-table td:last-child { text-align: right; font-weight: 700; color: var(--text-muted); }

.chat-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  min-height: 480px;
}
.conversation-list {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-height: 640px;
  overflow-y: auto;
}
.conversation-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  font-family: var(--font);
}
.conversation-item:hover { background: var(--bg); }
.conversation-item.active { background: #fdece3; }
.conversation-item .name { font-weight: 700; font-size: .9rem; }
.conversation-item .preview { font-size: .8rem; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-item .date { font-size: .7rem; color: var(--text-muted); margin-top: 4px; }

.chat-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
}
.chat-panel-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.chat-panel-header .name { font-weight: 700; }
.chat-panel-header .email { font-size: .8rem; color: var(--text-muted); }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 480px;
}
.msg { max-width: 75%; padding: 10px 14px; border-radius: 14px; font-size: .9rem; }
.msg-visitor { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); }
.msg-admin { align-self: flex-end; background: var(--accent); color: #fff; }
.msg .meta { font-size: .68rem; opacity: .65; margin-top: 4px; }
.chat-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); font-size: .9rem; }

.reply-box { border-top: 1px solid var(--border); padding: 14px; display: flex; gap: 10px; }
.reply-box textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--font);
  font-size: .9rem;
  min-height: 48px;
}
.reply-box .btn { width: auto; padding: 0 20px; }

@media (max-width: 800px) {
  .chat-layout { grid-template-columns: 1fr; }
  .conversation-list { max-height: 220px; }
}
