/* ====== Admin Reset & Base ====== */
:root {
  --primary: #2563eb;
  --accent: #06b6d4;
  --gradient: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%);
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #0f172a;
  --bg-topbar: #ffffff;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-light: #e2e8f0;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow: 0 4px 6px -1px rgba(15,23,42,0.07);
  --shadow-lg: 0 10px 30px rgba(15,23,42,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --danger: #ef4444;
  --success: #10b981;
}

*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }
body { font-family:var(--font); background:var(--bg); color:var(--text); line-height:1.6; }
a { text-decoration:none; color:inherit; }
button { font-family:inherit; cursor:pointer; border:none; background:none; }
input,textarea,select { font-family:inherit; font-size:14px; }

/* ====== Login ====== */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f0f4ff 0%, #ecfeff 100%);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border-radius: 20px;
  padding: 48px 40px;
  box-shadow: 0 20px 60px rgba(15,23,42,0.08);
  text-align: center;
}

.login-header { margin-bottom: 32px; }

.admin-logo {
  width: 60px; height: 60px;
  margin: 0 auto 20px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, rgba(37,99,235,0.1), rgba(6,182,212,0.1));
  border-radius: 16px;
}

.login-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 4px; }
.login-header p { font-size: 14px; color: var(--text-muted); }

.input-group {
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  transition: border-color 0.2s;
  margin-bottom: 16px;
}
.input-group:focus-within { border-color: var(--primary); }
.input-group svg { color: var(--text-muted); flex-shrink: 0; }
.input-group input {
  flex: 1; border: none; outline: none; background: transparent;
  padding: 14px 0; font-size: 15px; color: var(--text);
}
.input-group input::placeholder { color: var(--text-muted); }

.login-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px; font-size: 15px; font-weight: 600; color: #fff;
  background: var(--gradient); border-radius: 12px;
  transition: all 0.2s; box-shadow: 0 4px 14px rgba(37,99,235,0.25);
}
.login-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(37,99,235,0.35); }

.login-error { font-size: 13px; color: var(--danger); margin-top: 12px; min-height: 20px; }

.login-footer { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
.login-footer a { font-size: 13px; color: var(--text-muted); transition: color 0.2s; }
.login-footer a:hover { color: var(--primary); }

/* ====== Admin Layout ====== */
.admin-wrapper {
  display: none;
  min-height: 100vh;
  background: var(--bg);
}

.admin-wrapper.active { display: flex; flex-direction: column; }

/* Top Bar */
.admin-topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px; padding: 0 24px;
  background: var(--bg-topbar); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}

.topbar-left { display: flex; align-items: center; }
.tb-logo { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 500; }
.tb-logo b { font-weight: 700; color: var(--primary); }

.tb-badge {
  font-size: 12px; font-weight: 600; color: var(--primary);
  padding: 3px 10px; background: rgba(37,99,235,0.08); border-radius: 6px;
}

.topbar-right { display: flex; align-items: center; gap: 16px; }
.tb-time { font-size: 13px; color: var(--text-muted); font-family: var(--font-mono); }

.tb-btn {
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  padding: 6px 12px; border-radius: 8px; transition: all 0.2s;
}
.tb-btn:hover { background: var(--border-light); color: var(--text); }

/* Body */
.admin-body { display: flex; flex: 1; }

/* Sidebar */
.admin-sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--bg-sidebar); padding: 20px 12px;
  display: flex; flex-direction: column;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }

.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; font-size: 14px; font-weight: 500; color: var(--text-light);
  border-radius: 10px; transition: all 0.2s;
}
.sidebar-item:hover { background: rgba(255,255,255,0.08); }
.sidebar-item.active { background: rgba(37,99,235,0.2); color: #fff; }

.sidebar-count {
  margin-left: auto; font-size: 11px; font-weight: 600;
  padding: 1px 7px; border-radius: 100px;
  background: rgba(255,255,255,0.15);
  min-width: 22px; text-align: center;
}

/* Main Content */
.admin-main { flex: 1; padding: 28px 32px; overflow-y: auto; max-height: calc(100vh - 60px); }

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

.panel-title { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 24px; }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 16px;
}
.panel-header .panel-title { margin-bottom: 0; }
.panel-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ====== Stats Grid ====== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px;
  display: flex; align-items: center; gap: 16px;
}

.stat-card-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(37,99,235,0.08); color: var(--primary); flex-shrink: 0;
}

.stat-card-value { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; line-height: 1; }
.stat-card-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* Dashboard Charts */
.dashboard-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.chart-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
}
.chart-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; }

.category-bars { display: flex; flex-direction: column; gap: 12px; }
.bar-item { display: flex; align-items: center; gap: 12px; }
.bar-label { font-size: 13px; color: var(--text-secondary); width: 80px; text-align: right; flex-shrink: 0; }
.bar-track { flex: 1; height: 8px; background: var(--bg); border-radius: 10px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 10px; background: var(--gradient); transition: width 0.5s ease; }
.bar-count { font-size: 13px; font-weight: 600; color: var(--text); width: 30px; }

.recent-list { display: flex; flex-direction: column; gap: 10px; }
.recent-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; border-radius: 8px; transition: background 0.2s;
}
.recent-item:hover { background: var(--bg); }
.recent-item-icon { font-size: 22px; width: 36px; text-align: center; }
.recent-item-name { font-size: 14px; font-weight: 500; flex: 1; }
.recent-item-date { font-size: 12px; color: var(--text-muted); }

/* ====== Table ====== */
.table-search {
  height: 38px; padding: 0 14px;
  font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-card); color: var(--text); outline: none;
  width: 200px; transition: border-color 0.2s;
}
.table-search:focus { border-color: var(--primary); }

.table-wrapper {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}

.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { background: var(--border-light); }
.data-table th {
  text-align: left; padding: 12px 16px; font-size: 12px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px;
}
.data-table td {
  padding: 12px 16px; font-size: 14px; border-top: 1px solid var(--border-light);
}
.data-table tbody tr:hover { background: var(--border-light); }

.table-category {
  display: inline-block; padding: 2px 10px; border-radius: 100px;
  font-size: 12px; font-weight: 500;
}

.table-actions { display: flex; gap: 6px; }
.table-action {
  padding: 4px 10px; font-size: 12px; font-weight: 500;
  border-radius: 6px; transition: all 0.2s;
}
.table-action.edit { color: var(--primary); }
.table-action.edit:hover { background: rgba(37,99,235,0.08); }
.table-action.delete { color: var(--danger); }
.table-action.delete:hover { background: rgba(239,68,68,0.08); }

.table-empty {
  display: none; padding: 48px; text-align: center; color: var(--text-muted); font-size: 14px;
}

/* ====== Action Buttons ====== */
.action-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; font-size: 13px; font-weight: 600;
  border-radius: var(--radius-sm); transition: all 0.2s;
  color: #fff; background: var(--gradient);
}
.action-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.action-btn.outline {
  background: var(--bg-card); color: var(--text-secondary); border: 1px solid var(--border);
}
.action-btn.outline:hover { border-color: var(--primary); color: var(--primary); }
.action-btn.danger { background: var(--danger); }
.action-btn.primary { padding: 12px 24px; font-size: 15px; }

/* ====== Form ====== */
.software-form {
  max-width: 720px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-row .form-group { margin-bottom: 0; }

.form-group label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }

.form-group input,
.form-group select,
.form-group textarea {
  padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); outline: none; transition: border-color 0.2s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.08); }

.form-group input[type="color"] {
  width: 60px; height: 42px; padding: 4px; cursor: pointer;
}

.form-actions { display: flex; gap: 12px; margin-top: 8px; }

/* File Upload */
.file-upload-wrapper {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.file-input { display: none; }
.file-label {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 16px; font-size: 13px; font-weight: 500;
  color: var(--primary); border: 1.5px dashed var(--primary);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: all 0.2s; background: rgba(37,99,235,0.04);
}
.file-label:hover { background: rgba(37,99,235,0.08); }
.file-name { font-size: 13px; color: var(--text-muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.form-hint { display: block; font-size: 11px; color: var(--success); margin-top: 6px; }

.upload-progress { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex: 1; }
.progress-bar { flex: 1; height: 6px; background: var(--border-light); border-radius: 10px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--gradient); border-radius: 10px; width: 0; transition: width 0.3s; }
.progress-text { font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); }

/* ====== Settings ====== */
.settings-card {
  max-width: 640px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}

.setting-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; gap: 20px;
}
.setting-item + .setting-item { border-top: 1px solid var(--border-light); }
.setting-info h4 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.setting-info p { font-size: 13px; color: var(--text-muted); }

/* Category Management */
.setting-section-title {
  padding: 16px 24px; font-size: 14px; font-weight: 700;
  color: var(--primary); background: rgba(37,99,235,0.04);
  border-bottom: 1px solid var(--border-light);
}

.category-list { padding: 8px 16px; }
.cat-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px; border-bottom: 1px solid var(--border-light);
  transition: background 0.15s;
}
.cat-row:hover { background: var(--border-light); }
.cat-row:last-child { border-bottom: none; }
.cat-row-icon { font-size: 18px; width: 28px; text-align: center; }
.cat-row-id {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-muted);
  width: 80px; flex-shrink: 0;
}
.cat-row input {
  flex: 1; border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; font-size: 13px; color: var(--text); outline: none;
  background: var(--bg); min-width: 0;
}
.cat-row input:focus { border-color: var(--primary); }
.cat-row .cat-icon-input { flex: 0 0 50px; text-align: center; }
.cat-row .cat-pwd-input {
  flex: 0 0 110px;
  font-size: 12px;
  letter-spacing: 1px;
}
.cat-row .cat-delete { color: var(--danger); font-size: 20px; cursor: pointer; padding: 4px; opacity: 0.5; transition: opacity 0.2s; }
.cat-row .cat-delete:hover { opacity: 1; }
.cat-hint { font-size: 11px; color: var(--text-muted); padding: 4px 8px; }

.category-add {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 24px; border-top: 1px solid var(--border-light);
}
.category-add input {
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 12px; font-size: 13px; color: var(--text); outline: none;
}
.category-add input:focus { border-color: var(--primary); }
.action-btn.small { padding: 7px 14px; font-size: 12px; }
.cat-tip { font-size: 12px; color: var(--text-muted); padding: 0 24px 12px; line-height: 1.5; }

/* ====== Modal (Password Change) ====== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5);
  display: none; align-items: center; justify-content: center;
  z-index: 300; backdrop-filter: blur(4px);
}
.modal-overlay.active { display: flex; }

.modal-card {
  width: 90%; max-width: 400px;
  background: var(--bg-card); border-radius: 16px;
  padding: 28px; box-shadow: 0 20px 60px rgba(15,23,42,0.2);
}
.modal-card h3 { font-size: 18px; font-weight: 700; margin-bottom: 20px; }
.modal-error { font-size: 13px; color: var(--danger); min-height: 20px; margin-bottom: 8px; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }

/* ====== Toast ====== */
.toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  padding: 12px 24px; background: var(--text); color: #fff;
  border-radius: 100px; font-size: 14px; font-weight: 500;
  z-index: 400; opacity: 0; transition: all 0.3s cubic-bezier(0.34,1.56,0.64,1);
  box-shadow: 0 10px 30px rgba(15,23,42,0.3);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ====== Responsive ====== */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-charts { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .panel-actions { flex-direction: column; align-items: stretch; }
}

@media (max-width: 768px) {
  .admin-sidebar {
    position: fixed; left: -240px; top: 60px; bottom: 0;
    z-index: 200; transition: left 0.3s;
  }
  .admin-sidebar.open { left: 0; }
  .admin-main { padding: 20px 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .topbar-center { display: none; }
  .table-search { width: 100%; }
}
