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

:root {
  --primary: #e8792b;
  --primary-hover: #d06820;
  --header-bg: #1a1a2e;
  --sidebar-bg: #16213e;
  --sidebar-text: #c4c9d4;
  --sidebar-active-bg: #1a2744;
  --sidebar-active-border: #e8792b;
  --body-bg: #0f0f23;
  --card-bg: #1a1a2e;
  --card-border: #2a2a4a;
  --text-primary: #e8e8f0;
  --text-secondary: #9ca3af;
  --table-header-bg: #16213e;
  --table-row-hover: #1e1e3a;
  --table-border: #2a2a4a;
  --input-bg: #16213e;
  --input-border: #3a3a5a;
  --input-text: #e8e8f0;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --secondary-btn-bg: #2a2a4a;
  --secondary-btn-text: #c4c9d4;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--body-bg);
  color: var(--text-primary);
  line-height: 1.6;
}

header {
  background: var(--header-bg);
  color: #fff;
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 2px solid var(--primary);
}

header h1 { font-size: 1.1rem; font-weight: 600; color: var(--primary); white-space: nowrap; }
header nav { display: flex; align-items: center; gap: 0.75rem; }
#user-info { font-size: 0.8rem; opacity: 0.9; white-space: nowrap; }

#main-layout { display: flex; min-height: calc(100vh - 50px); }

#sidebar {
  width: 200px;
  min-width: 200px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--card-border);
  padding: 0.75rem 0;
  flex-shrink: 0;
}

#sidebar ul { list-style: none; }
#sidebar li {
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--sidebar-text);
  border-left: 3px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}
#sidebar li:hover { background: var(--sidebar-active-bg); color: var(--primary); }
#sidebar li.active { background: var(--sidebar-active-bg); color: var(--primary); border-left-color: var(--sidebar-active-border); font-weight: 600; }
#sidebar li .nav-icon { margin-right: 0.4rem; }
.nav-section {
  padding: 0.6rem 1rem 0.3rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
  font-weight: 600;
  cursor: default;
  border-left: 3px solid transparent;
}
.nav-section:not(:first-child) { margin-top: 0.5rem; border-top: 1px solid var(--card-border); padding-top: 0.8rem; }

#content {
  flex: 1;
  padding: 1.5rem;
  min-width: 0;
  overflow-x: auto;
}

.card {
  background: var(--card-bg);
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  margin-bottom: 1rem;
  border: 1px solid var(--card-border);
}

.centered { text-align: center; max-width: 400px; margin: 4rem auto; }

h2 { margin-bottom: 1rem; font-size: 1.3rem; color: var(--text-primary); }
h3 { margin: 1.25rem 0 0.5rem; font-size: 1rem; color: var(--text-primary); }

.form-group { margin-bottom: 0.75rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.2rem; font-size: 0.8rem; color: var(--text-secondary); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  font-size: 0.8rem;
  background: var(--input-bg);
  color: var(--input-text);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--primary); }

.btn-primary, .btn-secondary, .btn-danger {
  padding: 0.35rem 0.9rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  margin-right: 0.4rem;
  margin-top: 0.4rem;
  white-space: nowrap;
}

/* Fixed-width action buttons in tables */
td .btn-primary, td .btn-secondary, td .btn-danger, td a.btn-secondary {
  min-width: 70px;
  width: 70px;
  text-align: center;
  display: inline-block;
  box-sizing: border-box;
  padding-left: 0;
  padding-right: 0;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary-btn-bg); color: var(--secondary-btn-text); }
.btn-secondary:hover { background: #3a3a5a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }

.error { color: var(--danger); margin-top: 0.5rem; font-size: 0.8rem; }

.table-container { overflow-x: auto; width: 100%; }

table { width: 100%; border-collapse: collapse; background: var(--card-bg); border: 1px solid var(--card-border); table-layout: auto; }
th, td { padding: 0.5rem 0.6rem; text-align: left; font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
th { background: var(--table-header-bg); font-weight: 600; border-bottom: 1px solid var(--table-border); color: var(--text-secondary); cursor: default; user-select: none; }
td { border-bottom: 1px solid var(--table-border); color: var(--text-primary); }
tr:hover td { background: var(--table-row-hover); }

.cell-truncate {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 500;
  white-space: nowrap;
}
.badge-pending { background: #78350f; color: #fbbf24; }
.badge-approved { background: #064e3b; color: #34d399; }
.badge-rejected { background: #7f1d1d; color: #fca5a5; }
.badge-provisioned { background: #1e3a5f; color: #60a5fa; }
.badge-failed { background: #7f1d1d; color: #fca5a5; }
.badge-shutdown { background: #374151; color: #9ca3af; }

#login-page { display: flex; justify-content: center; align-items: center; min-height: calc(100vh - 50px); }

#btn-logout {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--input-border);
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
}
#btn-logout:hover { border-color: var(--primary); color: var(--primary); }

.filter-bar { display: flex; gap: 0.4rem; margin-bottom: 0.6rem; flex-wrap: wrap; }
.filter-input {
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--input-border);
  border-radius: 4px;
  font-size: 0.75rem;
  background: var(--input-bg);
  color: var(--input-text);
  min-width: 100px;
  flex: 1;
  max-width: 180px;
}
.filter-input:focus { outline: none; border-color: var(--primary); }

/* Mobile responsive */
@media (max-width: 768px) {
  #main-layout { flex-direction: column; }
  #sidebar { width: 100%; min-width: 100%; border-right: none; border-bottom: 1px solid var(--card-border); padding: 0.5rem 0; }
  #sidebar ul { display: flex; overflow-x: auto; gap: 0; }
  #sidebar li { padding: 0.5rem 0.75rem; border-left: none; border-bottom: 3px solid transparent; font-size: 0.75rem; }
  #sidebar li.active { border-left: none; border-bottom-color: var(--sidebar-active-border); }
  #content { padding: 1rem; }
  header { padding: 0.5rem 1rem; }
  header h1 { font-size: 0.9rem; }
  #user-info { font-size: 0.7rem; }
  .card { padding: 1rem; }
  h2 { font-size: 1.1rem; }
  th, td { padding: 0.4rem; font-size: 0.7rem; max-width: 150px; }
  .filter-bar { gap: 0.3rem; }
  .filter-input { min-width: 80px; max-width: 140px; font-size: 0.7rem; }
  .btn-primary, .btn-secondary, .btn-danger { padding: 0.3rem 0.6rem; font-size: 0.7rem; }
}

@media (max-width: 480px) {
  header nav { gap: 0.4rem; }
  #user-info { display: none; }
  th, td { padding: 0.3rem; font-size: 0.65rem; max-width: 100px; }
  .badge { font-size: 0.6rem; padding: 0.05rem 0.3rem; }
}


.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--card-border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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


.refresh-btn {
  cursor: pointer;
  font-size: 1rem;
  opacity: 0.6;
  transition: opacity 0.15s, transform 0.3s;
  vertical-align: middle;
  margin-left: 0.4rem;
}
.refresh-btn:hover {
  opacity: 1;
  transform: rotate(180deg);
}

/* Button loading state */
.btn-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}
.btn-loading::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 6px;
  vertical-align: middle;
}

/* Overlay for form submissions */
.form-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.form-overlay .spinner-large {
  width: 48px;
  height: 48px;
  border: 4px solid var(--card-border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Budget threshold checkboxes */
#cfg-thresholds label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-primary);
  cursor: pointer;
  min-width: 70px;
}
#cfg-thresholds input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--input-border);
  border-radius: 3px;
  background: var(--input-bg);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}
#cfg-thresholds input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}
#cfg-thresholds input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute;
  top: -1px;
  left: 2px;
  color: #fff;
  font-size: 13px;
  font-weight: bold;
}

/* Config loading state */
.config-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 3rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}
