:root {
  --bg: #FAF7F5;
  --surface: #FFFFFF;
  --surface-alt: #F3ECE9;
  --primary: #B85D6E;
  --primary-dark: #9B4758;
  --text: #261D20;
  --muted: #76676C;
  --border: #E8DDE0;
  --ok: #2E8B57;
  --ok-bg: #E6F4EC;
  --warn: #D9822B;
  --warn-bg: #FDF2E4;
  --err: #C93B4B;
  --err-bg: #FCE8EA;
  --input-bg: #FFFFFF;
  --msg-ai-bg: #F4E6EA;
  --radius: 14px;
}

[data-theme="dark"] {
  --bg: #141215;
  --surface: #1E1B20;
  --surface-alt: #2A252C;
  --primary: #D47486;
  --primary-dark: #B85D6E;
  --text: #F2ECEE;
  --muted: #A99CA1;
  --border: #342D35;
  --ok: #55C486;
  --ok-bg: #1B3326;
  --warn: #F0A44C;
  --warn-bg: #362817;
  --err: #F06A78;
  --err-bg: #3A1D22;
  --input-bg: #262228;
  --msg-ai-bg: #2E2328;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.auth-card h1 { margin: 0 0 6px; font-size: 1.5rem; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-title { font-weight: 700; font-size: 1.05rem; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.main-content {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 14px 86px;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 6px 2px calc(6px + env(safe-area-inset-bottom));
}
.nav-item {
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.72rem;
  gap: 2px;
  padding: 4px 6px;
  cursor: pointer;
}
.nav-item.active { color: var(--primary); font-weight: 600; }

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.stat-value { font-size: 1.45rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.82rem; color: var(--muted); }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  background: var(--surface-alt);
  color: var(--text);
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-err { background: var(--err-bg); color: var(--err); }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin: 10px 0 4px;
}
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  background: var(--input-bg);
  color: var(--text);
}
textarea { min-height: 76px; resize: vertical; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #FFF; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface-alt); color: var(--text); }
.btn-danger { background: var(--err-bg); color: var(--err); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-full { width: 100%; margin-top: 14px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.list-item {
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.list-item:last-child { border-bottom: none; }

.service-item {
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.service-item:last-child { border-bottom: none; }
.service-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.service-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.chat-box {
  max-height: 360px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 0.92rem;
}
.msg-client { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); }
.msg-ai { align-self: flex-end; background: var(--msg-ai-bg); }
.msg-master { align-self: flex-end; background: var(--primary); color: #FFF; }

.error-box {
  margin-top: 12px;
  padding: 10px;
  border-radius: 10px;
  background: var(--err-bg);
  color: var(--err);
  font-size: 0.88rem;
}

.toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.88rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.tabs-inline { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
