*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
::placeholder { color: var(--text-dim); opacity: 1; }

/* ─── THEME: LIGHT (default) ─── */
:root {
  --bg: #eef1f7;
  --surface: #ffffff;
  --surface-2: #f3f5fa;
  --surface-3: #e9edf5;
  --border: #e2e7f0;
  --border-strong: #d2d9e6;
  --accent: #2d7ff9;
  --accent-hover: #1f6fe8;
  --accent-soft: rgba(45,127,249,0.10);
  --success: #1faf6a;
  --success-soft: rgba(31,175,106,0.12);
  --danger: #e2483d;
  --danger-soft: rgba(226,72,61,0.10);
  --text: #1a2233;
  --text-mid: #46506a;
  --text-dim: #8a93a8;
  --shadow-sm: 0 1px 2px rgba(20,30,60,0.06);
  --shadow: 0 4px 16px rgba(20,30,60,0.08);
  --shadow-lg: 0 12px 40px rgba(20,30,60,0.14);
  --radius: 10px;
  --radius-sm: 7px;
}

/* ─── THEME: DARK ─── */
[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d2e;
  --surface-2: #21243a;
  --surface-3: #2a2e48;
  --border: #2e3154;
  --border-strong: #3a3e63;
  --accent: #5b8cff;
  --accent-hover: #7aa3ff;
  --accent-soft: rgba(91,140,255,0.14);
  --success: #4caf82;
  --success-soft: rgba(76,175,130,0.16);
  --danger: #e05252;
  --danger-soft: rgba(224,82,82,0.16);
  --text: #e6e9f5;
  --text-mid: #b3bad2;
  --text-dim: #7a7fa8;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow: 0 4px 16px rgba(0,0,0,0.35);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.5);
}

html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px; line-height: 1.45;
  transition: background 0.25s, color 0.25s;
}

/* ─── LOGIN ─── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 40px; width: 380px; box-shadow: var(--shadow-lg); position: relative;
}
.login-box h1 { font-size: 26px; font-weight: 700; margin-bottom: 6px; color: var(--text); letter-spacing: -0.5px; }
.login-subtitle { color: var(--text-dim); margin-bottom: 30px; font-size: 13.5px; }
.login-form { display: flex; flex-direction: column; gap: 18px; }
.login-form .btn-full { margin-top: 6px; }
.login-error { background: var(--danger-soft); color: var(--danger); border-radius: var(--radius); padding: 11px 14px; margin-bottom: 4px; font-size: 13px; }
.login-logo {
  width: 52px; height: 52px; border-radius: 14px; margin-bottom: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  display: flex; align-items: center; justify-content: center; font-size: 26px; box-shadow: var(--shadow);
}

/* ─── MAIN LAYOUT ─── */
#app { display: grid; grid-template-columns: 320px 1fr 320px; height: 100vh; overflow: hidden; padding: 14px; gap: 14px; }

/* ─── PANELS ─── */
.panel, #panel-center {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; overflow: hidden; padding: 18px;
}
#panel-center { gap: 16px; }

.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-shrink: 0; }
.panel-header h2 { font-size: 16px; font-weight: 650; color: var(--text); letter-spacing: -0.2px; }
.header-actions { display: flex; align-items: center; gap: 8px; }

.badge { background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px; min-width: 26px; text-align: center; }

/* ─── FORMS ─── */
.form-group { display: flex; flex-direction: column; gap: 7px; }
.form-group label { font-size: 11.5px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; }
.form-row { display: flex; gap: 12px; }
.flex1 { flex: 1; }

textarea, input[type="number"], input[type="text"], input[type="password"] {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 11px 13px; font-size: 14px; outline: none; width: 100%;
  font-family: inherit; transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
textarea:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
textarea { resize: vertical; min-height: 80px; }
#group-input { flex: 1; min-height: 130px; resize: none; font-family: 'SF Mono', Menlo, Consolas, monospace; font-size: 12.5px; line-height: 1.6; }
#message-text { min-height: 110px; }

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius); border: 1px solid var(--border-strong);
  font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.15s; text-decoration: none;
  color: var(--text-mid); background: var(--surface-2); white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--text-dim); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); box-shadow: var(--shadow-sm); }
.btn-success:hover:not(:disabled) { background: var(--success); border-color: var(--success); filter: brightness(1.07); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); box-shadow: var(--shadow-sm); }
.btn-danger:hover:not(:disabled) { background: var(--danger); border-color: var(--danger); filter: brightness(1.07); }
.btn-danger-outline { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn-danger-outline:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
.btn-full { width: 100%; }
.btn-lg { padding: 11px 24px; font-size: 14px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { padding: 7px 9px; font-size: 15px; line-height: 1; }

.panel-actions { display: flex; gap: 8px; margin: 10px 0; flex-shrink: 0; }

/* ─── UPLOAD AREA ─── */
.upload-area { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 22px; cursor: pointer; transition: border-color 0.15s, background 0.15s; background: var(--surface-2); }
.upload-area:hover, .upload-area.dragover { border-color: var(--accent); background: var(--accent-soft); }
.upload-placeholder { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text-dim); font-size: 13px; }
.upload-icon { font-size: 26px; }
.image-preview { display: flex; align-items: center; gap: 14px; }
.image-preview img { max-height: 84px; max-width: 130px; border-radius: 8px; object-fit: cover; box-shadow: var(--shadow-sm); }

/* ─── ITEM LISTS ─── */
.item-list { list-style: none; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 7px; margin-top: 6px; padding-right: 2px; }
.item-list::-webkit-scrollbar, .progress-log::-webkit-scrollbar { width: 6px; }
.item-list::-webkit-scrollbar-track, .progress-log::-webkit-scrollbar-track { background: transparent; }
.item-list::-webkit-scrollbar-thumb, .progress-log::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.item-list::-webkit-scrollbar-thumb:hover, .progress-log::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
.empty-hint { color: var(--text-dim); font-size: 13px; padding: 10px 2px; }

/* Account item */
.account-item { display: flex; align-items: center; gap: 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 9px 11px; transition: border-color 0.15s; }
.account-item:hover { border-color: var(--border-strong); }
.account-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: var(--surface-3); flex-shrink: 0; }
.account-avatar-placeholder { width: 36px; height: 36px; border-radius: 50%; background: var(--surface-3); display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.account-name { flex: 1; font-size: 13.5px; font-weight: 500; color: var(--text); line-height: 1.3; overflow: hidden; }
.account-name small { color: var(--text-dim); font-size: 11px; font-weight: 400; display: block; }
.btn-remove { background: none; border: none; color: var(--text-dim); cursor: pointer; padding: 5px; font-size: 14px; line-height: 1; border-radius: 6px; transition: all 0.15s; }
.btn-remove:hover { color: var(--danger); background: var(--danger-soft); }

/* Group item */
.group-item { display: flex; align-items: center; gap: 10px; padding: 9px 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; transition: border-color 0.15s; }
.group-item:hover { border-color: var(--border-strong); }
.group-item .status-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.status-dot.pending { background: var(--text-dim); animation: pulse 1.4s ease-in-out infinite; }
.status-dot.resolved { background: var(--success); }
.status-dot.error { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }
.group-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: 500; }
.group-label small { color: var(--text-dim); font-size: 11px; font-weight: 400; display: block; }

/* ─── MAILING CENTER ─── */
.mailing-form { display: flex; flex-direction: column; gap: 15px; flex-shrink: 0; }
.controls { display: flex; gap: 10px; }
.controls .btn { flex: 1; }

.progress-section { flex: 1; display: flex; flex-direction: column; gap: 10px; overflow: hidden; border-top: 1px solid var(--border); padding-top: 14px; }
.progress-stats { font-size: 13px; color: var(--text-mid); flex-shrink: 0; font-weight: 500; }
.text-danger { color: var(--danger); }
.stat-status { margin-left: 8px; font-weight: 600; }
.progress-bar-wrap { height: 8px; background: var(--surface-3); border-radius: 4px; flex-shrink: 0; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-hover)); border-radius: 4px; transition: width 0.3s; }

.progress-log { list-style: none; overflow-y: auto; flex: 1; font-size: 12px; font-family: 'SF Mono', Menlo, Consolas, monospace; display: flex; flex-direction: column; gap: 1px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.log-item { padding: 3px 0; line-height: 1.4; }
.log-item.success { color: var(--success); }
.log-item.error { color: var(--danger); }
.log-item.info { color: var(--text-dim); }

/* ─── RESPONSIVE ─── */
@media (max-width: 1000px) {
  #app { grid-template-columns: 1fr; grid-auto-rows: minmax(min-content, max-content); height: auto; min-height: 100vh; overflow: auto; }
  .panel, #panel-center { max-height: 80vh; }
}
