:root {
  --bg: #0a0c13;
  --bg-elevated: #10121b;
  --card: #151827;
  --card-hover: #191d2f;
  --border: #252a3d;
  --text: #eceefa;
  --text-muted: #8b91a8;
  --accent-1: #1e40f5;
  --accent-2: #4d9dff;
  --accent-grad: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  --success: #33d17e;
  --warning: #f5b342;
  --danger: #f5576c;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

::selection { background: var(--accent-2); color: #fff; }

/* ---------- layout ---------- */
#app-view { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 22px; }
.brand img { width: 28px; height: 28px; object-fit: contain; }
.brand span { font-weight: 700; font-size: 16px; letter-spacing: .01em; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--text-muted); font-size: 14px; font-weight: 500;
  cursor: pointer; border: none; background: transparent; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: var(--card); color: var(--text); }
.nav-item.active::before { content: ""; }

.sidebar-app-name {
  padding: 16px 12px 8px; margin-top: 6px; border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
}
.nav-item.detail-tab { padding-left: 12px; }

.sidebar-footer { margin-top: auto; padding: 10px 8px; }
.sidebar-footer button {
  width: 100%; padding: 9px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--text-muted); cursor: pointer; font-size: 13px;
}
.sidebar-footer button:hover { color: var(--text); border-color: var(--text-muted); }

.main { flex: 1; padding: 28px 36px; max-width: 1200px; }

.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 22px; }
.page-header h1 { font-size: 22px; margin: 0 0 4px; }
.page-header p { margin: 0; color: var(--text-muted); font-size: 13px; }

.breadcrumb { color: var(--text-muted); font-size: 13px; margin-bottom: 6px; }
.breadcrumb a { color: var(--text-muted); cursor: pointer; text-decoration: none; }
.breadcrumb a:hover { color: var(--text); }

/* ---------- buttons ---------- */
button { font-family: inherit; }
.btn {
  border-radius: 8px; padding: 9px 16px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--border); background: var(--card); color: var(--text);
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--card-hover); }
.btn-primary { background: var(--accent-grad); border: none; color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: rgba(245, 87, 108, 0.1); }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---------- login ---------- */
#login-view {
  max-width: 360px; margin: 10vh auto; background: var(--card);
  padding: 32px; border-radius: var(--radius); border: 1px solid var(--border);
}
#login-view .brand { justify-content: center; padding-bottom: 24px; }
#login-view input {
  width: 100%; padding: 11px 12px; margin-bottom: 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 14px;
}
#login-view input:focus { outline: none; border-color: var(--accent-2); }
#login-view button {
  width: 100%; padding: 11px; background: var(--accent-grad); border: none;
  border-radius: 8px; color: white; font-weight: 700; cursor: pointer; font-size: 14px;
}
#login-error { color: var(--danger); min-height: 18px; font-size: 13px; margin-bottom: 4px; }

/* ---------- stat cards ---------- */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 24px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-card .value { font-size: 26px; font-weight: 700; }
.stat-card .label { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

/* ---------- server resources ---------- */
.resource-row { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.resource-group { display: flex; flex-direction: column; gap: 8px; }
.resource-label { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-muted); }
.resource-label span:last-child { color: var(--text); font-weight: 600; }

/* ---------- app grid / cards ---------- */
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.app-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; cursor: pointer; transition: border-color .15s, transform .15s;
}
.app-card:hover { border-color: var(--accent-2); transform: translateY(-1px); }
.app-card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.app-avatar {
  width: 38px; height: 38px; border-radius: 10px; background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; color: #fff;
  flex-shrink: 0;
}
.app-card-title { font-weight: 600; font-size: 15px; }
.app-card-sub { color: var(--text-muted); font-size: 12px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.running { background: var(--success); box-shadow: 0 0 0 3px rgba(51,209,126,.15); }
.status-dot.exited { background: var(--text-muted); }
.status-dot.other { background: var(--warning); }

.mini-bars { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.mini-bar-row { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-muted); }
.mini-bar-row .label { width: 30px; flex-shrink: 0; }
.mini-bar-track { flex: 1; height: 5px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.mini-bar-fill { height: 100%; background: var(--accent-grad); width: 0%; transition: width .3s; }
.mini-bar-fill.mem { background: linear-gradient(135deg, #7c3aed, #a78bfa); }
.mini-bar-row .val { width: 44px; flex-shrink: 0; text-align: right; }

.empty-state { color: var(--text-muted); font-size: 14px; padding: 40px 0; text-align: center; }

/* ---------- app detail ---------- */
.detail-header {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 18px;
}
.detail-header-left { display: flex; align-items: center; gap: 14px; }
.detail-title { display: flex; align-items: center; gap: 8px; font-size: 19px; font-weight: 700; }
.detail-sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.detail-actions { display: flex; gap: 8px; }

.tab-bar { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-bar button {
  background: none; border: none; color: var(--text-muted); font-size: 14px; font-weight: 500;
  padding: 10px 16px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-bar button:hover { color: var(--text); }
.tab-bar button.active { color: var(--text); border-bottom-color: var(--accent-2); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.overview-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 18px; }
.overview-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.overview-card .label { color: var(--text-muted); font-size: 12px; margin-bottom: 6px; }
.overview-card .value { font-size: 20px; font-weight: 700; }

.slider-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.slider-card h3 { margin: 0 0 16px; font-size: 14px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.slider-group label { font-size: 13px; display: flex; justify-content: space-between; margin-bottom: 8px; }
.slider-group label .val { color: var(--accent-2); font-weight: 700; }
.slider-group input[type=range] {
  width: 100%; accent-color: var(--accent-2);
}

.link-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 18px; display: flex; justify-content: space-between; align-items: center; }
.link-card a { color: var(--accent-2); text-decoration: none; font-weight: 600; }
.link-card a:hover { text-decoration: underline; }

/* ---------- deploy form ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 14px; }

.tabs-toggle { display: flex; gap: 8px; margin-bottom: 18px; }
.tabs-toggle button {
  background: transparent; border: 1px solid var(--border); color: var(--text-muted);
  padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.tabs-toggle button.active { background: var(--accent-grad); color: white; border-color: transparent; }

.form-row { display: flex; gap: 12px; margin-bottom: 14px; }
.form-row > div { flex: 1; }
.form-row label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 10px 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-family: inherit; font-size: 13px; resize: vertical;
}
.form-row input:focus, .form-row textarea:focus { outline: none; border-color: var(--accent-2); }
#deploy-status { margin-top: 8px; font-size: 13px; color: var(--text-muted); }

/* ---------- env vars ---------- */
.env-add-row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.env-add-row > div { flex: 1; }
.env-add-row label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.env-add-row input {
  width: 100%; padding: 10px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 13px; font-family: "SF Mono", Consolas, monospace;
}
.env-list { display: flex; flex-direction: column; gap: 8px; }
.env-row {
  display: flex; align-items: center; gap: 12px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px;
}
.env-row .key { font-family: "SF Mono", Consolas, monospace; font-size: 13px; font-weight: 600; width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.env-row .value { flex: 1; font-family: "SF Mono", Consolas, monospace; font-size: 13px; color: var(--text-muted); letter-spacing: 2px; }
.env-row button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; }
.env-row button:hover { color: var(--danger); }

/* ---------- file manager ---------- */
.file-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.file-path { font-family: "SF Mono", Consolas, monospace; font-size: 13px; color: var(--text-muted); }
.file-path a { color: var(--text-muted); cursor: pointer; text-decoration: none; }
.file-path a:hover { color: var(--accent-2); }
.file-actions { display: flex; gap: 8px; }
.file-table { width: 100%; border-collapse: collapse; }
.file-table tr { border-bottom: 1px solid var(--border); }
.file-table tr:hover td { background: var(--card-hover); }
.file-table td { padding: 10px 12px; font-size: 13px; }
.file-table td.name { cursor: pointer; display: flex; align-items: center; gap: 8px; }
.file-table td.size { color: var(--text-muted); text-align: right; width: 100px; }
.file-table td.actions-cell { width: 40px; text-align: right; }
.file-table td.actions-cell button { background: none; border: none; color: var(--text-muted); cursor: pointer; }
.file-table td.actions-cell button:hover { color: var(--danger); }

/* ---------- logs ---------- */
.logs-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.logs-status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); }
#log-terminal { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; padding: 10px; height: 440px; overflow: hidden; }
.console-input-row {
  display: flex; align-items: center; gap: 10px; background: var(--bg);
  border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius);
  padding: 10px 16px;
}
.console-prompt { color: var(--accent-2); font-family: "SF Mono", Consolas, monospace; font-weight: 700; }
.console-input-row input {
  flex: 1; background: none; border: none; color: var(--text); font-family: "SF Mono", Consolas, monospace;
  font-size: 13px;
}
.console-input-row input:focus { outline: none; }
.console-input-row input:disabled { color: var(--text-muted); }

/* ---------- building list ---------- */
.building-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.building-item:last-child { border-bottom: none; }
.badge { padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.building { background: rgba(245, 179, 66, .15); color: var(--warning); }
.badge.failed { background: rgba(245, 87, 108, .15); color: var(--danger); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  width: 90%; max-width: 720px; max-height: 80vh; display: flex; flex-direction: column;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-header span { font-weight: 600; font-size: 14px; }
.modal-header button { background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; }
.modal-body { padding: 18px; overflow: auto; flex: 1; }
.modal-body textarea {
  width: 100%; height: 100%; min-height: 340px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-family: "SF Mono", Consolas, monospace;
  font-size: 13px; resize: vertical;
}
.modal-footer { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 860px) {
  #app-view { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 12px 16px; }
  .brand { padding: 0; }
  .sidebar-footer { display: none; }
  .main { padding: 20px; }
  .overview-grid, .sliders, .stat-row { grid-template-columns: 1fr; }
}
