/* Server Manager — layout & theming. Kontrol ada di controls.css (terpusat). */

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  margin: 0;
}
* { box-sizing: border-box; }
a { color: inherit; text-decoration: none; }
.serif { font-family: var(--font-sans); font-weight: var(--fw-semibold); letter-spacing: -0.01em; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 12px; position: sticky; top: 0; height: 100vh;
}
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 4px 6px 14px; }
.brand-mark {
  width: 38px; height: 38px; border: 1px solid var(--border); border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center; background: var(--surface-active); color: var(--text-primary); flex: none;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; overflow: hidden; }
.brand-text strong { color: var(--text-primary); font-size: var(--fs-md); }
.brand-text .mono { font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm); color: var(--text-secondary);
  font-weight: var(--fw-medium); transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); cursor: pointer;
}
.nav-item svg { color: var(--text-muted); flex: none; }
.nav-item:hover { background: var(--surface-hover); color: var(--text-primary); }
.nav-item.active { background: var(--bg); color: var(--text-primary); }
.nav-item.active svg { color: var(--accent); }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; padding-top: 14px; border-top: 1px solid var(--border); }
.conn { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--text-muted); padding: 0 4px; }
.dot { width: 8px; height: 8px; border-radius: var(--radius-pill); background: var(--text-muted); flex: none; }
.conn.ok .dot { background: var(--accent-green); }
.conn.err .dot { background: var(--accent-red); }
.conn.ok #conn-label { color: var(--accent-green); }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 24px 12px; border-bottom: 1px solid var(--border); background: var(--bg); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; font-size: var(--fs-xl); color: var(--text-primary); }
.topbar p { margin: 2px 0 0; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.view { padding: 18px 24px 52px; max-width: 1400px; }

/* ---------- cards / bento ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-title { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: var(--fw-semibold); margin: 0; }
.card h3 { margin: 0; }

.bento { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px; }
.bento > .card { min-width: 0; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }

.stat-value { font-family: var(--font-mono); font-size: var(--fs-2xl); color: var(--text-primary); line-height: 1.1; letter-spacing: -0.02em; }
.stat-sub { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 6px; }
.stat-label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: var(--fw-semibold); }

.tag {
  display: inline-flex; align-items: center; padding: 2px 9px; border-radius: var(--radius-pill);
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.04em; font-weight: var(--fw-semibold);
  background: var(--surface-active); color: var(--text-muted); border: 1px solid var(--border);
}
.tag-green { background: var(--status-success-bg); color: var(--accent-green); border-color: transparent; }
.tag-red { background: var(--status-danger-bg); color: var(--accent-red); border-color: transparent; }
.tag-blue { background: var(--status-info-bg); color: var(--accent); border-color: transparent; }
.tag-yellow { background: var(--status-warning-bg); color: var(--accent-amber); border-color: transparent; }

/* progress */
.bar { height: 8px; background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--radius-pill); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: var(--radius-pill); transition: width 0.5s var(--ease-out); }
.bar.warn > i { background: var(--accent-amber); }
.bar.crit > i { background: var(--accent-red); }

.spark { width: 100%; height: 42px; display: block; margin-top: 8px; }

.core-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 6px; margin-top: 10px; }
.core { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 5px 6px; background: var(--surface-active); }
.core .n { font-size: 10px; color: var(--text-muted); font-family: var(--font-mono); }
.core .v { font-size: var(--fs-sm); color: var(--text-primary); font-family: var(--font-mono); }
.core .bar { height: 4px; margin-top: 5px; }

.kv { display: grid; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--border); }
.kv-row:first-child { border-top: none; }
.kv-row .k { color: var(--text-muted); font-size: var(--fs-sm); }
.kv-row .v { color: var(--text-primary); font-family: var(--font-mono); font-size: var(--fs-sm); text-align: right; word-break: break-all; }

/* ---------- tables ---------- */
/* Datagrid: tidak boleh scroll horizontal. Kolom dipaksa pas container; teks
   panjang dipotong dengan ellipsis (detail tetap ada di title/data-label). */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden auto; background: var(--surface); max-width: 100%; }
table { width: 100%; max-width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
#fs-table, #proc-table { table-layout: fixed; }
thead th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: var(--fw-semibold); padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--surface-active); white-space: nowrap; }
tbody td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--dur-fast) var(--ease-out); }
tbody tr:hover { background: var(--surface-hover); }
tbody tr.clickable { cursor: pointer; }
tbody tr.selected, tbody tr.selected:hover { background: var(--accent-light); }
#fs-table th, #fs-table td, #proc-table th, #proc-table td { overflow: hidden; }
#fs-table .fs-cell-name, #proc-table .td-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#fs-table col.col-check { width: 34px; }
#fs-table col.col-type { width: 76px; }
#fs-table col.col-size { width: 92px; }
#fs-table col.col-date { width: 138px; }
#fs-table col.col-actions { width: 118px; }
#proc-table col.col-pid { width: 68px; }
#proc-table col.col-cpu, #proc-table col.col-mempct { width: 72px; }
#proc-table col.col-mem { width: 92px; }
#proc-table col.col-actions { width: 56px; }
.td-mono { font-family: var(--font-mono); font-size: 11px; }
.td-right { text-align: right; }
.row-actions { display: inline-flex; gap: 4px; }

/* ---------- toolbar & file explorer ---------- */
.fs-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--text-muted); flex: 1 1 300px; min-width: 0; }
.crumbs a { color: var(--text-secondary); padding: 2px 5px; border-radius: 5px; }
.crumbs a:hover { background: var(--surface-hover); color: var(--text-primary); }
.crumbs .sep { color: var(--text-tertiary); }
.crumbs .cur { color: var(--text-primary); padding: 2px 5px; }
.fs-search { position: relative; flex: 0 1 210px; min-width: 0; }
.fs-search input { padding-left: 32px; width: 100%; }
.fs-search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.fs-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }
.sort-field { display: inline-flex; align-items: center; gap: 6px; flex: 0 1 180px; min-width: 0; }
.sort-field > span { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); white-space: nowrap; }
.sort-field select { flex: 1; min-width: 0; }
.proc-controls, .proc-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.proc-meta { margin-left: auto; }
.fs-cell-check { width: 34px; text-align: center; }
.fs-check { width: 17px; height: 17px; min-width: 17px; margin: 0; vertical-align: middle; accent-color: var(--accent); cursor: pointer; }

.selection-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px 10px; margin: 0 0 12px;
  border: 1px solid var(--border-strong); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); background: var(--surface);
}
.selection-bar .hint { margin: 0; }

.file-icon { color: var(--text-muted); flex: none; }
.file-name { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--text-primary); }
.file-name > span:not(.tag) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dir-name { font-weight: var(--fw-medium); }

/* editor */
.editor { display: grid; gap: 12px; }
.editor textarea { min-height: 320px; white-space: pre; }
.editor-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Editor file: dialog lebih lapang, textarea mengikuti tinggi dialog */
.modal-wide .modal-card { max-width: min(1040px, calc(100vw - 48px)); height: 88vh; height: min(88vh, 760px); min-height: 480px; max-height: 92vh; }
.modal-wide .modal-body { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.modal-wide .editor { display: flex; flex-direction: column; flex: 1; min-height: 0; gap: 8px; }
.modal-wide .editor-bar { flex: none; }
.modal-wide .editor textarea { flex: 1; min-height: 0; height: 100%; line-height: 1.6; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 36px 32px; }
.login-card h1 { margin: 14px 0 6px; font-size: var(--fs-xl); color: var(--text-primary); }
.login-card p { margin: 0 0 20px; }
.login-card .brand-mark { width: 52px; height: 52px; border-radius: var(--radius-md); }
.hint { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 18px; line-height: 1.5; }
.error { color: var(--accent-red); font-size: var(--fs-sm); min-height: 18px; margin: 0 0 12px; }

/* ---------- toast ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; background: var(--text-primary); color: #fff; padding: 12px 18px; border-radius: var(--radius-sm); font-size: var(--fs-md); box-shadow: var(--shadow-md); max-width: 90vw; }
.toast.err { background: var(--accent-red); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,0.32); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 90; }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); width: 100%; max-width: 560px; max-height: 86vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: var(--fs-lg); color: var(--text-primary); }
.modal-body { padding: 22px; overflow: auto; }
.modal-body p { margin: 0 0 14px; }

/* ---------- reveal ---------- */
.reveal { opacity: 0; transform: translateY(12px); transition: opacity 0.5s var(--ease-out), transform 0.5s var(--ease-out); }
.reveal.in { opacity: 1; transform: none; }

/* ---------- misc ---------- */
.empty { text-align: center; padding: 48px 16px; color: var(--text-muted); }
.empty .big { font-size: var(--fs-lg); color: var(--text-primary); margin-bottom: 6px; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.nowrap { white-space: nowrap; }
.section-title { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: var(--fw-semibold); margin: 0 0 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-inline { margin-bottom: 0; }

/* responsive */
@media (max-width: 1080px) {
  .span-3 { grid-column: span 6; } .span-4 { grid-column: span 6; } .span-8 { grid-column: span 12; } .span-6 { grid-column: span 12; }
}
@media (max-width: 820px) {
  /* ---------- mobile: side panel -> bottom nav ---------- */
  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; height: auto; z-index: 50;
    flex-direction: column; flex-wrap: nowrap; gap: 0; padding: 0;
    border-right: none; border-top: 1px solid var(--border);
    background: var(--surface);
    box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.05);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .sidebar-head { display: none; }
  .sidebar-foot { display: none; }

  .nav {
    flex-direction: row; flex-wrap: nowrap; width: 100%; margin: 0; gap: 0;
    justify-content: space-around; align-items: stretch; overflow-x: auto;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-item {
    flex: 1 1 0; min-width: 0; min-height: 56px;
    flex-direction: column; gap: 3px; align-items: center; justify-content: center;
    padding: 7px 4px; border-radius: 0; text-align: center;
    color: var(--text-muted); font-size: 11px; font-weight: var(--fw-medium);
  }
  .nav-item span { font-size: 11px; line-height: 1.1; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-item svg { width: 22px; height: 22px; }
  .nav-item:hover { background: transparent; color: var(--text-primary); }
  .nav-item.active { background: transparent; color: var(--accent); }
  .nav-item.active svg { color: var(--accent); }

  /* ruang supaya konten tidak ketutup bottom nav */
  .main { padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)); }
  .view { padding: 16px; padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); max-width: 100%; }
  .topbar { padding: 14px 16px; padding-top: calc(14px + env(safe-area-inset-top, 0px)); }
  .topbar h1 { font-size: var(--fs-xl); }

  /* toast di atas bottom nav */
  .toast { bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }

  .span-3, .span-4, .span-6, .span-8, .span-12 { grid-column: span 12; }
  .grid-2 { grid-template-columns: 1fr; }
  .bento { gap: 12px; }
  .card { padding: 16px; }
  .stat-value { font-size: var(--fs-xl); }
  .kv-row { gap: 10px; }
  .editor textarea { min-height: 260px; }
  .modal { padding: 12px; align-items: flex-end; }
  .modal-card { max-height: 90vh; }

  /* editor file mobile: hampir full-screen supaya nyaman baca/edit */
  .modal-wide { align-items: stretch; padding: calc(8px + env(safe-area-inset-top, 0px)) 8px calc(8px + env(safe-area-inset-bottom, 0px)); }
  .modal-wide .modal-card { max-width: 100%; max-height: none; height: 100%; }
  .modal-wide .modal-head { padding: 12px 14px; }
  .modal-wide .modal-body { flex: 1; min-height: 0; padding: 10px 12px 12px; }
  .modal-wide .editor textarea { min-height: 0; height: 100%; padding: 12px; font-size: 12.5px; line-height: 1.55; }

  /* ---------- kontrol mobile: dekat dengan konteksnya ---------- */
  /* baris 1 breadcrumb, baris 2 cari + muat ulang, baris 3 aksi file */
  .fs-toolbar { gap: 8px; }
  .fs-toolbar .crumbs { flex: 1 1 100%; order: -3; min-width: 0; }
  .fs-toolbar .fs-search { flex: 1 1 calc(100% - 56px); order: -2; min-width: 0; }
  .fs-toolbar > #fs-refresh { order: -1; flex: 0 0 44px; }
  .fs-toolbar .fs-actions {
    order: 0; flex: 1 1 100%; margin-left: 0;
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px;
  }
  .fs-toolbar .fs-actions .sp-btn, .fs-toolbar .fs-actions .btn { width: 100%; padding: 0 8px; }
  #fs-roots.fs-toolbar { margin-bottom: 12px; gap: 6px; }
  #fs-roots.fs-toolbar .sp-btn, #fs-roots.fs-toolbar .btn { flex: 0 1 auto; }

  /* Proses: cari penuh, urut + muat ulang sebaris, meta di bawah */
  .proc-toolbar .proc-controls { flex: 1 1 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; }
  .proc-toolbar .proc-controls .fs-search { grid-column: 1 / -1; flex: 1 1 100%; }
  .proc-toolbar .sort-field { flex: 1 1 auto; }
  .proc-toolbar .sort-field select { min-width: 0; }
  .proc-toolbar .proc-meta { flex: 1 1 100%; margin-left: 0; }

  .selection-bar { gap: 6px; }
  .selection-bar .hint { display: none; }
  .selection-bar .sp-btn { flex: 1 1 auto; }

  /* ---------- FS datagrid -> kartu list ---------- */
  #fs-table, #fs-table tbody, #fs-table tr, #fs-table td { display: block; width: 100%; }
  #fs-table { border: none; background: transparent; }
  #fs-table thead, #fs-table colgroup { display: none; }
  .fs-wrap { border: none; background: transparent; overflow: visible; }
  #fs-table tbody tr {
    display: grid; grid-template-columns: 20px minmax(0, 1fr); column-gap: 8px;
    border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface);
    margin-bottom: 10px; padding: 10px 12px; box-shadow: none;
  }
  #fs-table tbody tr:hover, #fs-table tbody tr.selected, #fs-table tbody tr.selected:hover { background: var(--surface); }
  #fs-table tbody tr.selected { border-color: var(--accent); }
  #fs-table tbody td { border: none; padding: 4px 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
  #fs-table tbody td::before {
    content: attr(data-label); color: var(--text-muted); font-size: var(--fs-xs);
    text-transform: uppercase; letter-spacing: 0.04em; flex: none;
  }
  #fs-table tbody td[colspan]::before { content: none; }
  #fs-table tbody td[colspan] { grid-column: 1 / -1; display: block; }

  #fs-table tbody td.fs-cell-check { grid-column: 1; grid-row: 1; width: 20px; padding: 0; align-self: center; }
  #fs-table tbody td.fs-cell-check::before { content: none; }
  #fs-table tbody td.fs-cell-name {
    grid-column: 2; grid-row: 1; justify-content: flex-start;
    padding-bottom: 7px; margin-bottom: 5px; border-bottom: 1px solid var(--border);
  }
  #fs-table tbody td.fs-cell-name::before { content: none; }
  #fs-table tbody td.fs-cell-name .file-name { min-width: 0; flex: 1; }
  #fs-table tbody td:not(.fs-cell-check):not(.fs-cell-name) { grid-column: 1 / -1; }
  #fs-table tbody td.fs-cell-actions { justify-content: flex-end; padding-top: 7px; margin-top: 3px; border-top: 1px solid var(--border); }
  #fs-table tbody td.fs-cell-actions::before { content: none; }
  #fs-table tbody td.fs-cell-actions .row-actions { flex-wrap: wrap; justify-content: flex-end; }

  /* ---------- Proses datagrid -> kartu list ---------- */
  #proc-table, #proc-table tbody, #proc-table tr, #proc-table td { display: block; width: 100%; }
  #proc-table { border: none; background: transparent; }
  #proc-table thead, #proc-table colgroup { display: none; }
  .proc-wrap { border: none; background: transparent; overflow: visible; }
  #proc-table tbody tr {
    border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface);
    margin-bottom: 8px; padding: 9px 12px;
  }
  #proc-table tbody tr:hover { background: var(--surface); }
  #proc-table tbody td { border: none; padding: 3px 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
  #proc-table tbody td::before {
    content: attr(data-label); color: var(--text-muted); font-size: var(--fs-xs);
    text-transform: uppercase; letter-spacing: 0.04em; flex: none;
  }
  #proc-table tbody td.td-name { padding-bottom: 6px; margin-bottom: 4px; border-bottom: 1px solid var(--border); font-weight: var(--fw-semibold); }
  #proc-table tbody td.td-name::before, #proc-table tbody td.td-actions::before { content: none; }
  #proc-table tbody td.td-actions { justify-content: flex-end; padding-top: 6px; margin-top: 3px; border-top: 1px solid var(--border); }

  .td-right { text-align: left; }
}
@media (max-width: 480px) {
  .view { padding: 12px; padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
  .card { padding: 14px; }
  .card-head { margin-bottom: 12px; }
  .core-grid { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; }
  .stat-value { font-size: var(--fs-lg); }
  .kv-row .k, .kv-row .v { font-size: 11px; }
  .table-wrap { border-radius: var(--radius-md); }
  .topbar-right { gap: 8px; }
  .empty { padding: 32px 12px; }
}

/* sentuh lebih besar di mobile */
@media (max-width: 820px) {
  .nav-item { min-height: 56px; }
}

@media (prefers-reduced-motion: reduce) { .reveal { transition: none; } }
