/* =====================================================================
   Checkup — calm light operations-dashboard visual system (Phase 1)
   Light theme first. Soft neutral background, white cards, subtle borders,
   soft shadows, calm indigo-blue primary, soft readable status colors.
   RTL-native: logical properties throughout. No CDN, no heavy animation.
   Class names + DOM hooks are preserved from the original markup.
   ===================================================================== */

:root {
  /* Surfaces & background */
  --bg: #F6F8FB;
  --surface: #FFFFFF;
  --surface-muted: #F1F4F9;
  --border: #E6EAF0;
  --border-strong: #D7DEE8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --shadow-hover: 0 4px 12px rgba(16, 24, 40, .08);

  /* Text */
  --text: #1F2A37;
  --text-2: #475467;
  --muted: #667085;
  --faint: #98A2B3;

  /* Brand / actions */
  --primary: #3B5BDB;
  --primary-hover: #2F4BC4;
  --primary-soft: #EEF2FF;
  --accent: #0E9384;
  --accent-soft: #E6F4F1;

  /* Status — soft, readable */
  --success: #067647;
  --success-bg: #ECFDF3;
  --success-border: #ABEFC6;
  --warning: #B54708;
  --warning-bg: #FFFAEB;
  --warning-border: #FEDF89;
  --danger: #B42318;
  --danger-bg: #FEF3F2;
  --danger-border: #FECDCA;
  --info: #175CD3;
  --info-bg: #EFF8FF;
  --info-border: #B2DDFF;
  --neutral: #475467;
  --neutral-bg: #F2F4F7;
  --neutral-border: #E4E7EC;

  /* Radius */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Arabic", "Noto Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  line-height: 1.6;
  font-size: 0.9375rem;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

code {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-size: .9em;
  color: var(--text-2);
}

/* --- App shell (sidebar + content) ---------------------------------- */
.app-shell { display: flex; align-items: stretch; min-height: 100vh; }

.sidebar {
  flex: 0 0 240px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px 16px;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.brand {
  display: block;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--text);
  padding: 6px 8px 14px;
}
.brand:hover { color: var(--text); }

.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-nav a {
  display: block;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text-2);
  font-weight: 500;
  transition: background-color .12s ease, color .12s ease;
}
.side-nav a:hover { background: var(--surface-muted); color: var(--text); }
.side-nav a.active { background: var(--primary-soft); color: var(--primary); }

.side-user {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.side-logout { color: var(--muted); font-weight: 500; font-size: .9rem; }
.side-logout:hover { color: var(--danger); }

.app-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.app-main .container { flex: 1 0 auto; }

/* --- Layout --------------------------------------------------------- */
.container { width: 100%; max-width: 1100px; margin: 28px auto; padding: 0 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

h1 { margin: 0 0 8px; font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; }
h2 { margin: 0 0 14px; font-size: 1.125rem; font-weight: 600; color: var(--text); }

.muted { color: var(--muted); }
.hint { font-size: .85rem; color: var(--muted); }

/* --- Forms / inputs ------------------------------------------------- */
.upload-form { display: flex; flex-direction: column; gap: 16px; margin: 18px 0 4px; }
.file-field span { display: block; margin-bottom: 6px; color: var(--text-2); font-size: .8125rem; font-weight: 500; }

input[type=file],
input[type=text],
input[type=password] {
  background: var(--surface-muted);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text);
  width: 100%;
  font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input[type=file]:focus,
input[type=text]:focus,
input[type=password]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
input[type=file]::file-selector-button {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  margin-inline-end: 12px;
  cursor: pointer;
  font: inherit;
}
input[type=file]::file-selector-button:hover { border-color: var(--primary); color: var(--primary); }

.checkbox { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: .9rem; }
.checkbox input { accent-color: var(--primary); width: 16px; height: 16px; }

/* --- Buttons -------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: .9375rem;
  font-weight: 500;
  line-height: 1.2;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }

.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }

.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger-border); background: var(--danger-bg); color: var(--danger); }

.btn.small { padding: 5px 12px; font-size: .85rem; }

.btn:disabled,
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--border-strong); color: var(--text); }
.btn.primary:disabled:hover { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Loading state: hide the label and show a small centred spinner. */
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; opacity: 1; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  width: 15px;
  height: 15px;
  margin-block-start: -8px;
  margin-inline-start: -8px;
  border: 2px solid var(--muted);
  border-top-color: transparent;
  border-radius: 50%;
  animation: btn-spin .6s linear infinite;
}
.btn.primary.is-loading::after { border-color: rgba(255, 255, 255, .6); border-top-color: transparent; }
@keyframes btn-spin { to { transform: rotate(360deg); } }

.cfg-note {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .85rem;
  color: var(--muted);
}

/* --- Tables --------------------------------------------------------- */
table.jobs { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.jobs thead th { background: var(--surface-muted); }
table.jobs th, table.jobs td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  text-align: start;
  vertical-align: middle;
}
table.jobs th { color: var(--muted); font-weight: 600; font-size: .8125rem; }
table.jobs thead th:first-child { border-start-start-radius: var(--radius); }
table.jobs thead th:last-child { border-start-end-radius: var(--radius); }
table.jobs tbody tr { transition: background-color .12s ease; }
table.jobs tbody tr:hover { background: var(--surface-muted); }
table.jobs tbody tr:last-child td { border-bottom: none; }

.ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.cell-action { text-align: end; }

/* Filter toolbar (jobs page) */
.table-toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.toolbar-input {
  flex: 1 1 200px;
  min-width: 0;
  max-width: 320px;
  background: var(--surface-muted);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--text);
  font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.toolbar-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.toolbar-select { flex: 0 0 auto; max-width: 220px; }
.no-results { margin-top: 14px; }

/* Empty state */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-2); }
.empty-state .empty-icon { font-size: 2rem; margin-bottom: 8px; opacity: .65; }
.empty-state .empty-title { font-size: 1.05rem; font-weight: 600; color: var(--text); margin: 0 0 4px; }
.empty-state .muted { margin: 0; }
.empty-state .btn { margin-top: 16px; }

/* --- Badges (status) ------------------------------------------------ */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 500;
  border: 1px solid var(--neutral-border);
  background: var(--neutral-bg);
  color: var(--neutral);
  white-space: nowrap;
}
/* Completed -> success */
.status-Completed { color: var(--success); background: var(--success-bg); border-color: var(--success-border); }
/* In-progress -> info */
.status-Running, .status-Cleaning, .status-Validating, .status-Queued, .status-Retrying, .status-Stopping {
  color: var(--info); background: var(--info-bg); border-color: var(--info-border);
}
/* Paused / waiting -> warning */
.status-Paused, .status-QuotaWait { color: var(--warning); background: var(--warning-bg); border-color: var(--warning-border); }
/* Failures / billing stop -> danger */
.status-Failed, .status-StoppedBilling { color: var(--danger); background: var(--danger-bg); border-color: var(--danger-border); }
/* Idle / neutral end states */
.status-Pending, .status-Stopped, .status-Cancelled { color: var(--neutral); background: var(--neutral-bg); border-color: var(--neutral-border); }

/* --- Progress ------------------------------------------------------- */
.progress { background: var(--surface-muted); border-radius: 999px; height: 8px; overflow: hidden; min-width: 90px; }
.progress.big { height: 14px; margin: 12px 0 6px; }
.progress .bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width .4s ease; }

/* --- Job detail ----------------------------------------------------- */
.job-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.stats { display: flex; flex-wrap: wrap; gap: 12px; margin: 18px 0; }
.stat {
  flex: 1 1 120px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: center;
}
.stat .num { display: block; font-size: 1.5rem; font-weight: 700; color: var(--text); line-height: 1.2; }
.stat span:last-child { color: var(--muted); font-size: .8125rem; }
.stat.ok .num { color: var(--success); }
.stat.warn .num { color: var(--warning); }
.stat.bad .num { color: var(--danger); }

.controls { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

.logs {
  background: #0F1620;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 14px;
  max-height: 360px;
  overflow: auto;
  direction: ltr;
  text-align: left;
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: .82rem;
  color: #D5DEE9;
  white-space: pre-wrap;
}

/* --- Footer --------------------------------------------------------- */
.footer { text-align: center; color: var(--muted); padding: 22px; font-size: .82rem; }

/* --- Misc chips / alerts ------------------------------------------- */
.user-chip {
  margin-inline-start: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: .82rem;
  font-weight: 500;
}

.alert {
  padding: 12px 14px;
  border-radius: var(--radius);
  margin: 14px 0;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  font-size: .9rem;
}
.alert.warn { color: var(--warning); border-color: var(--warning-border); background: var(--warning-bg); }
.alert.error { color: var(--danger); border-color: var(--danger-border); background: var(--danger-bg); }

/* --- Toasts (transient feedback, top-centre, RTL) ------------------- */
.toast-host {
  position: fixed;
  inset-block-start: 16px;
  inset-inline: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 460px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--neutral);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  padding: 10px 14px;
  font-size: .9rem;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .15s ease, transform .15s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast .dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--neutral); }
.toast.success { border-inline-start-color: var(--success); }
.toast.success .dot { background: var(--success); }
.toast.error { border-inline-start-color: var(--danger); }
.toast.error .dot { background: var(--danger); }

/* --- Live / connection indicator (job detail) ---------------------- */
.job-head-meta { display: flex; align-items: center; gap: 10px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--muted); }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.live.online::before { background: var(--success); }
.live.offline::before { background: var(--warning); }

/* --- Login ---------------------------------------------------------- */
.login-body {
  background:
    radial-gradient(1100px 520px at 50% -8%, #EAEEFB 0%, rgba(234, 238, 251, 0) 62%),
    var(--bg);
}
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
}
.login-brand {
  margin-bottom: 22px;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--text-2);
  text-align: center;
}
.login-card { width: 100%; max-width: 400px; }
.login-card h1 { font-size: 1.35rem; text-align: center; margin-bottom: 20px; }

/* --- Responsive ----------------------------------------------------- */
/* Tablet / mobile: the sidebar folds into a sticky top bar. */
@media (max-width: 768px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    flex: 0 0 auto;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 10;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 12px 16px;
    border-inline-end: none;
    border-bottom: 1px solid var(--border);
  }
  .brand { padding: 0; }
  .side-nav { flex-direction: row; gap: 4px; }
  .side-user {
    margin-top: 0;
    margin-inline-start: auto;
    padding-top: 0;
    border-top: none;
  }
}

@media (max-width: 640px) {
  .container { margin: 18px auto; padding: 0 16px; }
  .card { padding: 18px; }

  /* Stack each job row into a labelled card (no horizontal scroll on phones). */
  .table-wrap { overflow-x: visible; }
  table.jobs thead { display: none; }
  table.jobs, table.jobs tbody, table.jobs tr, table.jobs td { display: block; width: 100%; }
  table.jobs tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    margin-bottom: 12px;
    padding: 4px 14px;
  }
  table.jobs tbody tr:hover { background: var(--surface); }
  table.jobs td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    text-align: start;
  }
  table.jobs tr td:last-child { border-bottom: none; }
  table.jobs td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: .78rem;
    font-weight: 600;
    white-space: nowrap;
  }
  table.jobs td.ellipsis { max-width: none; overflow: visible; white-space: normal; }
  table.jobs td.cell-action { justify-content: flex-end; }
  table.jobs .progress { min-width: 120px; }
}
