/* ======================================================
   Refly Ops Dashboard  –  Custom Stylesheet
   Bootstrap 5.3 base + custom admin theme
   ====================================================== */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --sidebar-width  : 245px;
  --sidebar-bg     : #1e2a3a;
  --sidebar-text   : #c8d6e5;
  --sidebar-active : #3d9be9;
  --topbar-height  : 58px;
  --topbar-bg      : #ffffff;
  --body-bg        : #f0f4f8;
  --card-radius    : 12px;
  --status-ok      : #28a745;
  --status-issue   : #dc3545;
  --status-pending : #6c757d;
  --accent         : #3d9be9;
  --transition     : 0.25s ease;
}

/* ── Dark Mode ─────────────────────────────────────────────── */
body.dark-mode {
  --topbar-bg  : #161b22;
  --body-bg    : #0d1117;
  --card-bg    : #161b22;
  --text-color : #e6edf3;
  --border-col : #30363d;
  --input-bg   : #21262d;
  --table-str  : #1c2128;
}

/* ── Base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  background-color : var(--body-bg);
  font-family      : 'Segoe UI', system-ui, -apple-system, sans-serif;
  color            : #333;
  transition       : background-color var(--transition), color var(--transition);
}

body.dark-mode { background-color: var(--body-bg); color: var(--text-color); }

/* ── Layout Wrapper ─────────────────────────────────────────── */
.wrapper { display: flex; min-height: 100vh; position: relative; }

/* ── Sidebar ────────────────────────────────────────────────── */
#sidebar {
  width         : var(--sidebar-width);
  min-height    : 100vh;
  background    : var(--sidebar-bg);
  color         : var(--sidebar-text);
  position      : fixed;
  top           : 0;
  left          : 0;
  z-index       : 1050;
  display       : flex;
  flex-direction: column;
  transition    : transform var(--transition);
  overflow-y    : auto;
  overflow-x    : hidden;
}

#sidebar.collapsed { transform: translateX(-100%); }

.sidebar-header {
  padding       : 18px 20px 14px;
  border-bottom : 1px solid rgba(255,255,255,.1);
  flex-shrink   : 0;
}

.logo-wrap { display: flex; align-items: center; gap: 10px; }

.logo-text {
  font-size  : 1.15rem;
  font-weight: 700;
  color      : #fff;
  letter-spacing: .4px;
  white-space: nowrap;
}

.sidebar-nav {
  padding: 10px 0;
  flex   : 1;
}

.sidebar-nav .nav-section {
  font-size     : .65rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color         : rgba(200,214,229,.4);
  padding       : 10px 20px 4px;
  font-weight   : 600;
}

.sidebar-nav li a {
  display        : flex;
  align-items    : center;
  gap            : 11px;
  padding        : 11px 20px;
  color          : var(--sidebar-text);
  text-decoration: none;
  font-size      : .875rem;
  transition     : background var(--transition), color var(--transition);
  border-left    : 3px solid transparent;
  white-space    : nowrap;
}

.sidebar-nav li a:hover {
  background        : rgba(255,255,255,.07);
  color             : #fff;
  border-left-color : var(--sidebar-active);
}

.sidebar-nav li.active a {
  background        : rgba(61,155,233,.18);
  color             : #fff;
  border-left-color : var(--sidebar-active);
  font-weight       : 600;
}

.sidebar-footer {
  padding      : 14px 20px;
  border-top   : 1px solid rgba(255,255,255,.08);
  font-size    : .8rem;
  color        : var(--sidebar-text);
  flex-shrink  : 0;
}

/* ── Content Area ───────────────────────────────────────────── */
#content {
  margin-left: var(--sidebar-width);
  flex       : 1;
  transition : margin-left var(--transition);
  min-width  : 0;
}

#content.full-width { margin-left: 0; }

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  height       : var(--topbar-height);
  background   : var(--topbar-bg);
  border-bottom: 1px solid rgba(0,0,0,.07);
  box-shadow   : 0 2px 6px rgba(0,0,0,.05);
  position     : sticky;
  top          : 0;
  z-index      : 1040;
  display      : flex;
  align-items  : center;
  padding      : 0 16px;
}

body.dark-mode .topbar {
  background   : var(--topbar-bg);
  border-color : var(--border-col);
}

/* ── Main Content ───────────────────────────────────────────── */
.main-content { min-height: calc(100vh - var(--topbar-height)); }

/* ── Summary / Stat Cards ───────────────────────────────────── */
.stat-card {
  border        : none;
  border-radius : var(--card-radius);
  padding       : 18px 20px;
  transition    : transform var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
  transform  : translateY(-2px);
  box-shadow : 0 8px 24px rgba(0,0,0,.1) !important;
}

.stat-icon {
  width          : 50px;
  height         : 50px;
  border-radius  : 12px;
  display        : flex;
  align-items    : center;
  justify-content: center;
  font-size      : 1.3rem;
  flex-shrink    : 0;
}

.stat-number { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat-label  { font-size: .75rem; text-transform: uppercase; letter-spacing: .4px; opacity: .75; }

/* ── Task Cards ─────────────────────────────────────────────── */
.task-card {
  border        : 1px solid #e4e8ed;
  border-radius : var(--card-radius);
  background    : #fff;
  transition    : box-shadow var(--transition);
  margin-bottom : 14px;
  overflow      : hidden;
}

.task-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); }

.task-card.status-ok          { border-left: 4px solid var(--status-ok); }
.task-card.status-issue        { border-left: 4px solid var(--status-issue); }
.task-card.status-not_checked  { border-left: 4px solid #dee2e6; }

.task-card .card-header {
  background   : transparent;
  border-bottom: 1px solid #f0f2f5;
  padding      : 13px 18px;
  display      : flex;
  align-items  : center;
  justify-content: space-between;
  flex-wrap    : wrap;
  gap          : 8px;
}

.task-card .card-footer {
  background   : transparent;
  border-top   : 1px solid #f0f2f5;
  padding      : 10px 18px;
}

.task-number {
  width          : 28px;
  height         : 28px;
  border-radius  : 50%;
  background     : #e9ecef;
  display        : inline-flex;
  align-items    : center;
  justify-content: center;
  font-size      : .78rem;
  font-weight    : 700;
  color          : #555;
  flex-shrink    : 0;
}

/* Keep visible breathing room between labels and controls in task cards */
.task-form .form-label { margin-bottom: .35rem; }

.task-form .form-control,
.task-form .form-select { padding-top: .35rem; padding-bottom: .35rem; }

/* Dark mode – cards */
body.dark-mode .task-card,
body.dark-mode .stat-card,
body.dark-mode .card {
  background      : var(--card-bg);
  border-color    : var(--border-col);
  color           : var(--text-color);
}

body.dark-mode .task-card .card-header,
body.dark-mode .task-card .card-footer { border-color: var(--border-col); }

body.dark-mode .task-number { background: #2d3748; color: #adb5bd; }

/* ── Status Badges ──────────────────────────────────────────── */
.status-badge {
  display       : inline-block;
  font-size     : .72rem;
  padding       : 3px 10px;
  border-radius : 20px;
  font-weight   : 600;
  text-transform: uppercase;
  letter-spacing: .3px;
  white-space   : nowrap;
}

.status-badge.ok          { background: #d4edda; color: #155724; }
.status-badge.issue       { background: #f8d7da; color: #721c24; }
.status-badge.not_checked { background: #e2e3e5; color: #383d41; }

/* ── Issue Field (conditional visibility) ───────────────────── */
.issue-field {
  display  : none;
  animation: fadeSlideIn .2s ease;
}

.issue-field.visible { display: block; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Link Builder ───────────────────────────────────────────── */
.link-item {
  display  : flex;
  gap      : 6px;
  margin-bottom: 6px;
  animation: fadeSlideIn .15s ease;
}

.link-item input { flex: 1; min-width: 0; }

/* ── File Preview ───────────────────────────────────────────── */
.file-preview-container { display: flex; flex-wrap: wrap; gap: 6px; min-height: 0; }

/* Paste flash: brief green glow when a screenshot is pasted */
@keyframes pasteFlash {
  0%   { box-shadow: 0 0 0 3px rgba(40,167,69,.6); border-color: #28a745; }
  100% { box-shadow: none; border-color: #dee2e6; }
}
.file-upload-wrap.paste-flash .form-control {
  animation: pasteFlash 0.6s ease forwards;
}

.file-preview-item {
  position      : relative;
  width         : 70px;
  height        : 70px;
  border-radius : 8px;
  overflow      : hidden;
  border        : 1px solid #dee2e6;
  background    : #f8f9fa;
  display       : flex;
  align-items   : center;
  justify-content: center;
  flex-shrink   : 0;
}

.file-preview-item img   { width: 100%; height: 100%; object-fit: cover; }
.file-preview-item .ficon { font-size: 1.6rem; color: #6c757d; }

/* ── Thumbnail in reports ───────────────────────────────────── */
.thumbnail-preview {
  width       : 48px;
  height      : 48px;
  object-fit  : cover;
  border-radius: 6px;
  border      : 1px solid #dee2e6;
  cursor      : pointer;
  transition  : transform var(--transition);
  display     : block;
}

.thumbnail-preview:hover { transform: scale(1.12); }

/* ── Save button states ─────────────────────────────────────── */
.btn-save-task { min-width: 90px; transition: all var(--transition); }
.btn-save-task.saving { opacity: .75; cursor: wait; }
.btn-save-task.saved  { background: var(--status-ok) !important; border-color: var(--status-ok) !important; color: #fff !important; }

/* ── Charts ─────────────────────────────────────────────────── */
.chart-container { position: relative; height: 210px; }

/* ── Server Monitor ─────────────────────────────────────────── */
.server-metric-box {
  border: 1px solid #e4e8ed;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  height: 100%;
}

.server-metric-box .label {
  font-size: .72rem;
  text-transform: uppercase;
  color: #6c757d;
  letter-spacing: .3px;
}

.server-metric-box .value {
  font-weight: 700;
  font-size: .95rem;
  margin-top: 4px;
}

.server-metric-progress {
  height: 6px;
  background: #eef1f4;
}

/* ── Reports Table ──────────────────────────────────────────── */
.report-table th {
  background     : #f4f6f8;
  font-size      : .78rem;
  text-transform : uppercase;
  letter-spacing : .4px;
  white-space    : nowrap;
}

.report-table tr.has-issue { background-color: #fff5f5 !important; }

body.dark-mode .report-table th                            { background: var(--table-str); color: var(--text-color) !important; }
body.dark-mode .report-table td                            { color: var(--text-color); }
body.dark-mode .table-striped > tbody > tr:nth-of-type(odd) > * { background-color: var(--table-str); color: var(--text-color); }
body.dark-mode .report-table tr.has-issue                  { background-color: #2d1b1b !important; }
body.dark-mode .server-metric-box                          { background: var(--card-bg); border-color: var(--border-col); }
body.dark-mode .server-metric-box .label                   { color: #9aa4af; }

/* ── Timeline ───────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 28px; }

.timeline::before {
  content  : '';
  position : absolute;
  left     : 9px;
  top      : 0;
  bottom   : 0;
  width    : 2px;
  background: #dee2e6;
}

.timeline-item { position: relative; margin-bottom: 16px; }

.timeline-item::before {
  content   : '';
  position  : absolute;
  left      : -23px;
  top       : 14px;
  width     : 10px;
  height    : 10px;
  border-radius: 50%;
  background: var(--status-issue);
  border    : 2px solid #fff;
  box-shadow: 0 0 0 2px var(--status-issue);
}

/* ── Dark mode – form controls ──────────────────────────────── */
body.dark-mode .form-control,
body.dark-mode .form-select,
body.dark-mode .input-group-text {
  background-color: var(--input-bg);
  border-color    : var(--border-col);
  color           : var(--text-color);
}

body.dark-mode .form-control::placeholder { color: #6c757d; }

body.dark-mode .form-control:focus,
body.dark-mode .form-select:focus {
  background-color: var(--input-bg);
  border-color    : var(--accent);
  color           : var(--text-color);
  box-shadow      : 0 0 0 .2rem rgba(61,155,233,.3);
}

body.dark-mode .modal-content {
  background: var(--card-bg);
  border-color: var(--border-col);
  color: var(--text-color);
}

/* ── Monitor Dashboard (monitor.php) ────────────────────────── */
.monitor-card {
  background    : #fff;
  border        : 1px solid #e4e8ed;
  border-radius : var(--card-radius);
  padding       : 18px 20px 14px;
  height        : 100%;
  transition    : border-color var(--transition), box-shadow var(--transition);
}

.monitor-card.status-online  { border-left: 4px solid var(--status-ok);    }
.monitor-card.status-offline { border-left: 4px solid var(--status-issue);  }
.monitor-card.status-loading { border-left: 4px solid #adb5bd;              }

.monitor-card.status-offline { opacity: .85; }

.monitor-metrics { display: flex; flex-direction: column; gap: 0; }

.monitor-metric-row {
  display        : flex;
  align-items    : center;
  justify-content: space-between;
  padding        : 5px 0;
  border-bottom  : 1px solid #f0f3f6;
  gap            : 8px;
}

.monitor-metric-row:last-child { border-bottom: none; }

.monitor-metric-label {
  font-size  : .75rem;
  color      : #6c757d;
  white-space: nowrap;
  flex-shrink: 0;
}

.monitor-metric-value {
  font-size  : .82rem;
  font-weight: 600;
  text-align : right;
  word-break : break-all;
}

.monitor-mini-progress {
  height      : 5px;
  border-radius: 3px;
  background  : #eef1f4;
  margin-top  : 2px;
}

.monitor-status-badge { font-size: .72rem; white-space: nowrap; flex-shrink: 0; }

/* Dark mode – monitor */
body.dark-mode .monitor-card                { background: var(--card-bg); border-color: var(--border-col); }
body.dark-mode .monitor-card.status-online  { border-left-color: var(--status-ok); }
body.dark-mode .monitor-card.status-offline { border-left-color: var(--status-issue); }
body.dark-mode .monitor-metric-row          { border-bottom-color: var(--border-col); }
body.dark-mode .monitor-metric-label        { color: #9aa4af; }
body.dark-mode .monitor-metric-value        { color: var(--text-color); }
body.dark-mode .monitor-mini-progress       { background: #2d3340; }

/* ── Login Page ─────────────────────────────────────────────── */
.login-page {
  background  : linear-gradient(135deg, #1e2a3a 0%, #2c4a6e 55%, #1e2a3a 100%);
  min-height  : 100vh;
  display     : flex;
  align-items : center;
  justify-content: center;
}

.login-container { width: 100%; max-width: 430px; padding: 16px; }

.login-card { border-radius: 16px; }

.login-logo {
  display         : inline-flex;
  align-items     : center;
  justify-content : center;
  width           : 64px;
  height          : 64px;
  background      : rgba(230,126,34,.15);
  border-radius   : 50%;
  font-size       : 2rem;
  color           : #e67e22;
}

/* ── Sidebar Overlay (mobile) ───────────────────────────────── */
.sidebar-overlay {
  display  : none;
  position : fixed;
  inset    : 0;
  background: rgba(0,0,0,.5);
  z-index  : 1049;
}

.sidebar-overlay.visible { display: block; }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #adb5bd; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #6c757d; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 767.98px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.mobile-open { transform: translateX(0); }
  #content { margin-left: 0 !important; }
  .stat-number { font-size: 1.5rem; }
}

/* ── Print ──────────────────────────────────────────────────── */
@media print {
  #sidebar, .topbar, .no-print { display: none !important; }
  #content { margin-left: 0 !important; }
  .task-card { page-break-inside: avoid; }
  body { background: #fff !important; color: #000 !important; }
}
