/* ============================================================
   API Gateway Manager - Main Stylesheet
   ============================================================ */

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

:root {
  --sidebar-w: 230px;
  --sidebar-bg: #0f1729;
  --sidebar-text: #a8b4cc;
  --sidebar-active-bg: #1d4ed8;
  --sidebar-active-text: #fff;
  --sidebar-hover-bg: rgba(255,255,255,0.07);
  --topbar-h: 60px;
  --topbar-bg: #ffffff;
  --topbar-border: #e5e9f0;
  --body-bg: #f0f4f8;
  --card-bg: #ffffff;
  --primary: #1d4ed8;
  --primary-hover: #1a44c2;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --info: #0891b2;
  --text-main: #111827;
  --text-muted: #6b7280;
  --border: #e5e9f0;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1);
}

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

body {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  background: var(--body-bg);
  color: var(--text-main);
  line-height: 1.5;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1c7d0; border-radius: 3px; }

/* ============================================================
   LAYOUT
   ============================================================ */
.ams-wrapper { display: flex; min-height: 100vh; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.ams-sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: width .25s;
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  height: var(--topbar-h);
  border-bottom: 1px solid rgba(255,255,255,.08);
  text-decoration: none;
}

.sidebar-brand-icon {
  width: 32px; height: 32px;
  background: var(--primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
  color: #fff;
}

.sidebar-brand-text {
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  white-space: nowrap;
  line-height: 1.2;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(168,180,204,.5);
  padding: 10px 18px 4px;
}

.nav-item { list-style: none; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 6px;
  margin: 1px 8px;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
  white-space: nowrap;
}

.nav-link:hover { background: var(--sidebar-hover-bg); color: #fff; }

.nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

.nav-link i { width: 18px; text-align: center; font-size: 14px; flex-shrink: 0; }

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

.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sidebar-text);
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 6px;
  border-radius: 6px;
  width: 100%;
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  transition: background .15s;
  white-space: nowrap;
}
.sidebar-collapse-btn:hover { background: var(--sidebar-hover-bg); color: #fff; }
.sidebar-collapse-btn i { width: 18px; text-align: center; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.ams-main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left .25s;
}

/* ============================================================
   TOPBAR
   ============================================================ */
.ams-topbar {
  height: var(--topbar-h);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 90;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }

.sidebar-toggle-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .15s;
}
.sidebar-toggle-btn:hover { background: var(--body-bg); }

.topbar-right { display: flex; align-items: center; gap: 16px; }

.topbar-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 16px;
  padding: 6px;
  border-radius: 6px;
  position: relative;
  transition: background .15s;
}
.topbar-icon-btn:hover { background: var(--body-bg); }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .15s;
  text-decoration: none;
  color: var(--text-main);
}
.topbar-user:hover { background: var(--body-bg); }

.topbar-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

.topbar-username { font-weight: 600; font-size: 13.5px; }

/* ============================================================
   PAGE CONTENT
   ============================================================ */
.ams-content { padding: 24px; flex: 1; }

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-title { font-size: 22px; font-weight: 700; color: var(--text-main); }
.page-subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

.breadcrumb {
  background: none;
  padding: 0;
  margin: 0;
  font-size: 13px;
}
.breadcrumb-item a { color: var(--primary); text-decoration: none; }
.breadcrumb-item.active { color: var(--text-muted); }
.breadcrumb-item + .breadcrumb-item::before { color: var(--text-muted); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-body { padding: 20px; }
.card-header-custom {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ============================================================
   STAT CARDS (Dashboard)
   ============================================================ */
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
}

.stat-card-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-card-icon.blue   { background: #eff6ff; color: #1d4ed8; }
.stat-card-icon.green  { background: #f0fdf4; color: #16a34a; }
.stat-card-icon.red    { background: #fef2f2; color: #dc2626; }
.stat-card-icon.orange { background: #fff7ed; color: #d97706; }
.stat-card-icon.purple { background: #f5f3ff; color: #7c3aed; }
.stat-card-icon.teal   { background: #f0fdfa; color: #0d9488; }

.stat-card-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.stat-card-value { font-size: 26px; font-weight: 700; line-height: 1.2; }

.stat-change { font-size: 12px; margin-top: 2px; }
.stat-change.up   { color: var(--success); }
.stat-change.down { color: var(--danger); }

.mini-chart { opacity: .6; }

/* ============================================================
   SUMMARY CARDS (Dashboard)
   ============================================================ */
.summary-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  height: 100%;
}

.summary-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.summary-card-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}

.summary-card-title { font-size: 13.5px; font-weight: 600; }
.summary-card-view  { font-size: 12px; color: var(--primary); text-decoration: none; font-weight: 500; }
.summary-card-view:hover { text-decoration: underline; }
.summary-total { font-size: 22px; font-weight: 700; margin-bottom: 10px; }

.summary-stats { display: flex; flex-direction: column; gap: 4px; }
.summary-stat { display: flex; align-items: center; gap: 6px; font-size: 12.5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-green  { background: var(--success); }
.dot-gray   { background: #9ca3af; }
.dot-yellow { background: var(--warning); }
.dot-blue   { background: var(--primary); }

/* ============================================================
   TABLES
   ============================================================ */
.table-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-toolbar {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}

.table-footer {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}

.table { margin: 0; }
.table th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  white-space: nowrap;
}
.table td {
  padding: 12px 16px;
  border-color: var(--border);
  vertical-align: middle;
  font-size: 13.5px;
}
.table tbody tr:hover { background: #fafbfc; }

/* ============================================================
   BADGES & STATUS
   ============================================================ */
.badge-status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-active   { background: #dcfce7; color: #15803d; }
.badge-inactive { background: #f1f5f9; color: #64748b; }
.badge-draft    { background: #fef9c3; color: #854d0e; }

.badge-role {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
}
.badge-role-admin    { background: #fee2e2; color: #dc2626; }
.badge-role-manager  { background: #e0f2fe; color: #0369a1; }
.badge-role-operator { background: #f0fdf4; color: #15803d; }
.badge-role-viewer   { background: #f5f3ff; color: #7c3aed; }
.badge-role-user     { background: #e0f2fe; color: #0369a1; }
.badge-role-default  { background: #f1f5f9; color: #475569; }

.badge-type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: #eff6ff;
  color: #1d4ed8;
}
.badge-type-sms { background: #f0fdf4; color: #15803d; }

.badge-priority-type {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: #eff6ff;
  color: #1d4ed8;
}
.badge-priority-random {
  background: #f5f3ff;
  color: #7c3aed;
}

.http-code {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
}
.http-2xx { background: #dcfce7; color: #15803d; }
.http-4xx { background: #fee2e2; color: #dc2626; }
.http-5xx { background: #fef3c7; color: #b45309; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn { font-size: 13.5px; font-weight: 500; border-radius: 7px; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-sm { font-size: 12px; padding: 4px 10px; }

.btn-icon {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
  font-size: 13px;
}
.btn-icon:hover { background: var(--body-bg); }
.btn-icon.view  { color: var(--primary); }
.btn-icon.edit  { color: var(--primary); }
.btn-icon.del   { color: var(--danger); border-color: #fecaca; background: #fff5f5; }
.btn-icon.del:hover { background: #fee2e2; }

.action-btn-group { display: flex; align-items: center; gap: 4px; }

/* ============================================================
   FORMS
   ============================================================ */
.form-label { font-weight: 500; font-size: 13.5px; margin-bottom: 5px; }
.form-label .required { color: var(--danger); }

.form-control, .form-select {
  font-size: 13.5px;
  border-color: #d1d5db;
  border-radius: 7px;
  padding: 8px 12px;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}

.form-text { font-size: 12px; color: var(--text-muted); }

.form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  background: var(--card-bg);
}

.form-section-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
}

.form-section-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* ============================================================
   CODE / SCRIPT EDITOR
   ============================================================ */
.script-editor-wrap {
  border: 1px solid #d1d5db;
  border-radius: 7px;
  overflow: hidden;
  background: #1e293b;
}

.script-editor-lines {
  display: flex;
}

.script-line-numbers {
  background: #0f172a;
  color: #475569;
  font-family: 'Fira Code', 'Courier New', monospace;
  font-size: 12.5px;
  padding: 12px 0;
  text-align: right;
  user-select: none;
  min-width: 40px;
}

.script-line-numbers span {
  display: block;
  padding: 0 10px;
  line-height: 1.6;
}

.script-editor {
  flex: 1;
  background: #1e293b;
  color: #e2e8f0;
  font-family: 'Fira Code', 'Courier New', monospace;
  font-size: 12.5px;
  line-height: 1.6;
  border: none;
  outline: none;
  padding: 12px;
  resize: vertical;
  min-height: 220px;
  width: 100%;
}

.script-editor-preview {
  background: #1e293b;
  color: #e2e8f0;
  font-family: 'Fira Code', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
  padding: 12px 16px;
  min-height: 220px;
  white-space: pre;
  overflow-x: auto;
}

.token-keyword { color: #93c5fd; }
.token-string  { color: #86efac; }
.token-url     { color: #60a5fa; }
.token-var     { color: #fde68a; font-weight: 600; }
.token-key     { color: #f9a8d4; }

/* ============================================================
   VARIABLE ROWS
   ============================================================ */
.variable-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.variable-row:last-child { border-bottom: none; }
.variable-name-input { flex: 1; }

/* ============================================================
   SEARCH & FILTER BAR
   ============================================================ */
.search-input-wrap { position: relative; }
.search-input-wrap .search-icon {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 13px;
  pointer-events: none;
}
.search-input-wrap .form-control { padding-left: 32px; }

/* ============================================================
   VARIABLE TAGS
   ============================================================ */
.var-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.var-tag {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 500;
}

/* ============================================================
   ROLES & PERMISSIONS
   ============================================================ */
.roles-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  overflow: hidden;
}

.role-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}
.role-item:last-child { border-bottom: none; }
.role-item:hover { background: #f9fafb; }
.role-item.active { background: #eff6ff; border-left: 3px solid var(--primary); }

.role-icon {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: #eff6ff;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary);
  margin-right: 10px;
  flex-shrink: 0;
}

.role-name { font-weight: 600; font-size: 14px; }
.role-count { font-size: 12px; color: var(--text-muted); }

.perm-table { width: 100%; }
.perm-table th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  padding: 10px 16px;
  background: #f9fafb;
}
.perm-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.perm-table tbody tr:last-child td { border-bottom: none; }
.perm-table .module-name { font-weight: 500; }

.perm-allowed { color: #16a34a; font-weight: 600; display: flex; align-items: center; gap: 4px; font-size: 13px; }
.perm-denied  { color: #dc2626; font-weight: 600; display: flex; align-items: center; gap: 4px; font-size: 13px; }
.perm-notset  { color: #9ca3af; font-weight: 500; display: flex; align-items: center; gap: 4px; font-size: 13px; }

/* ============================================================
   COPY BUTTON
   ============================================================ */
.copy-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px 4px;
  border-radius: 4px;
  transition: color .15s;
}
.copy-btn:hover { color: var(--primary); }

/* ============================================================
   MODAL OVERRIDES
   ============================================================ */
.modal-header { border-bottom: 1px solid var(--border); }
.modal-footer { border-top: 1px solid var(--border); }
.modal-title  { font-size: 15px; font-weight: 700; }

.request-detail-section { margin-bottom: 16px; }
.request-detail-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.request-detail-value {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  font-family: 'Fira Code', monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  color: #1e293b;
  max-height: 200px;
  overflow-y: auto;
}

/* ============================================================
   INFO BOX
   ============================================================ */
.info-box {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 7px;
  padding: 12px 16px;
  font-size: 13px;
  color: #0369a1;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.warn-box {
  background: #fffbeb;
  border: 1px solid #fed7aa;
  border-radius: 7px;
  padding: 12px 16px;
  font-size: 13px;
  color: #92400e;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

/* ============================================================
   DROPDOWN MENU (topbar)
   ============================================================ */
.topbar-dropdown { position: relative; }
.topbar-dropdown-menu {
  position: absolute;
  right: 0; top: calc(100% + 8px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 180px;
  z-index: 200;
  display: none;
}
.topbar-dropdown-menu.show { display: block; }
.topbar-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: 13.5px;
  color: var(--text-main);
  text-decoration: none;
  transition: background .12s;
}
.topbar-dropdown-item:hover { background: var(--body-bg); }
.topbar-dropdown-divider { border-top: 1px solid var(--border); margin: 4px 0; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f1729 0%, #1e3a5f 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: #fff;
  border-radius: 14px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}

.login-logo {
  width: 48px; height: 48px;
  background: var(--primary);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  color: #fff;
  margin: 0 auto 16px;
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert { border-radius: 7px; font-size: 13.5px; }

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination .page-link {
  font-size: 13px;
  padding: 5px 11px;
  /*color: var(--primary);*/
  border-color: var(--border);
}
.pagination .page-item.active .page-link {
  background: var(--primary);
  border-color: var(--primary);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 992px) {
  .ams-sidebar { transform: translateX(-100%); }
  .ams-sidebar.open { transform: translateX(0); }
  .ams-main { margin-left: 0; }
}
