/* ================================================================
   Rehab Center — Back-Office  |  Dark Theme
   ================================================================ */

:root {
  --bg: #0b0d14;
  --surface: #13161f;
  --surface2: #1a1d2a;
  --border: #252836;
  --accent: #4f8ef7;
  --accent2: #00d4aa;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --text: #e2e8f0;
  --muted: #6b7280;
  --radius: 8px;
  --sidebar-w: 220px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---- LOGIN ---- */
#view-login {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
#view-login.hidden { display: none; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 380px;
  max-width: 90vw;
  text-align: center;
}
.login-card h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 4px; }
.login-card > p { color: var(--muted); font-size: .85rem; margin-bottom: 24px; }
.login-card .form-group { text-align: left; margin-bottom: 16px; }
.login-card label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 6px; }
.login-card input {
  width: 100%; padding: 10px 12px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: .9rem;
  outline: none; transition: border .2s;
}
.login-card input:focus { border-color: var(--accent); }
#login-error { color: var(--red); font-size: .8rem; margin-top: 12px; min-height: 1.2em; }

/* ---- BUTTONS ---- */
.btn-primary {
  width: 100%; padding: 10px; border: none; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-weight: 600; font-size: .9rem;
  cursor: pointer; transition: opacity .2s;
}
.btn-primary:hover { opacity: .85; }

.btn-publish {
  padding: 8px 18px; border: none; border-radius: var(--radius);
  background: var(--green); color: #fff; font-weight: 600; font-size: .85rem;
  cursor: pointer; transition: opacity .2s;
}
.btn-publish:hover { opacity: .85; }

.btn-discard {
  padding: 8px 18px; border: 1px solid var(--border); border-radius: var(--radius);
  background: transparent; color: var(--muted); font-weight: 500; font-size: .85rem;
  cursor: pointer; transition: border-color .2s, color .2s;
}
.btn-discard:hover { border-color: var(--red); color: var(--red); }

.btn-sm {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: transparent; color: var(--text); font-size: .8rem; cursor: pointer;
  transition: border-color .2s;
}
.btn-sm:hover { border-color: var(--accent); }

.btn-danger {
  padding: 6px 12px; border: 1px solid var(--red); border-radius: var(--radius);
  background: transparent; color: var(--red); font-size: .8rem; cursor: pointer;
}
.btn-danger:hover { background: var(--red); color: #fff; }

.btn-add {
  padding: 6px 14px; border: 1px dashed var(--border); border-radius: var(--radius);
  background: transparent; color: var(--accent); font-size: .8rem; cursor: pointer;
}
.btn-add:hover { border-color: var(--accent); }

/* ---- SIDEBAR ---- */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100vh;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 16px; font-weight: 700; font-size: .95rem;
}
.logo-icon {
  width: 28px; height: 28px; border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 0 0 12px; }
.nav-section-label {
  padding: 16px 16px 6px; font-size: .65rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
.nav-item {
  display: block; padding: 8px 16px; font-size: .85rem;
  color: var(--muted); text-decoration: none;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active {
  color: var(--accent); border-left-color: var(--accent);
  background: rgba(79, 142, 247, .08);
}

.sidebar-user {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px; border-top: 1px solid var(--border);
  font-size: .8rem;
}
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 700; color: #fff;
}
.sidebar-user span { flex: 1; }
#btn-logout {
  background: none; border: none; color: var(--muted); font-size: 1.1rem;
  cursor: pointer; padding: 4px;
}
#btn-logout:hover { color: var(--red); }

/* ---- CONTENT AREA ---- */
#content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

#content-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  background: var(--surface); min-height: 56px;
}
#breadcrumb { font-size: .95rem; font-weight: 600; }
#content-actions { display: flex; align-items: center; gap: 10px; }

.draft-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .78rem; color: var(--yellow); font-weight: 500;
}
.draft-badge::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: var(--yellow); display: inline-block;
}

#editor-area {
  flex: 1; overflow-y: auto; padding: 20px 24px;
}

/* ---- EDITOR SECTIONS (collapsible cards) ---- */
.editor-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.editor-section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; cursor: pointer; user-select: none;
  font-weight: 600; font-size: .9rem;
  transition: background .15s;
}
.editor-section-header:hover { background: var(--surface2); }
.editor-section-header .chevron {
  transition: transform .2s; font-size: .7rem; color: var(--muted);
}
.editor-section.collapsed .editor-section-body { display: none; }
.editor-section.collapsed .chevron { transform: rotate(-90deg); }

.editor-section-body { padding: 0 18px 18px; }

/* ---- FORM ELEMENTS ---- */
.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: .75rem; color: var(--muted);
  margin-bottom: 5px; font-weight: 500;
}
.field input[type="text"],
.field input[type="email"],
.field input[type="url"],
.field input[type="number"],
.field textarea,
.field select {
  width: 100%; padding: 9px 12px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: .85rem;
  font-family: inherit; outline: none; transition: border .2s;
  resize: vertical;
}
.field input:focus,
.field textarea:focus,
.field select:focus { border-color: var(--accent); }

.field textarea { min-height: 80px; }

.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* Color picker */
.color-field {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px;
}
.color-field input[type="color"] {
  width: 40px; height: 36px; border: 1px solid var(--border);
  border-radius: var(--radius); background: none; cursor: pointer;
  padding: 2px;
}
.color-field .color-label { font-size: .82rem; min-width: 100px; }
.color-field .color-hex {
  font-size: .78rem; color: var(--muted); font-family: monospace;
}

/* Card-like sub-items */
.sub-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.sub-card-header {
  font-size: .8rem; font-weight: 600; color: var(--accent);
  margin-bottom: 10px;
}

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 32px; text-align: center; cursor: pointer;
  transition: border-color .2s, background .2s;
  margin-bottom: 16px;
}
.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent); background: rgba(79,142,247,.05);
}
.upload-zone p { color: var(--muted); font-size: .85rem; }
.upload-zone input[type="file"] { display: none; }

.upload-gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.upload-item {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; position: relative;
}
.upload-item img {
  width: 100%; height: 100px; object-fit: cover;
  border-radius: 4px; margin-bottom: 6px;
}
.upload-item .upload-name {
  font-size: .75rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.upload-item .upload-delete {
  position: absolute; top: 6px; right: 6px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--red); color: #fff; border: none;
  font-size: .7rem; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  opacity: 0; transition: opacity .2s;
}
.upload-item:hover .upload-delete { opacity: 1; }

/* Submissions table */
.submissions-table {
  width: 100%; border-collapse: collapse; font-size: .82rem;
}
.submissions-table th {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border);
  color: var(--muted); font-weight: 600; font-size: .75rem;
  text-transform: uppercase; letter-spacing: .04em;
}
.submissions-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  color: var(--text);
}
.submissions-table tr:hover td { background: var(--surface2); }

.status-sent { color: var(--green); }
.status-failed { color: var(--red); }

/* Email list items */
.email-list-item {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.email-list-item input { flex: 1; }

/* ---- LOGIN TRANSITION / LOADER ---- */
#view-login {
  transition: opacity .4s ease, transform .4s ease;
}
#view-login.fade-out {
  opacity: 0;
  transform: scale(1.02);
  pointer-events: none;
}

#app-loader {
  position: fixed; inset: 0; z-index: 999;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: var(--bg);
  opacity: 0; transition: opacity .3s ease;
}
#app-loader.visible { opacity: 1; }
#app-loader.fade-out { opacity: 0; }

.loader-ring {
  width: 48px; height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: loaderSpin .8s linear infinite;
}
.loader-text {
  margin-top: 16px; font-size: .85rem; color: var(--muted);
  letter-spacing: .04em;
}
.loader-bar {
  width: 200px; height: 3px; margin-top: 12px;
  background: var(--border); border-radius: 2px; overflow: hidden;
}
.loader-bar-fill {
  height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px; animation: loaderProgress 1.2s ease-out forwards;
}
@keyframes loaderSpin { to { transform: rotate(360deg); } }
@keyframes loaderProgress { to { width: 100%; } }

#app {
  opacity: 0; transition: opacity .5s ease .1s;
}
#app.visible { opacity: 1; }

/* ---- TOAST ---- */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  padding: 12px 20px; border-radius: var(--radius);
  font-size: .85rem; font-weight: 500;
  z-index: 9999; animation: toastIn .25s ease-out;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast-success { background: var(--green); color: #fff; }
.toast-error { background: var(--red); color: #fff; }
.toast-info { background: var(--accent); color: #fff; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- MOBILE ---- */
@media (max-width: 768px) {
  #sidebar {
    position: fixed; left: -260px; z-index: 100;
    transition: left .25s; width: 260px;
  }
  #sidebar.open { left: 0; }
  #content { width: 100%; }
  #content-header { padding: 12px 16px; }
  #editor-area { padding: 16px; }
  .field-row { flex-direction: column; gap: 0; }
  .field-grid { grid-template-columns: 1fr; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* Category selector */
.category-selector {
  display: flex; gap: 8px; margin-bottom: 16px;
}
.category-selector button {
  padding: 6px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: transparent; color: var(--muted); font-size: .8rem; cursor: pointer;
}
.category-selector button.active {
  border-color: var(--accent); color: var(--accent); background: rgba(79,142,247,.1);
}

/* Language toggle */
.lang-btn {
  transition: all .15s;
}
.lang-btn.active {
  background: rgba(79,142,247,.1) !important;
  color: var(--accent) !important;
  border-color: var(--accent) !important;
}
