:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --bg-color: #f9fafb;
  --bg-card: #ffffff;
  --bg-surface: #f8fafc;
  --text-main: #111827;
  --text-muted: #6b7280;
  --border-color: #e5e7eb;
  --border: #e5e7eb;
  --danger: #b91c1c;
  --sidebar-w: 260px;
  --header-h: 64px;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, Avenir, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

#root {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

.app-container {
  display: flex;
  flex: 1;
  width: 100%;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background-color: var(--bg-card);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
}

.sidebar-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--border-color);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--primary);
  gap: 12px;
}

.sidebar-nav {
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
}

.sidebar-service {
  padding: 0 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-service__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-service__label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.sidebar-service__status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 700;
}

.sidebar-service__status--muted {
  color: var(--text-muted);
  font-weight: 500;
}

.sidebar-service__status--online {
  color: #15803d;
}

.sidebar-service__status--offline {
  color: #b91c1c;
}

.sidebar-service__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.sidebar-service__restart {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(217, 119, 6, 0.35);
  border-radius: 12px;
  background: #fffbeb;
  color: #b45309;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.sidebar-service__restart:hover:not(:disabled) {
  background: #fef3c7;
  border-color: rgba(217, 119, 6, 0.5);
  color: #92400e;
}

.sidebar-service__restart:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.sidebar-storage {
  margin-top: auto;
  padding: 0 16px 24px;
}

.sidebar-storage__card {
  background: #eef2ff;
  border-radius: 16px;
  padding: 16px;
  border: 1px solid rgba(99, 102, 241, 0.15);
}

.sidebar-storage__title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--primary);
}

.sidebar-storage__muted {
  font-size: 0.8rem;
  color: #6366f1;
  opacity: 0.85;
}

.sidebar-storage__error {
  margin-top: 8px;
  font-size: 0.8rem;
  color: #b91c1c;
  line-height: 1.4;
}

.sidebar-storage__bar-track {
  margin-top: 12px;
  height: 10px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.2);
  overflow: hidden;
}

.sidebar-storage__bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width 0.25s ease, background-color 0.25s ease;
}

.sidebar-storage__summary {
  margin-top: 10px;
  font-size: 0.72rem;
  color: #6366f1;
  font-weight: 500;
  line-height: 1.4;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  text-decoration: none;
  color: var(--text-muted);
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.2s;
}

.nav-item:hover, .nav-item.active {
  background-color: #eef2ff;
  color: var(--primary);
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.top-header {
  height: var(--header-h);
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-header__actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Header user menu (profile dropdown) */
.user-menu {
  position: relative;
  z-index: 20;
}

.user-menu__trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  background: #f3f4f6;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  color: var(--text-main);
  max-width: 220px;
  transition: background 0.15s, border-color 0.15s;
}

.user-menu__trigger:hover {
  background: #e5e7eb;
  border-color: #d1d5db;
}

.user-menu__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  font-weight: 700;
  color: #ffffff;
  background: #6ee7b7;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.user-menu__avatar--sm {
  width: 32px;
  height: 32px;
  font-size: 0.875rem;
}

.user-menu__trigger-name {
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
  text-align: left;
}

.user-menu__chevron {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.user-menu__chevron--open {
  transform: rotate(180deg);
}

.user-menu__panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 256px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 4px 10px -4px rgba(0, 0, 0, 0.06);
  padding: 8px 0;
}

.user-menu__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 8px 14px;
}

.user-menu__head-text {
  min-width: 0;
  flex: 1;
}

.user-menu__head-name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: #374151;
  line-height: 1.3;
}

.user-menu__head-sub {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu__rule {
  height: 1px;
  margin: 6px 0;
  background: var(--border-color);
  border: none;
}

.user-menu__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: #374151;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}

.user-menu__item:hover,
.user-menu__item:focus-visible {
  background: #f3f4f6;
  outline: none;
}

.user-menu__item--danger {
  color: #b91c1c;
}

.user-menu__item--danger:hover,
.user-menu__item--danger:focus-visible {
  background: #fef2f2;
}

.page-container {
  padding: 32px;
  flex: 1;
}

.page-title {
  font-size: 1.875rem;
  font-weight: 700;
  margin: 0 0 24px 0;
}

/* Cards & Elements */
.card {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
  padding: 24px;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.2s;
  font-size: 0.875rem;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-outline {
  background-color: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  background-color: #f3f4f6;
}

.btn-danger {
  background-color: #b91c1c;
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background-color: #991b1b;
}

.btn-danger:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

/* Tables */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-card);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th {
  background-color: #f9fafb;
  padding: 12px 24px;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
}

td {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.875rem;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background-color: #f9fafb;
}

th.table-col-actions,
td.table-col-actions {
  width: 220px;
  white-space: nowrap;
}

th.table-col-actions {
  text-align: center;
}

td.table-col-actions {
  vertical-align: middle;
}

.table-actions-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
}

.study-detail-action-btn {
  width: 34px;
  height: 34px;
  border-radius: 5px;
  border: none;
  background: #6b7280;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background-color 0.2s ease, transform 0.15s ease;
}

.study-detail-action-btn:hover:not(:disabled) {
  background: var(--primary);
  transform: translateY(-1px);
}

.study-detail-action-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Tooltip kustom (pengganti atribut title native).
   Dirender via portal ke document.body oleh global tooltip. */
.app-tooltip-wrap {
  display: inline-flex;
}

.app-tooltip {
  position: fixed;
  transform: translate(-50%, calc(-100% - 8px));
  background: #111827;
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.app-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #111827;
}

.table-compact th,
.table-compact td {
  padding: 10px 12px;
}

.study-list-table th,
.study-list-table td {
  padding: 10px 12px;
}

.study-list-table th {
  white-space: nowrap;
}

.study-detail-node-option {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text-main);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.study-detail-node-option:hover {
  background: #eef2ff;
  color: var(--primary);
}

.list-toolbar {
  margin-bottom: 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.list-toolbar__label {
  font-weight: 500;
  white-space: nowrap;
}

.list-toolbar__input-wrap {
  position: relative;
  width: 100%;
  max-width: 280px;
}

.list-toolbar__input {
  width: 100%;
}

.list-toolbar__input--with-clear {
  padding-right: 40px;
}

.list-toolbar__clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 9999px;
  border: none;
  background: #e5e7eb;
  color: #374151;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.list-toolbar__summary {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.list-pagination-wrap,
.patients-pagination-wrap {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.list-pagination,
.patients-pagination {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.list-page-btn,
.patients-page-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border-color);
  border-radius: 9px;
  background: #f9fafb;
  color: #374151;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.05s ease;
}

.list-page-btn:hover:not(:disabled),
.patients-page-btn:hover:not(:disabled) {
  background: #eef2f7;
  border-color: #d1d5db;
}

.list-page-btn:active:not(:disabled),
.patients-page-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.list-page-btn.is-active,
.patients-page-btn.is-active {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.list-page-btn:disabled,
.patients-page-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Forms */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-main);
}

.form-input {
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.1);
}

.badge {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  background-color: #eef2ff;
  color: var(--primary);
}

/* Alert banner (feedback create/update/delete) */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  border: 1px solid transparent;
}

.alert-success {
  background: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}

.alert-error {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  /* backdrop-filter: blur() dihapus — sangat berat di GPU lemah (PC RS),
     menyebabkan modal terasa lambat terbuka. Overlay gelap tetap dipertahankan. */
}

.modal-content {
  background: var(--bg-card);
  border-radius: 12px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.modal-sm {
  max-width: 460px;
}

.modal-header {
  padding: 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  margin: 0;
  font-size: 1.25rem;
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.modal-footer-inline {
  padding: 16px 0 0;
  border-top: none;
  margin-top: 16px;
}

.login-page {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #eef2ff, #f9fafb);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(17, 24, 39, 0.08);
  padding: 28px;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 24px;
  gap: 12px;
}

.login-brand__logo {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  object-fit: contain;
  display: block;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.login-brand__title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.02em;
  line-height: 1.3;
}

.login-title {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

.login-subtitle {
  margin: 0 0 20px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.login-btn {
  width: 100%;
  min-height: 40px;
  margin-top: 6px;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
}

.login-btn__spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: login-spin .7s linear infinite;
}

.login-btn.is-loading .login-btn__spinner {
  display: inline-block;
}

@keyframes login-spin {
  to { transform: rotate(360deg); }
}

.login-error {
  margin: 8px 0 12px;
  font-size: 0.875rem;
  color: #b91c1c;
}

.login-helper {
  margin: 12px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.auth-loading {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--text-muted);
}

.success-text {
  margin: 8px 0 0;
  font-size: 0.875rem;
  color: #047857;
}

/* SweetAlert2 — selaras dengan tema aplikasi */
.swal2-popup {
  font-family: 'Inter', system-ui, sans-serif !important;
  border-radius: 12px !important;
  padding: 1.75rem 1.5rem 1.25rem !important;
}

.swal2-title {
  font-size: 1.25rem !important;
  font-weight: 600 !important;
  color: var(--text-main) !important;
  padding: 0.25rem 0 0 !important;
}

.swal2-html-container {
  color: var(--text-muted) !important;
  font-size: 0.9rem !important;
  line-height: 1.55 !important;
  margin-top: 0.35rem !important;
}

.swal2-html-container strong {
  color: var(--text-main);
  font-weight: 600;
}

.swal2-validation-message {
  background: #fef2f2 !important;
  color: #991b1b !important;
  border-radius: 8px !important;
  margin-top: 0.75rem !important;
}

.swal2-actions {
  margin-top: 1.35rem !important;
  gap: 0.65rem !important;
}

.swal2-styled {
  border-radius: 8px !important;
  font-weight: 500 !important;
  font-size: 0.875rem !important;
  padding: 0.55rem 1.25rem !important;
}

/* Loading text helper */
.loading-text {
  color: var(--text-muted);
}

/* ── Ganti bahasa ─────────────────────────────────────────────── */
.locale-switch { display: inline-flex; border: 1px solid var(--border-color); border-radius: 8px; overflow: hidden; }
.locale-switch__item { padding: 6px 10px; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-decoration: none; }
.locale-switch__item.is-active { background: var(--primary); color: #fff; }
.locale-switch__item:not(.is-active):hover { background: var(--bg-color); }
