:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e2e4e9;
  --text: #1b1e24;
  --muted: #6b7280;
  --brand: #2f6fed;
  --brand-dark: #1f52b8;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--brand); }

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

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

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.login-card p.subtitle {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 14px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 14px 0 6px;
}

input[type="text"],
input[type="email"],
input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}

input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
}

button.primary {
  background: var(--brand);
  color: #fff;
  width: 100%;
  margin-top: 20px;
}
button.primary:hover { background: var(--brand-dark); }
button.primary:disabled { opacity: 0.6; cursor: default; }

button.secondary {
  background: #eef1f6;
  color: var(--text);
}

button.danger {
  background: #fdecec;
  color: var(--danger);
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
  min-height: 16px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* ---------- App shell ---------- */

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

.sidebar {
  width: 220px;
  background: #14161c;
  color: #d7dae0;
  flex-shrink: 0;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  font-weight: 700;
  color: #fff;
  font-size: 16px;
  margin-bottom: 24px;
}

.sidebar nav a {
  display: block;
  color: #b6bac4;
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 2px;
}
.sidebar nav a.active, .sidebar nav a:hover { background: #23262f; color: #fff; }

.sidebar .who {
  margin-top: auto;
  font-size: 12px;
  color: #8b8f99;
  border-top: 1px solid #2a2d36;
  padding-top: 14px;
}
.sidebar .who button {
  margin-top: 8px;
  width: 100%;
  background: #23262f;
  color: #d7dae0;
}

.main {
  flex: 1;
  padding: 28px 32px;
  overflow-y: auto;
}

.main h1 { font-size: 20px; margin: 0 0 4px; }
.main p.subtitle { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 { font-size: 15px; margin: 0 0 14px; }

.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row .field { flex: 1; min-width: 180px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge.active { background: #e7f6ec; color: var(--success); }
.badge.inactive { background: #f3f4f6; color: var(--muted); }
.badge.open { background: #e8f0fe; color: var(--brand-dark); }
.badge.closed { background: #f3f4f6; color: var(--muted); }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #14161c;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s ease;
  pointer-events: none;
  max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #4a1414; }

/* ---------- Agent chat layout ---------- */

.chat-shell { display: flex; height: calc(100vh - 40px); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: #fff; }

.conv-list { width: 300px; border-right: 1px solid var(--border); overflow-y: auto; flex-shrink: 0; }
.conv-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.conv-item:hover { background: #f7f8fa; }
.conv-item.selected { background: #eef3ff; }
.conv-item .name { font-weight: 600; font-size: 14px; }
.conv-item .preview { color: var(--muted); font-size: 12.5px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .time { color: var(--muted); font-size: 11px; float: right; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; display:flex; justify-content: space-between; align-items:center; }
.chat-messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }

.msg { max-width: 62%; padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.4; }
.msg.customer { background: #f0f1f4; align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.agent { background: var(--brand); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .meta { font-size: 10.5px; opacity: 0.65; margin-top: 4px; }

.chat-input { border-top: 1px solid var(--border); padding: 12px; display: flex; gap: 10px; }
.chat-input textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  min-height: 44px;
  max-height: 120px;
}

.empty-state { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--muted); font-size: 14px; text-align: center; padding: 20px; }
