@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }

:root[data-theme="dark"] {
  --bg: #0d0d0f;
  --surface: #16161a;
  --surface2: #1e1e24;
  --border: #2a2a35;
  --accent: #c084fc;
  --accent2: #9333ea;
  --accent-btn: #8b5cf6;
  --accent-btn-hover: #7c3aed;
  --text: #f0f0f5;
  --muted: #6b6b80;
  --success: #4ade80;
  --error: #f87171;
  --warning: #fbbf24;
  --shadow: rgba(0,0,0,0.4);
  --card-bg: #18181f;
}

:root[data-theme="light"] {
  --bg: #f4f4f7;
  --surface: #ffffff;
  --surface2: #f0f0f5;
  --border: #e0e0ea;
  --accent: #9333ea;
  --accent2: #7c3aed;
  --accent-btn: #7c3aed;
  --accent-btn-hover: #6d28d9;
  --text: #111118;
  --muted: #8888a0;
  --success: #16a34a;
  --error: #dc2626;
  --warning: #d97706;
  --shadow: rgba(0,0,0,0.1);
  --card-bg: #ffffff;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  height: 100%;
  display: flex;
  flex-direction: column;
  transition: background 0.2s, color 0.2s;
}

/* Navigation & Views */
.view-container {
  display: none;
  flex: 1;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.view-container.active {
  display: flex;
}

header {
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  height: 52px;
  flex-shrink: 0;
}

header .logo {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--accent2), #818cf8);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
}

header h1 { font-size: 14px; font-weight: 600; letter-spacing: -0.3px; white-space: nowrap; }
header .acc-sub { font-size: 11px; color: var(--muted); white-space: nowrap; }

.btn-header-analytics {
  background: linear-gradient(135deg, var(--accent-btn), var(--accent-btn-hover));
  color: white;
  border: none;
  border-radius: 8px;
  padding: 6px 14px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
  margin-left: 8px;
  box-shadow: 0 2px 6px rgba(124, 58, 237, 0.25);
}
.btn-header-analytics:hover { transform: translateY(-1px); opacity: 0.95; }

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0;
}

.header-seg {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border-left: 1px solid var(--border);
  height: 52px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.header-seg strong { font-size: 11px; font-weight: 600; color: var(--text); }

.header-seg input[type="number"] {
  width: 46px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border-left: 1px solid var(--border);
  height: 52px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  user-select: none;
}
.theme-toggle:hover { color: var(--text); }

.main {
  display: flex;
  flex: 1;
  height: calc(100vh - 52px);
  overflow: hidden;
  position: relative;
}

/* Accounts Panel */
.accounts-panel {
  width: 380px;
  min-width: 270px;
  max-width: 80vw;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.panel-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.panel-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-header h2 { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; }

.account-count {
  background: var(--accent2);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
}

.panel-header-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.btn-panel-action {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 10px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}
.btn-panel-action:hover {
  border-color: var(--accent2);
  color: var(--accent2);
  background: rgba(147,51,234,0.06);
}

.btn-delete-action {
  color: var(--error);
  border-color: rgba(248, 113, 113, 0.3);
}
.btn-delete-action:hover {
  border-color: var(--error) !important;
  background: rgba(248, 113, 113, 0.08) !important;
  color: var(--error) !important;
}

.accounts-list { overflow-y: auto; flex: 1; padding: 6px; }

.account-item {
  border-radius: 10px;
  margin-bottom: 4px;
  border: 1px solid var(--border);
  background: var(--surface2);
  transition: border-color 0.2s;
  position: relative;
}

.account-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
}

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-btn), #818cf8);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: white;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}

.account-name   { font-size: 12px; font-weight: 600; }
.account-number { font-size: 10px; color: var(--muted); }

.acc-checkbox {
  width: 16px; height: 16px;
  border-radius: 4px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
  font-size: 10px;
  color: transparent;
}
.acc-checkbox.checked { background: var(--accent2); border-color: var(--accent2); color: white; }

.account-right { margin-left: auto; display: flex; align-items: center; gap: 6px; position: relative; }

.three-dot-btn {
  width: 26px; height: 26px;
  border-radius: 6px; border: 1px solid transparent;
  background: transparent; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; cursor: pointer; transition: all 0.2s;
}
.three-dot-btn:hover { background: var(--surface); color: var(--text); border-color: var(--border); }

.acc-dropdown-menu {
  display: none; position: absolute; right: 0; top: 32px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px var(--shadow);
  z-index: 50; width: 160px; padding: 4px;
}
.acc-dropdown-menu.visible { display: block; }

.acc-dropdown-item {
  padding: 8px 10px; font-size: 11px; font-weight: 500;
  color: var(--text); border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; gap: 8px; transition: background 0.15s;
}
.acc-dropdown-item:hover { background: var(--surface2); color: var(--accent2); }

.chevron { color: var(--muted); font-size: 11px; transition: transform 0.2s; line-height: 1; }
.account-item.open .chevron { transform: rotate(180deg); }

.account-dropdown { display: none; padding: 0 12px 12px; border-top: 1px solid var(--border); }
.account-item.open .account-dropdown { display: block; }

.account-caption {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; color: var(--text);
  font-family: 'Inter', sans-serif; font-size: 12px; resize: none; min-height: 72px;
}

.post-panel {
  flex: 1; display: flex; flex-direction: column; overflow-y: auto;
  padding: 16px 20px; gap: 16px; min-width: 0;
}

.upload-zone {
  border: 2px dashed var(--border); border-radius: 14px; padding: 28px 24px;
  text-align: center; cursor: pointer; transition: all 0.2s; background: var(--surface);
}
.upload-zone:hover { border-color: var(--accent2); background: rgba(147,51,234,0.04); }

.post-btn {
  width: 100%; padding: 14px;
  background: linear-gradient(135deg, var(--accent-btn), #818cf8);
  border: none; border-radius: 12px; color: white;
  font-family: 'Inter', sans-serif; font-size: 14px; font-weight: 700;
  cursor: pointer; transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
}
.post-btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; background: var(--border); color: var(--muted); }

/* Post Progress Status Box */
.posting-status-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: none;
  flex-direction: column;
  gap: 12px;
}
.posting-status-box.active { display: flex; }

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: var(--surface2);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent2), #818cf8);
  transition: width 0.3s ease;
}

.posting-log-list {
  max-height: 160px;
  overflow-y: auto;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.log-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--surface2);
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* PRIMARY PURPLE BUTTON CLASS */
.btn-primary-purple {
  background: var(--accent-btn) !important;
  color: white !important;
  border: none !important;
  border-radius: 8px;
  padding: 6px 12px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  box-shadow: 0 2px 6px rgba(124, 58, 237, 0.25);
  white-space: nowrap;
  user-select: none;
}
.btn-primary-purple:hover {
  background: var(--accent-btn-hover) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(124, 58, 237, 0.35);
}

/* Subpage Header */
.subpage-header {
  height: 52px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 14px;
  flex-shrink: 0;
}

.btn-back-nav {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px; font-family: 'Inter', sans-serif;
  font-size: 12px; font-weight: 600; color: var(--text); cursor: pointer;
}

.subpage-title { font-size: 15px; font-weight: 700; color: var(--text); }

.subpage-content { flex: 1; overflow-y: auto; padding: 20px 24px; background: var(--bg); }

/* Profile Banner */
.profile-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 24px;
  position: relative;
}

.avatar-column {
  display: flex; flex-direction: column; align-items: center; gap: 12px; flex-shrink: 0;
}

.profile-avatar-container {
  position: relative; width: 92px; height: 92px; border-radius: 50%;
  overflow: hidden; cursor: pointer; box-shadow: 0 4px 14px var(--shadow);
}

.profile-avatar-large {
  width: 100%; height: 100%;
  background: linear-gradient(135deg, var(--accent2), #818cf8);
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-weight: 700; color: white;
  background-size: cover; background-position: center;
}

.avatar-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 18px; opacity: 0; transition: opacity 0.2s;
}
.profile-avatar-container:hover .avatar-overlay { opacity: 1; }

.profile-info { flex: 1; min-width: 0; }

.inline-edit-row {
  display: flex; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap;
}

.profile-handle { font-size: 22px; font-weight: 700; word-break: break-all; }
.profile-name { font-size: 13px; color: var(--muted); font-weight: 500; }

.bio-inline-container {
  margin-top: 8px;
  line-height: 1.6;
  font-size: 13px;
  color: var(--text);
}

.profile-bio-text {
  display: inline;
  white-space: pre-wrap;
  word-break: break-word;
}

.btn-bio-inline {
  display: inline-flex !important;
  margin-left: 8px;
  vertical-align: middle;
}

.meta-pills-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.meta-pill {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px; font-size: 11px;
  font-weight: 600; color: var(--text); display: inline-flex; align-items: center; gap: 5px;
}
.meta-pill-verified {
  color: #0284c7; border-color: rgba(56, 189, 248, 0.4); background: rgba(56, 189, 248, 0.08);
}
:root[data-theme="dark"] .meta-pill-verified { color: #38bdf8; }

.meta-pill-unverified {
  color: var(--muted); border-color: var(--border); background: var(--surface2);
}

.profile-meta-strip {
  display: flex; 
  gap: 16px; 
  margin-top: 18px; 
  padding-top: 14px; 
  border-top: 1px solid var(--border);
}

.profile-meta-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-meta-item strong { font-size: 16px; font-weight: 700; color: var(--text); }
.profile-meta-item span { font-size: 13px; color: var(--muted); font-weight: 500; }

.live-sync-badge {
  position: absolute; top: 16px; right: 18px;
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; color: var(--success);
  background: rgba(74, 222, 128, 0.1); border: 1px solid rgba(74, 222, 128, 0.2);
  padding: 4px 10px; border-radius: 20px;
}

/* Section Header Controls & Collapsible Chevron */
.section-control-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.section-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.section-title-text {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.btn-section-chevron {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.15s;
}
.btn-section-chevron:hover { background: var(--border); }
.btn-section-chevron.collapsed { transform: rotate(-90deg); }

.section-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.format-segmented-control {
  display: inline-flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.btn-format-opt {
  background: transparent;
  border: none;
  padding: 4px 10px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-format-opt.active {
  background: var(--accent-btn);
  color: white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

.filter-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  outline: none;
  cursor: pointer;
}
.filter-select:focus { border-color: var(--accent2); }

/* Posts Grid Layout Modes */
.posts-grid {
  display: grid;
  gap: 16px;
  margin-bottom: 28px;
  transition: all 0.25s ease;
}
.posts-grid.mode-3x3 { grid-template-columns: repeat(3, 1fr); }
.posts-grid.mode-4x4 { grid-template-columns: repeat(4, 1fr); }
.posts-grid.mode-list { grid-template-columns: 1fr; }

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: transform 0.2s, border-color 0.2s;
}
.post-card:hover { border-color: var(--accent2); transform: translateY(-2px); }

.post-thumb {
  height: 160px;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; position: relative;
}
.mode-list .post-card { display: flex; align-items: center; }
.mode-list .post-thumb { width: 120px; height: 90px; flex-shrink: 0; }
.mode-list .post-body { flex: 1; }

.post-badge {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.65); color: white;
  font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px;
}

.post-body { padding: 12px; }
.post-caption { font-size: 12px; color: var(--text); line-height: 1.4; height: 34px; overflow: hidden; }
.post-stats-row { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 10px; font-weight: 600; }

/* Comments Grid & Modes */
.comments-list {
  display: grid;
  gap: 10px;
  margin-bottom: 28px;
  transition: all 0.25s ease;
}
.comments-list.mode-3x3 { grid-template-columns: repeat(3, 1fr); }
.comments-list.mode-4x4 { grid-template-columns: repeat(4, 1fr); }
.comments-list.mode-list { grid-template-columns: 1fr; }

.comment-item { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; }
.comment-user { font-weight: 600; font-size: 11px; color: var(--accent2); margin-bottom: 2px; }
.comment-text { font-size: 12px; color: var(--text); line-height: 1.4; }
.comment-date { font-size: 10px; color: var(--muted); margin-top: 4px; }

/* Modal Overlay System */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  z-index: 100; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.visible { display: flex; }

.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; width: 100%; max-width: 480px;
  box-shadow: 0 20px 40px var(--shadow); overflow: hidden; display: flex; flex-direction: column;
}

.modal-header { padding: 18px 20px 14px; border-bottom: 1px solid var(--border); }
.modal-title-row { display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 15px; font-weight: 700; color: var(--text); }
.modal-close-x { background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; }
.modal-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }

.modal-body { padding: 20px; overflow-y: auto; max-height: 60vh; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.form-input, .form-textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; color: var(--text);
  font-family: 'Inter', sans-serif; font-size: 13px;
}
.form-input:focus, .form-textarea:focus { outline: none; border-color: var(--accent2); }

.modal-footer {
  padding: 14px 20px; border-top: 1px solid var(--border);
  background: var(--surface2); display: flex; justify-content: flex-end; gap: 10px;
}

.btn-modal-save {
  background: var(--accent-btn); border: none; border-radius: 8px;
  color: white; padding: 8px 18px; font-family: 'Inter', sans-serif;
  font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.2s;
  box-shadow: 0 2px 6px rgba(124, 58, 237, 0.25);
}
.btn-modal-save:disabled {
  opacity: 0.45; cursor: not-allowed; box-shadow: none; background: var(--border) !important; color: var(--muted) !important;
}

.btn-cancel-modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); padding: 8px 16px;
  font-family: 'Inter', sans-serif; font-size: 12px; font-weight: 500; cursor: pointer;
}

.notice-banner {
  border-radius: 8px; padding: 10px 12px; font-size: 11px; font-weight: 600;
  margin-bottom: 14px; display: flex; align-items: center; gap: 8px; line-height: 1.4;
}
.notice-warning {
  background: rgba(217, 119, 6, 0.12); border: 1px solid rgba(217, 119, 6, 0.35); color: var(--warning);
}
.notice-info {
  background: rgba(147, 51, 234, 0.12); border: 1px solid rgba(147, 51, 234, 0.3); color: var(--accent2);
}

.image-preview-box {
  width: 120px; height: 120px; border-radius: 50%;
  border: 2px dashed var(--accent2); margin: 10px auto; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface2); background-size: cover; background-position: center;
}

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.stat-title { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 24px; font-weight: 700; margin: 6px 0 2px; color: var(--text); }
.stat-change { font-size: 11px; font-weight: 600; }
.stat-up { color: var(--success); }
