/* ===================================================
   PsPanel - Professional Control Panel Stylesheet
   =================================================== */

:root {
  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --primary-light: #dbeafe;
  --sidebar-bg:    #0f172a;
  --sidebar-text:  #cbd5e1;
  --sidebar-hover: #1e293b;
  --sidebar-width: 230px;
  --topbar-height: 52px;
  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --border:        #e2e8f0;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --success:       #16a34a;
  --danger:        #dc2626;
  --radius:        8px;
  --shadow:        0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
  --shadow-md:     0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Inter', 'Segoe UI', Arial, sans-serif; font-size: 14px; background: var(--bg); color: var(--text); }
a { text-decoration: none; color: inherit; }
h1,h2,h3,h4,h5,h6 { font-weight: 600; line-height: 1.3; }
.fas { margin-right: 5px; }

/* ===== Layout Shell ===== */
.shell { display: flex; height: 100vh; overflow: hidden; }

/* ===== Sidebar ===== */
.sidebar { width: var(--sidebar-width); background: var(--sidebar-bg); display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto; transition: width 0.25s ease; z-index: 200; }

.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px 16px; border-bottom: 1px solid rgba(255,255,255,0.07); }
.sidebar-brand .brand-icon { width: 32px; height: 32px; background: var(--primary); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.sidebar-brand .brand-name { font-size: 16px; font-weight: 700; color: #fff; letter-spacing: 0.3px; }
.sidebar-brand .brand-version { font-size: 10px; color: #64748b; display: block; font-weight: 400; }

.sidebar-section { padding: 20px 0 8px; }
.sidebar-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: #475569; padding: 0 20px 6px; }

.sidebar-nav a { display: flex; align-items: center; gap: 10px; padding: 9px 20px; color: var(--sidebar-text); font-size: 13.5px; transition: background 0.15s, color 0.15s; border-left: 3px solid transparent; }
.sidebar-nav a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-nav a.active { background: rgba(37,99,235,0.15); color: #93c5fd; border-left-color: var(--primary); }
.sidebar-nav a .nav-icon { width: 18px; text-align: center; font-size: 14px; opacity: 0.8; }

.sidebar-dropdown > a::after { content: '▾'; margin-left: auto; font-size: 10px; transition: transform 0.2s; }
.sidebar-dropdown.open > a::after { transform: rotate(180deg); }
.sidebar-submenu { display: none; background: rgba(0,0,0,0.2); }
.sidebar-dropdown.open .sidebar-submenu { display: block; }
.sidebar-submenu a { padding-left: 48px; font-size: 13px; }

.sidebar-footer { margin-top: auto; padding: 12px 0; border-top: 1px solid rgba(255,255,255,0.07); }

/* ===== Main Area ===== */
.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* ===== Top Bar ===== */
.topbar { height: var(--topbar-height); background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; flex-shrink: 0; box-shadow: var(--shadow); z-index: 100; }
.topbar-left { display: flex; align-items: center; gap: 14px; }
.sidebar-toggle { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 18px; padding: 4px; display: flex; align-items: center; }
.topbar-breadcrumb { font-size: 13px; color: var(--text-muted); }
.topbar-breadcrumb strong { color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.topbar-user { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 5px 10px; border-radius: var(--radius); transition: background 0.15s; }
.topbar-user:hover { background: var(--bg); }
.topbar-user .avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; }
.topbar-user .uname { font-size: 13px; font-weight: 500; color: var(--text); }

.user-dropdown-wrap { position: relative; }
.user-dropdown { display: none; position: absolute; top: calc(100% + 6px); right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); min-width: 170px; z-index: 9999; }
.user-dropdown-wrap.open .user-dropdown { display: block; }
.user-dropdown a { display: flex; align-items: center; gap: 8px; padding: 9px 14px; font-size: 13px; color: var(--text); transition: background 0.15s; }
.user-dropdown a:hover { background: var(--bg); }
.user-dropdown a.danger { color: var(--danger); }
.user-dropdown hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ===== Page Content ===== */
.page-content { flex: 1; overflow-y: auto; padding: 20px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.page-title { font-size: 18px; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ===== Cards ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 14px; font-weight: 600; color: var(--text); }
.card-body { padding: 18px; }

/* ===== Stat Cards ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow); }
.stat-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.stat-icon.blue   { background: #dbeafe; color: #2563eb; }
.stat-icon.green  { background: #dcfce7; color: #16a34a; }
.stat-icon.orange { background: #ffedd5; color: #ea580c; }
.stat-icon.purple { background: #f3e8ff; color: #9333ea; }
.stat-value { font-size: 20px; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; font-size: 13px; font-weight: 500; border-radius: 6px; border: 1px solid transparent; cursor: pointer; transition: background 0.15s, border-color 0.15s; line-height: 1.4; }
.btn-primary   { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger    { background: #fee2e2; color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fecaca; }
.btn-ghost     { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 5px; }

input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="search"], select, textarea {
  width: 100%; padding: 8px 12px; font-size: 13.5px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--surface); color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s; box-sizing: border-box;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }

select[multiple] { min-height: 180px; font-family: monospace; white-space: nowrap; overflow-x: auto; }

form { background: var(--surface); padding: 20px; border-radius: var(--radius); max-width: 700px; margin: auto; box-shadow: var(--shadow); }
form input, form select { margin-bottom: 12px; }
button { cursor: pointer; }

/* ===== Alerts ===== */
.alert { padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.alert-danger   { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.alert-warning  { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.alert-info     { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.success { color: var(--success); }
.error   { color: var(--danger); }

/* ===== File Manager ===== */
.fm-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #1e293b; border-radius: 6px 6px 0 0; flex-wrap: wrap; }

.breadcrumb { font-size: 13px; color: var(--text-muted); padding: 8px 12px; background: var(--surface); border-left: 1px solid var(--border); border-right: 1px solid var(--border); word-break: break-all; }
.breadcrumb a { color: var(--primary); }
.breadcrumb a:hover { text-decoration: underline; }

.back-button { display: inline-flex; align-items: center; padding: 4px 10px; background: var(--primary); color: #fff !important; border-radius: 5px; font-size: 12.5px; transition: background 0.15s; }
.back-button:hover { background: var(--primary-dark); }

.inline-buttons { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; padding: 6px 10px; background: #1e293b; }
.inline-buttons button { width: auto; display: inline-flex; align-items: center; gap: 4px; padding: 5px 11px; margin: 2px; font-size: 12.5px; background: rgba(255,255,255,0.12); color: #e2e8f0; border: 1px solid rgba(255,255,255,0.15); border-radius: 5px; transition: background 0.15s; }
.inline-buttons button:hover { background: rgba(255,255,255,0.22); }

ul.file-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-top: none; border-radius: 0 0 6px 6px; height: 70vh; overflow: auto; }
ul.file-list li { border-bottom: 1px solid #f1f5f9; font-family: 'JetBrains Mono', 'Fira Code', monospace; transition: background 0.1s; }
ul.file-list li:hover { background: #f8fafc; }
ul.file-list li .row { display: flex; align-items: center; justify-content: space-between; padding: 7px 12px; gap: 10px; flex-wrap: wrap; }
ul.file-list .item-name { flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
ul.file-list .item-name a { text-decoration: none; color: var(--primary); font-weight: 500; }
ul.file-list .item-name a:hover { text-decoration: underline; }
ul.file-list .filetype, ul.file-list .size { flex: 0 0 auto; font-size: 12px; color: var(--text-muted); white-space: nowrap; }
ul.file-list .filetype { font-weight: 600; background: #f1f5f9; padding: 2px 7px; border-radius: 4px; text-transform: uppercase; min-width: 52px; text-align: center; font-size: 11px; }

.file-list-header { background: #334155; color: #e2e8f0; font-weight: 600; font-size: 12px; padding: 8px 12px; }
.file-list-header .row, .file-list .row { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 15px; }
.file-list .row > .item-name, .file-list-header .row > .item-name { flex: 1 1 auto; min-width: 180px; }
.file-list .row > .filetype, .file-list-header .row > .filetype { flex: 0 0 80px; text-align: center; }
.file-list .row > .size, .file-list-header .row > .size { flex: 0 0 80px; text-align: right; }
.file-list .row > .modified, .file-list-header .row > .modified { flex: 0 0 140px; text-align: right; font-size: 12px; color: #94a3b8; }
.file-item.selected { background: #eff6ff; }

/* ===== Context Menu ===== */
.context-menu { display: none; position: fixed; background: var(--surface); border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0,0,0,0.15); z-index: 100000; min-width: 170px; border-radius: 8px; padding: 4px 0; }
.context-menu ul { list-style: none; margin: 0; padding: 0; }
.context-menu li { padding: 8px 16px; cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 8px; transition: background 0.1s; color: var(--text); }
.context-menu li:hover { background: #f1f5f9; }
.context-menu li.danger { color: var(--danger); }
.context-menu li.danger:hover { background: #fef2f2; }
.context-menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ===== Modals ===== */
.modal { display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.55); z-index: 10000; align-items: center; justify-content: center; backdrop-filter: blur(2px); }
.modal.open, .modal[style*="flex"] { display: flex !important; }

.modal > form, .modal > div {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  padding: 24px;
  width: 420px;
  max-width: 95vw;
}

.modal h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; color: var(--text); }
.modal form { padding: 0; margin: 0; box-shadow: none; max-width: 100%; background: none; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ===== Toast ===== */
#toast-container { position: fixed; top: 16px; right: 16px; z-index: 99999; display: flex; flex-direction: column; gap: 8px; }
.toast { min-width: 220px; max-width: 340px; padding: 12px 16px; border-radius: 8px; font-size: 13.5px; font-weight: 500; display: flex; align-items: center; gap: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); opacity: 0; transform: translateX(20px); transition: opacity 0.3s, transform 0.3s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(0); pointer-events: auto; }
.toast.success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.toast.error   { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.toast.info    { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.toast.warning { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }

/* ===== Login Page ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0369a1 100%); }
.login-box { background: var(--surface); border-radius: 12px; padding: 36px 32px; width: 360px; max-width: 95vw; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand .brand-icon { width: 52px; height: 52px; background: var(--primary); border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 24px; margin: 0 auto 12px; box-shadow: 0 4px 16px rgba(37,99,235,0.4); }
.login-brand h1 { font-size: 22px; color: var(--text); }
.login-brand p  { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.login-box form { padding: 0; margin: 0; box-shadow: none; background: none; max-width: 100%; }
.login-box .form-group { margin-bottom: 14px; }
.login-box input { margin-bottom: 0; padding: 10px 14px; font-size: 14px; }
.login-btn { width: 100%; padding: 11px; background: var(--primary); color: #fff; border: none; border-radius: 7px; font-size: 14px; font-weight: 600; cursor: pointer; margin-top: 6px; transition: background 0.15s; }
.login-btn:hover { background: var(--primary-dark); }

/* ===== Utilities ===== */
.container { padding: 0; background: transparent; }
.path_value { background: var(--bg); display: inline-block; padding: 5px 10px; border-radius: 5px; min-width: 200px; border: 1px solid var(--border); font-family: monospace; font-size: 12.5px; }
.navbar { display: none; }

/* Code editor */
.code_edit_file { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.CodeMirror { flex: 1 1 auto; width: 100% !important; height: 100% !important; font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 13.5px; }
.CodeMirror-scroll { overflow: auto !important; -webkit-overflow-scrolling: touch; }

/* Change/password box */
.change-box { max-width: 440px; margin: auto; background: var(--surface); padding: 28px 28px; border-radius: 10px; box-shadow: var(--shadow-md); }
.change-box h2 { margin-bottom: 20px; color: var(--text); font-size: 17px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -230px; height: 100vh; z-index: 999; }
  .sidebar.open { left: 0; }
  .page-content { padding: 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== ps-modal (shared modal system) ===== */
.ps-modal { display:none; position:fixed; inset:0; background:rgba(15,23,42,.58); z-index:10000; align-items:center; justify-content:center; backdrop-filter:blur(3px); }
.ps-modal-box { background:#fff; border-radius:12px; box-shadow:0 24px 64px rgba(0,0,0,.28); padding:28px; width:500px; max-width:96vw; max-height:92vh; overflow-y:auto; animation:modalin .18s ease; }
@keyframes modalin { from{opacity:0;transform:translateY(-18px) scale(.97)} to{opacity:1;transform:translateY(0) scale(1)} }
.ps-modal-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:20px; font-size:15px; font-weight:700; color:var(--text); }
.ps-modal-close { background:#f1f5f9; border:none; border-radius:6px; width:36px; height:36px; font-size:20px; cursor:pointer; display:flex; align-items:center; justify-content:center; color:#475569; transition:background .15s; flex-shrink:0; font-weight:600; }
.ps-modal-close:hover { background:#e2e8f0; color:#1e293b; }

/* ===== Multi-select mode ===== */
.multi-select-mode .file-item { cursor: pointer; user-select: none; }
.multi-select-mode .file-item:hover { background: #f0f9ff; }
.file-item.multi-checked { background: #eff6ff !important; outline: 2px solid #93c5fd; outline-offset: -2px; }

/* Checkbox shown on each item in multi-select mode */
.item-checkbox {
  display: none;
  width: 17px; height: 17px;
  margin-right: 8px;
  cursor: pointer;
  accent-color: var(--primary);
  flex-shrink: 0;
}
.multi-select-mode .item-checkbox { display: inline-block; }

/* Multi-select toolbar (shown above file list when active) */
#multiSelectBar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #1e40af;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  flex-wrap: wrap;
}
#multiSelectBar.active { display: flex; }
#multiSelectBar button {
  background: rgba(255,255,255,0.18);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  padding: 4px 12px;
  border-radius: 5px;
  font-size: 12.5px;
  cursor: pointer;
  transition: background .15s;
  width: auto;
  margin: 0;
}
#multiSelectBar button:hover { background: rgba(255,255,255,0.3); }
#multiSelectBar .ms-cancel {
  background: rgba(239,68,68,0.18);
  color: #fecaca;
  border-color: rgba(239,68,68,0.4);
}
#multiSelectBar .ms-cancel:hover {
  background: rgba(239,68,68,0.35);
  color: #fff;
}

/* Scrollable file preview list inside modals */
.multi-file-list {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8fafc;
  padding: 8px 10px;
  font-size: 12.5px;
  font-family: 'JetBrains Mono', monospace;
}
.multi-file-list .mfl-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 2px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text);
}
.multi-file-list .mfl-item:last-child { border-bottom: none; }
.multi-file-list .mfl-icon { color: #64748b; font-size: 13px; flex-shrink: 0; }
.multi-file-list .mfl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Cancel button — distinct from primary actions ===== */
.btn-cancel {
  background: #f8fafc;
  color: #64748b;
  border: 1px solid #cbd5e1;
}
.btn-cancel:hover {
  background: #f1f5f9;
  color: #475569;
  border-color: #94a3b8;
}

/* ===== Mobile sidebar overlay ===== */
#sidebarOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 998;
}
#sidebarOverlay.show { display: block; }

/* Close button inside sidebar (mobile only) */
.sidebar-close-btn {
  display: none;
  position: absolute;
  top: 14px;
  right: 12px;
  background: rgba(255,255,255,0.1);
  border: none;
  color: #94a3b8;
  font-size: 18px;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.sidebar-close-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }

@media (max-width: 768px) {
  .sidebar { position: fixed; left: -230px; height: 100vh; z-index: 999; transition: left 0.25s ease; }
  .sidebar.open { left: 0; }
  .sidebar-close-btn { display: flex; }
}

/* ===== Page loader spinner ===== */
#page-loader {
  position: fixed;
  inset: 0;
  background: rgba(241,245,249,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  opacity: 1;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(2px);
}
#page-loader.done { opacity: 0; pointer-events: none; }

.page-loader-spinner {
  width: 44px;
  height: 44px;
  border: 4px solid #e2e8f0;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ===== Async stat loading shimmer ===== */
.stat-loading {
  display: inline-block;
  width: 56px;
  height: 20px;
  background: linear-gradient(90deg, #e2e8f0 25%, #f8fafc 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  border-radius: 4px;
  animation: shimmer 1.2s infinite;
  vertical-align: middle;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== Sortable column headers ===== */
.sort-col { transition: color 0.15s; }
.sort-col:hover { color: #93c5fd !important; }
.sort-arrow { font-size: 11px; opacity: 0; transition: opacity 0.2s; }

/* ===== File Viewer Modal ===== */
#fileViewerModal .ps-modal-box {
  background: var(--surface);
}
#viewerBody img {
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}
#viewerBody pre {
  tab-size: 4;
}
