@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@500;600;700;800&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --red: #C41E1E;
  --red-dark: #9A1717;
  --ink: #161513;
  --ink-soft: #322F2B;
  --paper: #F6F3EC;
  --paper-dim: #ECE7DC;
  --steel: #7C7A74;
  --steel-line: #D8D3C6;
  --white: #FFFFFF;
  --teal: #2B7A6F;
  --blue: #2B3A67;
  --amber: #C97A1E;
  --steel-accent: #55524B;
  --font-display: 'Barlow Condensed', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --sidebar-w: 230px;
}

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

body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; text-transform: uppercase; letter-spacing: 0.01em; }

/* ---- Login page ---- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--white);
  border: 1px solid var(--steel-line);
  padding: 2.5rem;
}

.login-logo { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 2rem; }
.login-logo img { height: 38px; }
.login-logo .brand-text { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; }
.login-logo .brand-text span { display:block; font-family: var(--font-mono); font-weight: 400; font-size: 0.6rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--steel); }

.field { margin-bottom: 1.2rem; }
.field label { display:block; font-family: var(--font-mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--steel); margin-bottom: 0.5em; }
.field input {
  width: 100%; padding: 0.7em 0.9em; border: 1px solid var(--steel-line);
  font-family: var(--font-body); font-size: 1rem; border-radius: 2px;
}
.field input:focus { outline: 2px solid var(--red); outline-offset: 1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5em;
  font-family: var(--font-display); font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  font-size: 1rem; padding: 0.8em 1.6em; border-radius: 2px; border: 2px solid var(--ink);
  cursor: pointer; background: var(--red); border-color: var(--red); color: var(--white); width: 100%;
}
.btn:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.error-box { background:#FBE4E4; border:1px solid #A32323; color:#A32323; padding: 0.7em 1em; margin-bottom: 1rem; font-size: 0.88rem; display:none; }

/* ---- Dashboard layout ---- */

.app-shell { display: block; min-height: 100vh; }

.sidebar {
  position: fixed; top:0; left:0; bottom:0; width: var(--sidebar-w);
  background: var(--ink); color: var(--paper); padding: 1.5rem 0;
  display: flex; flex-direction: column;
}

.sidebar-logo { display: flex; align-items: center; gap: 0.6rem; padding: 0 1.5rem 1.5rem; border-bottom: 1px solid #3A3833; margin-bottom: 1rem; }
.sidebar-logo img { height: 32px; }
.sidebar-logo .brand-text { font-family: var(--font-display); font-weight: 800; font-size: 1rem; }

.sidebar-nav { display: flex; flex-direction: column; gap: 0.2rem; padding: 0 0.8rem; flex: 1; }
.sidebar-nav a {
  padding: 0.7em 1em; border-radius: 2px; font-family: var(--font-display); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.02em; font-size: 0.92rem; color: #C9C5B8;
}
.sidebar-nav a:hover { background: #24221E; color: var(--paper); }
.sidebar-nav a.active { background: var(--red); color: var(--white); }

.sidebar-footer { padding: 1rem 1.5rem 0; border-top: 1px solid #3A3833; }
.sidebar-footer .admin-name { font-size: 0.85rem; color: var(--paper); margin-bottom: 0.6rem; }
.logout-btn {
  font-family: var(--font-mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: #C9C5B8; background: none; border: 1px solid #4A473F; padding: 0.5em 0.9em; cursor: pointer; border-radius: 2px; width: 100%;
}
.logout-btn:hover { border-color: var(--red); color: var(--red); }

.main-content { margin-left: var(--sidebar-w); padding: 2rem 2.5rem; }

@media (max-width: 800px) {
  .sidebar { position: static; width: 100%; flex-direction: row; align-items: center; padding: 0.8rem 1rem; }
  .sidebar-logo { border: none; padding: 0; margin: 0; }
  .sidebar-logo .brand-text { display: none; }
  .sidebar-nav { flex-direction: row; padding: 0 0 0 1rem; overflow-x: auto; }
  .sidebar-nav a { white-space: nowrap; font-size: 0.8rem; padding: 0.5em 0.8em; }
  .sidebar-footer { display: none; }
  .main-content { margin-left: 0; padding: 1.2rem; }
}

.page-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 1.8rem; flex-wrap: wrap; gap: 1rem; }
.page-head h1 { font-size: 1.8rem; }
.page-head p { color: var(--steel); font-size: 0.92rem; margin-top: 0.2rem; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 2rem; }
@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-card { background: var(--white); border: 1px solid var(--steel-line); padding: 1.2rem; }
.stat-card .label { font-family: var(--font-mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--steel); margin-bottom: 0.4rem; }
.stat-card .value { font-family: var(--font-display); font-weight: 800; font-size: 2.1rem; }
.stat-card.accent-red .value { color: var(--red); }

.panel { background: var(--white); border: 1px solid var(--steel-line); }
.panel-head { padding: 1rem 1.3rem; border-bottom: 1px solid var(--steel-line); display:flex; justify-content: space-between; align-items:center; flex-wrap: wrap; gap: 0.8rem; }
.panel-head h3 { font-size: 1.1rem; text-transform: none; }

.filters { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.filters select, .filters input {
  padding: 0.5em 0.8em; border: 1px solid var(--steel-line); font-family: var(--font-body); font-size: 0.88rem; border-radius: 2px;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.85em 1.3em; border-bottom: 1px solid var(--steel-line); font-size: 0.92rem; }
th { font-family: var(--font-mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--steel); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--paper-dim); }
tbody tr.unread td:first-child { border-left: 3px solid var(--red); }

.badge { font-family: var(--font-mono); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 0.25em 0.6em; border-radius: 2px; color: var(--white); display:inline-block; }
.badge-construction { background: var(--steel-accent); }
.badge-pharma-agrovet { background: var(--teal); }
.badge-education { background: var(--blue); }
.badge-supplies { background: var(--amber); }
.badge-general { background: var(--steel); }

.dot-unread { display:inline-block; width:8px; height:8px; border-radius:50%; background: var(--red); margin-right: 0.5em; }

.empty-state { padding: 3rem 1.5rem; text-align: center; color: var(--steel); }

.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; padding: 1rem; }
.pagination button { background: none; border: 1px solid var(--steel-line); padding: 0.4em 0.9em; cursor: pointer; border-radius: 2px; font-family: var(--font-mono); font-size: 0.8rem; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(22,21,19,0.6); display: none;
  align-items: center; justify-content: center; padding: 1rem; z-index: 200;
}
.modal-overlay.open { display: flex; }
.modal { background: var(--white); max-width: 560px; width: 100%; max-height: 85vh; overflow-y: auto; }
.modal-head { padding: 1.2rem 1.4rem; border-bottom: 1px solid var(--steel-line); display:flex; justify-content: space-between; align-items: center; }
.modal-head h3 { text-transform: none; font-size: 1.15rem; }
.modal-close { background:none; border:none; font-size: 1.4rem; cursor: pointer; color: var(--steel); line-height: 1; }
.modal-body { padding: 1.4rem; }
.modal-body dt { font-family: var(--font-mono); font-size: 0.7rem; text-transform: uppercase; color: var(--steel); letter-spacing: 0.05em; margin-top: 0.9em; }
.modal-body dd { margin: 0.25em 0 0; font-size: 0.95rem; }
.modal-actions { padding: 1rem 1.4rem; border-top: 1px solid var(--steel-line); display: flex; gap: 0.6rem; justify-content: flex-end; }
.btn-outline { background: none; color: var(--ink); border: 2px solid var(--steel-line); width: auto; }
.btn-outline:hover { border-color: var(--ink); }
.btn-danger { background: var(--white); color: #A32323; border: 2px solid #A32323; width: auto; }
.btn-danger:hover { background: #A32323; color: var(--white); }
.btn-auto { width: auto; }

/* ---- Live Chat page ---- */

.chat-layout { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 4rem); border: 1px solid var(--steel-line); }
@media (max-width: 800px) { .chat-layout { grid-template-columns: 1fr; height: auto; } }

.conv-list { border-right: 1px solid var(--steel-line); overflow-y: auto; background: var(--white); }
.conv-item { padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--steel-line); cursor: pointer; }
.conv-item:hover { background: var(--paper-dim); }
.conv-item.active { background: var(--paper-dim); border-left: 3px solid var(--red); }
.conv-item .conv-name { font-family: var(--font-display); font-weight: 700; font-size: 0.95rem; display:flex; justify-content: space-between; align-items:center; }
.conv-item .conv-preview { font-size: 0.82rem; color: var(--steel); margin-top: 0.2em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .conv-time { font-family: var(--font-mono); font-size: 0.68rem; color: var(--steel); margin-top: 0.3em; }

.thread-panel { display: flex; flex-direction: column; background: var(--paper-dim); }
.thread-head { background: var(--white); border-bottom: 1px solid var(--steel-line); padding: 1rem 1.3rem; }
.thread-head h3 { text-transform: none; font-size: 1.05rem; }
.thread-body { flex: 1; overflow-y: auto; padding: 1.2rem; display: flex; flex-direction: column; gap: 0.7rem; }
.thread-msg { max-width: 70%; padding: 0.6em 0.9em; border-radius: 10px; font-size: 0.92rem; line-height: 1.4; }
.thread-msg.from-visitor { align-self: flex-start; background: var(--white); border: 1px solid var(--steel-line); border-bottom-left-radius: 2px; }
.thread-msg.from-admin { align-self: flex-end; background: var(--red); color: var(--white); border-bottom-right-radius: 2px; }
.thread-foot { display: flex; border-top: 1px solid var(--steel-line); background: var(--white); }
.thread-foot input { flex: 1; border: none; padding: 0.9em 1.1em; font-family: var(--font-body); font-size: 0.95rem; outline: none; }
.thread-foot button { background: var(--red); color: var(--white); border: none; padding: 0 1.4em; cursor: pointer; font-family: var(--font-display); font-weight: 700; text-transform: uppercase; font-size: 0.88rem; }
.thread-foot button:hover { background: var(--red-dark); }
.thread-foot button:disabled { opacity: 0.6; cursor: not-allowed; }
.thread-empty { margin: auto; color: var(--steel); text-align: center; padding: 2rem; }
.unread-dot { display:inline-block; width:8px; height:8px; border-radius:50%; background: var(--red); }
