@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

:root {
  --bg: #0f1117;
  --bg2: #161b27;
  --bg3: #1e2535;
  --border: #2a3147;
  --border2: #364060;
  --text: #e8ecf4;
  --text2: #8b95b0;
  --text3: #4a5470;
  --accent: #4f7ef8;
  --accent2: #3a63d4;
  --accent-soft: rgba(79,126,248,0.12);
  --green: #34d399;
  --green-soft: rgba(52,211,153,0.12);
  --red: #f87171;
  --red-soft: rgba(248,113,113,0.12);
  --amber: #fbbf24;
  --amber-soft: rgba(251,191,36,0.1);
  --radius: 10px;
  --radius-sm: 6px;
  --font: 'DM Sans', sans-serif;
  --mono: 'DM Mono', monospace;
  --sidebar-w: 220px;
  --transition: 0.15s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── LOGIN ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image: radial-gradient(ellipse at 20% 50%, rgba(79,126,248,0.06) 0%, transparent 60%),
                    radial-gradient(ellipse at 80% 20%, rgba(52,211,153,0.04) 0%, transparent 50%);
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.login-logo-icon {
  width: 36px; height: 36px;
  background: var(--accent-soft);
  border: 1px solid rgba(79,126,248,0.3);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}

.login-logo-icon svg { width: 18px; height: 18px; stroke: var(--accent); fill: none; stroke-width: 1.8; }

.login-logo-text { font-size: 16px; font-weight: 600; color: var(--text); }
.login-logo-sub { font-size: 11px; color: var(--text3); margin-top: 1px; }

.login-card h1 { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.login-card p { color: var(--text2); font-size: 13px; margin-bottom: 28px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 500; color: var(--text2); margin-bottom: 6px; letter-spacing: .02em; }

.field input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,126,248,0.15);
}
.field input::placeholder { color: var(--text3); }

.error-msg {
  background: var(--red-soft);
  border: 1px solid rgba(248,113,113,0.25);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--red);
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--border); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); border-color: var(--accent2); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { color: var(--red); border-color: transparent; background: transparent; }
.btn-danger:hover { background: var(--red-soft); border-color: rgba(248,113,113,0.2); }
.btn-success { background: var(--green-soft); border-color: rgba(52,211,153,0.2); color: var(--green); }
.btn-full { width: 100%; justify-content: center; padding: 11px; font-size: 14px; }

/* ── LAYOUT ── */
.layout { display: flex; min-height: 100vh; }

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
}

.sidebar-logo-icon {
  width: 32px; height: 32px;
  background: var(--accent-soft);
  border: 1px solid rgba(79,126,248,0.25);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
}
.sidebar-logo-icon svg { width: 16px; height: 16px; stroke: var(--accent); fill: none; stroke-width: 1.8; }

.sidebar-logo-name { font-size: 14px; font-weight: 600; }
.sidebar-logo-sub { font-size: 10px; color: var(--text3); margin-top: 1px; }

.sidebar-section { padding: 14px 12px 6px; }
.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text3);
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 0 8px;
  margin-bottom: 4px;
}

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 400;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 2px;
}
.nav-link svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.8; flex-shrink: 0; }
.nav-link:hover { background: var(--bg3); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }

.sidebar-footer {
  margin-top: auto;
  padding: 14px 12px;
  border-top: 1px solid var(--border);
}

.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
}
.user-avatar {
  width: 28px; height: 28px;
  background: var(--accent-soft);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: var(--accent);
  flex-shrink: 0;
}
.user-name { font-size: 12px; font-weight: 500; }
.user-role { font-size: 10px; color: var(--text3); }
.logout-btn {
  margin-left: auto;
  background: none; border: none; cursor: pointer;
  color: var(--text3); padding: 2px;
  transition: color var(--transition);
}
.logout-btn:hover { color: var(--red); }
.logout-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.8; }

/* ── MAIN CONTENT ── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px;
  max-width: calc(100vw - var(--sidebar-w));
}

.page-header {
  margin-bottom: 28px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.page-header h1 { font-size: 22px; font-weight: 600; }
.page-header p { color: var(--text2); font-size: 13px; margin-top: 3px; }

/* ── CARDS SCRIPTS (dashboard) ── */
.scripts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.script-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color var(--transition), transform var(--transition);
}
.script-card:hover { border-color: var(--border2); transform: translateY(-1px); }

.script-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.script-icon {
  width: 38px; height: 38px;
  background: var(--accent-soft);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.script-icon svg { width: 18px; height: 18px; stroke: var(--accent); fill: none; stroke-width: 1.8; }
.script-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 3px; }
.script-card p { color: var(--text2); font-size: 12px; line-height: 1.5; }
.script-filename { font-family: var(--mono); font-size: 11px; color: var(--text3); margin-top: 8px; }

.run-btn {
  width: 100%; margin-top: 16px;
  padding: 9px;
  background: var(--accent-soft);
  border: 1px solid rgba(79,126,248,0.2);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-family: var(--font);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background var(--transition), border-color var(--transition);
}
.run-btn:hover { background: rgba(79,126,248,0.2); border-color: rgba(79,126,248,0.35); }
.run-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.run-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }

/* Output terminal */
.output-panel {
  background: #0a0d14;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  color: #c8ffc8;
  min-height: 60px;
  max-height: 200px;
  overflow-y: auto;
  display: none;
  margin-top: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}
.output-panel.visible { display: block; }
.output-panel.error { color: var(--red); }
.output-meta { font-size: 11px; color: var(--text3); margin-top: 8px; }

/* ── TABLES ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h2 { font-size: 14px; font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: 10px 20px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  letter-spacing: .06em;
  text-transform: uppercase;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,0.015); }

.mono { font-family: var(--mono); font-size: 12px; color: var(--text2); }

/* ── BADGES ── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 11px; font-weight: 500;
}
.badge-blue { background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(79,126,248,0.2); }
.badge-green { background: var(--green-soft); color: var(--green); border: 1px solid rgba(52,211,153,0.2); }
.badge-red { background: var(--red-soft); color: var(--red); border: 1px solid rgba(248,113,113,0.2); }
.badge-gray { background: var(--bg3); color: var(--text2); border: 1px solid var(--border); }

/* ── TOGGLES PERMISSIONS ── */
.toggle-wrap {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.toggle-wrap:last-child { border-bottom: none; }
.toggle-info { flex: 1; }
.toggle-info .t-name { font-size: 13px; font-weight: 500; }
.toggle-info .t-file { font-family: var(--mono); font-size: 11px; color: var(--text3); margin-top: 2px; }

.toggle {
  position: relative; width: 36px; height: 20px; flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  position: absolute; inset: 0;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.toggle input:checked + .toggle-track {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: var(--text2);
  border-radius: 50%;
  transition: transform .2s, background .2s;
  pointer-events: none;
}
.toggle input:checked ~ .toggle-thumb {
  transform: translateX(16px);
  background: #fff;
}

/* ── MODALS ── */
.modal-bg {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: center; justify-content: center;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: 100%; max-width: 440px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal h2 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.modal .sub { color: var(--text2); font-size: 12px; margin-bottom: 22px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

/* ── FORMS ── */
.form-field { margin-bottom: 14px; }
.form-field label { display: block; font-size: 12px; font-weight: 500; color: var(--text2); margin-bottom: 6px; }
.form-field input, .form-field select, .form-field textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,126,248,0.12);
}
.form-field textarea { resize: vertical; min-height: 70px; }
.form-field select option { background: var(--bg2); }

.checkbox-field { display: flex; align-items: center; gap: 8px; }
.checkbox-field input[type=checkbox] { width: 15px; height: 15px; cursor: pointer; accent-color: var(--accent); }
.checkbox-field label { font-size: 13px; color: var(--text2); margin: 0; cursor: pointer; }

/* ── STATS ── */
.stats-row { display: flex; gap: 14px; margin-bottom: 24px; }
.stat-card {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.stat-val { font-size: 28px; font-weight: 600; }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 2px; }
.stat-card.green .stat-val { color: var(--green); }
.stat-card.red .stat-val { color: var(--red); }

/* ── LOGS terminal ── */
.log-terminal {
  background: #080b12;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.8;
}
.log-line { display: flex; gap: 12px; }
.log-ts { color: var(--text3); flex-shrink: 0; }
.log-user { color: var(--accent); flex-shrink: 0; min-width: 80px; }
.log-script { color: var(--text2); flex-shrink: 0; min-width: 140px; }
.log-ok { color: var(--green); }
.log-err { color: var(--red); }
.log-dur { color: var(--text3); margin-left: auto; }

/* ── RECENT LOGS mini ── */
.recent-log {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.recent-log:last-child { border-bottom: none; }
.recent-log .rl-script { font-weight: 500; flex: 1; }
.recent-log .rl-time { color: var(--text3); }
.recent-log .rl-dur { color: var(--text3); font-family: var(--mono); }

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

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { animation: spin .7s linear infinite; }

.sep { height: 1px; background: var(--border); margin: 10px 0; }
