:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #0f172a;
  --border: #334155;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #10b981;
  --primary-hover: #059669;
  --secondary: #3b82f6;
  --danger: #ef4444;
  --warning: #f59e0b;
  --wa-bubble: #005c4b;
  --radius: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Vazirmatn', system-ui, -apple-system, sans-serif;
}

body {
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.center {
  text-align: center;
  padding: 1.5rem 0;
}

/* Login Overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at top, #1e293b, #090d16);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.2rem;
  width: 100%;
  max-width: 410px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.login-logo {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.login-card h2 {
  font-size: 1.3rem;
  margin-bottom: 0.3rem;
}

.login-card form {
  margin-top: 1.4rem;
  text-align: right;
}

/* Layout */
.app-container {
  max-width: 1380px;
  margin: 0 auto;
  padding: 1.2rem 1.5rem 3rem;
}

.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 1rem 1.4rem;
  border-radius: var(--radius);
  margin-bottom: 1.2rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand-icon {
  font-size: 2rem;
}

.brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.clock-chip {
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}

.status-badge .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.status-connected {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.35);
}
.status-connected .dot { background: #10b981; box-shadow: 0 0 8px #10b981; }

.status-qr {
  background: rgba(245, 158, 11, 0.16);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.4);
}
.status-qr .dot { background: #f59e0b; }

.status-disconnected {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.35);
}
.status-disconnected .dot { background: #ef4444; }

/* Navigation Tabs */
.tabs-nav {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.2rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
}

.tab-btn {
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.7rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text);
  border-color: #475569;
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.badge-alert {
  background: var(--warning);
  color: #000;
  font-size: 0.72rem;
  padding: 0.1rem 0.45rem;
  border-radius: 99px;
  font-weight: 700;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.4rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-icon {
  font-size: 1.8rem;
  background: rgba(255, 255, 255, 0.04);
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 0.15rem;
}

/* Tab Content & Cards */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.main-grid {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 1.4rem;
  align-items: start;
}

@media (max-width: 1024px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 1.2rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--border);
}

.card-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

/* Forms */
.form-group {
  margin-bottom: 1.1rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 0.45rem;
  color: #e2e8f0;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.45rem;
}

.label-row label {
  margin-bottom: 0;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
}

/* Message Type Selector */
.type-selector {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(115px, 1fr));
  gap: 0.5rem;
}

.type-btn {
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.6rem 0.5rem;
  border-radius: 8px;
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.type-btn.active {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
  border-color: var(--primary);
}

/* Upload Box */
.upload-box {
  position: relative;
  border: 2px dashed #475569;
  border-radius: 10px;
  padding: 1.2rem;
  text-align: center;
  background: rgba(15, 23, 42, 0.5);
  cursor: pointer;
  transition: border-color 0.2s;
}

.upload-box:hover {
  border-color: var(--primary);
}

.upload-box input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-icon {
  font-size: 1.8rem;
  display: block;
  margin-bottom: 0.3rem;
}

.selected-file {
  margin-top: 0.6rem;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  padding: 0.45rem 0.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* Voice Recorder Box */
.voice-recorder-box {
  margin-top: 0.75rem;
  padding: 0.8rem;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 8px;
}

.recorder-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.record-timer {
  font-weight: 700;
  color: #f87171;
  font-family: monospace;
  font-size: 1rem;
}

#recordedAudioPreview {
  width: 100%;
  margin-top: 0.6rem;
  height: 36px;
}

/* Emoji bar */
.emoji-bar {
  display: flex;
  gap: 0.3rem;
}

.emoji-bar button {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.15rem 0.45rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.emoji-bar button:hover {
  border-color: var(--primary);
}

/* WhatsApp Bubble Preview */
.wa-preview-container {
  background: #0b141a;
  border: 1px solid #222e35;
  border-radius: 10px;
  padding: 0.9rem;
  margin-bottom: 1.1rem;
}

.wa-preview-title {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
}

.wa-bubble {
  background: var(--wa-bubble);
  color: #e9edef;
  border-radius: 10px 0 10px 10px;
  padding: 0.65rem 0.85rem;
  max-width: 90%;
  font-size: 0.88rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.wa-bubble-media {
  background: rgba(0, 0, 0, 0.22);
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  margin-bottom: 0.45rem;
  font-size: 0.82rem;
  color: #a7f3d0;
}

/* Days of week */
.days-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(82px, 1fr));
  gap: 0.45rem;
}

.day-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.4rem;
  cursor: pointer;
  font-size: 0.84rem;
  user-select: none;
}

.day-chip input {
  display: none;
}

.day-chip:has(input:checked) {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--primary);
  color: #34d399;
  font-weight: 700;
}

/* Radio Group */
.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 400;
  cursor: pointer;
}

/* Time Adder & Chips */
.time-adder {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.time-adder input[type="time"] {
  max-width: 170px;
}

.chips-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.time-chip {
  background: rgba(59, 130, 246, 0.18);
  border: 1px solid rgba(59, 130, 246, 0.4);
  color: #93c5fd;
  padding: 0.3rem 0.7rem;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.time-chip button {
  background: none;
  border: none;
  color: #f87171;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

/* Groups Checklist */
.search-input {
  margin-bottom: 0.5rem;
}

.sm-search {
  max-width: 220px;
  margin-bottom: 0;
}

.groups-checklist {
  max-height: 210px;
  overflow-y: auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
}

.group-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 400;
  margin-bottom: 0.2rem;
}

.group-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.group-item-left {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

/* Schedule Cards List */
.schedules-list {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.sched-item {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  transition: border-color 0.2s;
}

.sched-item.disabled {
  opacity: 0.6;
}

.sched-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.sched-title {
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.type-badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.55rem;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.07);
  color: #cbd5e1;
}

.sched-caption {
  font-size: 0.86rem;
  color: var(--text-muted);
  margin-bottom: 0.7rem;
  white-space: pre-wrap;
  max-height: 68px;
  overflow: hidden;
}

.sched-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.85rem;
  font-size: 0.8rem;
}

.meta-pill {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
}

.sched-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-top: 0.7rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.action-btns {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

/* Connection Tab */
.connection-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 1.4rem;
}

@media (max-width: 900px) {
  .connection-grid {
    grid-template-columns: 1fr;
  }
}

.connection-box {
  margin: 1.2rem 0;
  padding: 1.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: center;
}

.qr-img {
  width: 250px;
  height: 250px;
  border-radius: 12px;
  background: #fff;
  padding: 10px;
  margin: 1rem auto;
  display: block;
}

.connection-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  padding: 0.75rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  background: rgba(0, 0, 0, 0.15);
}

.log-success {
  color: #34d399;
  font-weight: 600;
}

.log-error {
  color: #f87171;
  font-weight: 600;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.1rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #334155;
  color: #fff;
}
.btn-secondary:hover {
  background: #475569;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger-outline {
  background: transparent;
  border: 1px solid var(--danger);
  color: #f87171;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 0.85rem 1.2rem;
  font-size: 0.98rem;
}

.btn-block {
  width: 100%;
}

.btn-link {
  background: none;
  border: none;
  color: #38bdf8;
  cursor: pointer;
  font-size: 0.82rem;
}

.alert {
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.alert-error {
  background: rgba(239, 68, 68, 0.16);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.settings-card {
  max-width: 650px;
}

.block-hint {
  display: block;
  margin-bottom: 1.1rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  background: #1e293b;
  border: 1px solid var(--primary);
  color: #fff;
  padding: 0.85rem 1.3rem;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  z-index: 2000;
  font-size: 0.9rem;
  font-weight: 600;
}
