/* Reset & Base - Dark Mode */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-hover: #30363d;
  --border-color: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent-primary: #58a6ff;
  --accent-secondary: #1f6feb;
  --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --success: #3fb950;
  --warning: #d29922;
  --danger: #f85149;
  --info: #58a6ff;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body:has(.navbar) {
  padding-top: 64px;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Navbar */
.navbar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  height: 64px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 1000;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  margin-right: 1rem;
  transition: transform 0.1s;
  z-index: 1001;
  position: relative;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  flex-direction: column;
}

.sidebar-toggle:hover {
  background: var(--bg-tertiary);
}

.sidebar-toggle:active {
  transform: scale(0.95);
}

.hamburger-icon {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 24px;
  height: 18px;
  position: relative;
}

.hamburger-icon span {
  display: block;
  height: 3px;
  width: 100%;
  background: var(--text-primary);
  border-radius: 3px;
  transition: all 0.3s ease;
}

.sidebar-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(1) {
  transform: rotate(45deg) translate(8px, 8px);
}

.sidebar-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(2) {
  opacity: 0;
}

.sidebar-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(3) {
  transform: rotate(-45deg) translate(8px, -8px);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-brand-logo {
  width: 50px;
}

.nav-brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.nav-brand a {
  color: var(--text-primary);
  font-size: 1.4rem;
  font-weight: bold;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* App Layout with Sidebar */
.app-layout {
  position: relative;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 64px;
  height: calc(100vh - 64px);
  z-index: 999;
  transition: transform 0.3s ease;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--border-color);
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.sidebar-nav {
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.5rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.2s;
  font-weight: 500;
  border-left: 3px solid transparent;
}

.sidebar-link:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border-left-color: var(--accent-primary);
}

.sidebar-link.active {
  color: var(--accent-primary);
  background: var(--bg-tertiary);
  border-left-color: var(--accent-primary);
}

.sidebar-icon {
  font-size: 1.2rem;
  width: 24px;
  text-align: center;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 998;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* Main content adjustment for sidebar */
main.container {
  margin-left: 280px;
  transition: margin-left 0.3s ease;
  margin-right: 0;
  padding: 2rem;
  min-height: calc(100vh - 64px - 73px);
}

.container-wrapper {
  margin: 0 auto;
  width: 100%;
  max-width: 1200px;
}

.nav-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-secondary);
}

.nav-user span {
  display: none;
}

@media (min-width: 768px) {
  .nav-user span {
    display: inline;
  }
}

/* Container */
/* .container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  flex: 1;
} */

/* Form container - consistent width with main container */
.form-container {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.form-container .card {
  max-width: 600px;
  margin: 0 auto;
}

/* Cards */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
  text-decoration: none;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #da3633;
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.btn-outline:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  text-decoration: none;
}

/* Forms */
.form-group {
  margin-bottom: 1.2rem;
}

.form-label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-control {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  transition: border-color 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.form-control::placeholder {
  color: var(--text-muted);
}

.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.form-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-primary);
}

.form-check label {
  color: var(--text-secondary);
  cursor: pointer;
}

select.form-control {
  cursor: pointer;
}

select.form-control option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.scopes-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: -1.5rem;
  padding: 1.5rem;
}

.card .table-wrapper {
  margin: -1.5rem;
}

.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

.table th, .table td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.table th {
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table tbody tr:hover {
  background: var(--bg-tertiary);
}

.table code {
  background: var(--bg-tertiary);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--accent-primary);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-admin { background: rgba(248, 81, 73, 0.2); color: var(--danger); border: 1px solid var(--danger); }
.badge-user { background: rgba(88, 166, 255, 0.2); color: var(--accent-primary); border: 1px solid var(--accent-primary); }
.badge-service { background: rgba(63, 185, 80, 0.2); color: var(--success); border: 1px solid var(--success); }

/* Alerts */
.alert {
  padding: 1rem 1.2rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  border: 1px solid;
}

.alert-success {
  background: rgba(63, 185, 80, 0.1);
  color: var(--success);
  border-color: rgba(63, 185, 80, 0.3);
}

.alert-error {
  background: rgba(248, 81, 73, 0.1);
  color: var(--danger);
  border-color: rgba(248, 81, 73, 0.3);
}

.alert-info {
  background: rgba(88, 166, 255, 0.1);
  color: var(--info);
  border-color: rgba(88, 166, 255, 0.3);
}

/* Login Page */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  background-image: 
    radial-gradient(ellipse at top, rgba(102, 126, 234, 0.15), transparent 50%),
    radial-gradient(ellipse at bottom, rgba(118, 75, 162, 0.1), transparent 50%);
}

.login-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 2.5rem;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  width: 100%;
  max-width: 400px;
}

.login-title {
  text-align: center;
  margin-bottom: 2rem;
}

.login-title h1 {
  font-size: 2rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.login-title p {
  color: var(--text-secondary);
}

.login-logo {
  width: 100px;
  height: auto;
  object-fit: contain;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 1.5rem;
  border-radius: 12px;
  transition: all 0.2s;
}

.stat-card:hover {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
}

.stat-value {
  font-size: 2.5rem;
  font-weight: bold;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-label {
  color: var(--text-secondary);
  margin-top: 0.25rem;
  font-size: 0.9rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from { 
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }
  to { 
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideIn 0.2s ease;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-body {
  padding: 1.5rem;
}

.modal-body p {
  color: var(--text-secondary);
  margin-bottom: 0;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* Copy box */
.copy-box {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1rem;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  word-break: break-all;
  margin: 1rem 0;
  color: var(--accent-primary);
  font-size: 0.9rem;
}

/* Footer */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

/* Page Title */
h1 {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Utilities */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-color);
}

/* Responsive */
@media (max-width: 992px) {
  /* Navbar Mobile */
  .navbar {
    padding: 0 1rem;
    height: 64px;
  }

  .sidebar-toggle {
    display: flex;
  }

  .nav-brand {
    flex: 1;
  }

  .nav-user {
    margin-left: auto;
    gap: 0.5rem;
  }

  .nav-user span {
    display: none;
  }

  .nav-user .btn {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    white-space: nowrap;
  }

  /* Main content - no margin on mobile */
  main.container {
    margin-left: 0;
  }

  /* Sidebar Mobile */
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
  }

  .sidebar.active {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: block;
  }
}

@media (max-width: 768px) {
  /* Container */
  .container {
    padding: 1rem;
  }

  .form-container {
    padding: 1rem;
  }

  .form-container .card {
    max-width: 100%;
  }
  
  /* Stats Grid */
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .stat-value {
    font-size: 2rem;
  }
  
  /* Cards */
  .card {
    padding: 1rem;
    margin-bottom: 1rem;
  }

  .card .table-wrapper {
    margin: -1rem;
    padding: 1rem;
  }
  
  /* Tables */
  .table-wrapper {
    margin: -1rem;
    padding: 1rem;
  }

  .table {
    font-size: 0.85rem;
    min-width: 600px;
  }
  
  .table th, .table td {
    padding: 0.75rem 0.5rem;
  }

  .table th {
    font-size: 0.75rem;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .card-header .btn {
    width: 100%;
    text-align: center;
  }

  /* Forms */
  .form-group {
    margin-bottom: 1rem;
  }

  .scopes-grid {
    grid-template-columns: 1fr;
  }

  /* Buttons */
  .flex.gap-1,
  .flex.gap-2 {
    flex-direction: column;
  }

  .flex.gap-1 .btn,
  .flex.gap-2 .btn {
    width: 100%;
  }

  /* Modal */
  .modal {
    max-width: 95%;
    margin: 1rem;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: 1rem;
  }

  /* Login */
  .login-box {
    padding: 1.5rem;
    margin: 1rem;
  }

  .login-title h1 {
    font-size: 1.5rem;
  }

  .login-logo {
    width: 80px;
  }

  /* Page Title */
  h1 {
    font-size: 1.5rem;
  }

  .card-title {
    font-size: 1.1rem;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0.75rem;
  }

  .form-container {
    padding: 0.75rem;
  }

  .card {
    padding: 0.75rem;
    border-radius: 8px;
  }

  .card .table-wrapper {
    margin: -0.75rem;
    padding: 0.75rem;
  }

  .table-wrapper {
    margin: -0.75rem;
    padding: 0.75rem;
  }

  .table {
    font-size: 0.8rem;
    min-width: 500px;
  }

  .table th, .table td {
    padding: 0.5rem 0.4rem;
  }

  .btn {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
  }

  .stat-value {
    font-size: 1.75rem;
  }
}
