/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg:        #0f1117;
  --bg2:       #161b26;
  --bg3:       #1e2535;
  --bg4:       #252d40;
  --border:    #2a3349;
  --border2:   #3a4560;
  --text:      #d4daf0;
  --text2:     #8b95b0;
  --text3:     #5a6580;
  --accent:    #4d7cfe;
  --accent2:   #3a62d8;
  --accent-g:  #34c89a;
  --danger:    #e05c6e;
  --warning:   #f0a033;
  --radius:    12px;
  --radius-sm: 8px;
  --mono:      'JetBrains Mono', monospace;
  --sans:      'Noto Sans SC', sans-serif;
  --shadow:    0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}
input, button, textarea { font-family: inherit; }
button { cursor: pointer; border: none; outline: none; }
input, textarea { outline: none; }
.hidden { display: none !important; }

/* ── Auth Screen ───────────────────────────────────────────────────────────── */
.auth-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 1000;
}
.auth-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 48px 40px;
  width: 360px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: fadeUp 0.4s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.auth-logo { font-size: 48px; margin-bottom: 12px; }
.auth-title {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 4px;
}
.auth-sub { color: var(--text3); font-size: 13px; margin: 6px 0 28px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--mono);
  transition: border-color 0.2s;
}
.auth-form input:focus { border-color: var(--accent); }
.auth-form button {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 15px;
  font-weight: 500;
  transition: background 0.2s, transform 0.1s;
}
.auth-form button:hover { background: var(--accent2); }
.auth-form button:active { transform: scale(0.98); }
.auth-error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* ── App Layout ────────────────────────────────────────────────────────────── */
.app { min-height: 100vh; }
.page { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Header ────────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 64px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: blur(8px);
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-logo { font-size: 22px; }
.header-title {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 2px;
}
.header-right { display: flex; align-items: center; gap: 12px; }

.search-wrap {
  display: flex; align-items: center;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  gap: 8px;
  transition: border-color 0.2s;
}
.search-wrap:focus-within { border-color: var(--accent); }
.search-icon { color: var(--text3); font-size: 18px; }
#search-input {
  background: none;
  border: none;
  color: var(--text);
  font-size: 14px;
  width: 200px;
  padding: 8px 0;
}
#search-input::placeholder { color: var(--text3); }

.btn-add {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s, transform 0.1s;
}
.btn-add:hover { background: var(--accent2); }
.btn-add:active { transform: scale(0.97); }

.btn-export {
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 14px;
  transition: all 0.2s;
}
.btn-export:hover { border-color: var(--accent-g); color: var(--accent-g); }

.btn-back {
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 14px;
  transition: all 0.2s;
}
.btn-back:hover { border-color: var(--border2); color: var(--text); }

.btn-edit-svc {
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 14px;
  transition: all 0.2s;
}
.btn-edit-svc:hover { border-color: var(--border2); color: var(--text); }

/* ── Main ──────────────────────────────────────────────────────────────────── */
.main { flex: 1; padding: 32px 28px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ── Services Grid ─────────────────────────────────────────────────────────── */
.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

.service-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: fadeUp 0.3s ease;
}
.service-card:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(77,124,254,0.15);
}
.service-card-actions {
  position: absolute;
  top: 10px; right: 10px;
  display: flex; gap: 6px;
  opacity: 0;
  transition: opacity 0.2s;
}
.service-card:hover .service-card-actions { opacity: 1; }
.card-action-btn {
  background: var(--bg4);
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 28px; height: 28px;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.card-action-btn:hover { background: var(--bg3); }
.card-action-btn.delete:hover { border-color: var(--danger); color: var(--danger); }

.service-logo {
  width: 72px; height: 72px;
  border-radius: 16px;
  overflow: hidden;
  background: var(--bg3);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.service-logo img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.logo-placeholder {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--sans);
  line-height: 1;
}
.service-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  text-align: center;
  word-break: break-word;
}
.service-path {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text3);
  background: var(--bg3);
  border-radius: 4px;
  padding: 2px 8px;
}
.service-count {
  font-size: 12px;
  color: var(--text3);
}

/* ── Service Header Logo ───────────────────────────────────────────────────── */
.svc-header-logo {
  width: 32px; height: 32px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg3);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.svc-header-logo img { width: 100%; height: 100%; object-fit: cover; }
.svc-header-logo .logo-placeholder { font-size: 14px; }

/* ── Accounts List ─────────────────────────────────────────────────────────── */
.accounts-list { display: flex; flex-direction: column; gap: 16px; }

.account-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  animation: fadeUp 0.3s ease;
}
.account-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.account-card-index {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text3);
  background: var(--bg3);
  border-radius: 4px;
  padding: 2px 8px;
}
.account-card-actions { display: flex; gap: 8px; }
.btn-icon {
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  transition: all 0.15s;
}
.btn-icon:hover { border-color: var(--border2); color: var(--text); }
.btn-icon.delete:hover { border-color: var(--danger); color: var(--danger); }

.account-fields { display: flex; flex-direction: column; gap: 10px; }
.field-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.field-label {
  font-size: 12px;
  color: var(--text3);
  min-width: 72px;
  flex-shrink: 0;
}
.field-value {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  flex: 1;
  word-break: break-all;
}
.field-copy {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 4px;
  transition: all 0.15s;
  flex-shrink: 0;
}
.field-copy:hover { background: var(--bg4); color: var(--accent-g); }
.field-copy.copied { color: var(--accent-g); }

/* ── Empty State ───────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text3);
}
.empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state p { font-size: 15px; margin-bottom: 20px; }
.empty-state button {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 10px 24px;
  font-size: 14px;
  transition: background 0.2s;
}
.empty-state button:hover { background: var(--accent2); }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
  backdrop-filter: blur(3px);
}
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 520px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow);
  animation: fadeUp 0.25s ease;
}
.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 32px; height: 32px;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.modal-close:hover { color: var(--text); border-color: var(--border2); }

.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 24px;
}

/* ── Form ──────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 7px;
  font-weight: 500;
}
.form-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.2s;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text3); }
.form-input.mono { font-family: var(--mono); }
.form-hint { font-size: 12px; color: var(--text3); margin-top: 5px; }

/* Logo upload in form */
.logo-upload-wrap {
  display: flex; align-items: center; gap: 16px;
}
.logo-preview {
  width: 64px; height: 64px;
  border-radius: 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.logo-preview img { width: 100%; height: 100%; object-fit: cover; }
.logo-preview .logo-placeholder { font-size: 24px; color: var(--accent); font-weight: 700; }
.logo-upload-btn {
  background: var(--bg3);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text2);
  padding: 8px 16px;
  font-size: 13px;
  transition: all 0.2s;
}
.logo-upload-btn:hover { border-color: var(--accent); color: var(--accent); }
#logo-file-input { display: none; }

/* Dynamic fields in account modal */
.dynamic-fields { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.dynamic-field-row {
  display: flex; gap: 8px; align-items: center;
}
.dynamic-field-row input:first-child { width: 120px; flex-shrink: 0; }
.dynamic-field-row input:last-of-type { flex: 1; }
.btn-remove-field {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--danger);
  border-radius: 6px;
  width: 32px; height: 36px;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.btn-remove-field:hover { background: var(--bg4); }
.btn-add-field {
  background: none;
  border: 1px dashed var(--border);
  color: var(--text3);
  border-radius: var(--radius-sm);
  padding: 8px;
  font-size: 13px;
  width: 100%;
  transition: all 0.2s;
}
.btn-add-field:hover { border-color: var(--accent-g); color: var(--accent-g); }

/* Form footer */
.form-footer {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--accent2); }
.btn-secondary {
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: 14px;
  transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--border2); color: var(--text); }
.btn-danger {
  background: rgba(224,92,110,0.12);
  color: var(--danger);
  border: 1px solid rgba(224,92,110,0.3);
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: 14px;
  transition: all 0.2s;
  margin-right: auto;
}
.btn-danger:hover { background: rgba(224,92,110,0.2); }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 10px 22px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 9999;
  box-shadow: var(--shadow);
  animation: toastIn 0.25s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border2); }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .header { padding: 0 16px; }
  .main { padding: 20px 16px; }
  .services-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  #search-input { width: 120px; }
}
