:root {
  --primary-color: #1565c0;
  --primary-dark: #0d47a1;
  --primary-light: #e3f2fd;
  --success-color: #4caf50;
  --warning-color: #ff9800;
  --error-color: #f44336;
  --text-color: #333;
  --text-light: #666;
  --background-color: #f5f5f5;
  --card-color: #fff;
  --border-color: #ddd;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  line-height: 1.6;
  color: var(--text-color);
  background-color: var(--background-color);
  padding: 20px;
}

.container {
  max-width: 1040px;
  margin: 0 auto;
  background-color: var(--card-color);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 30px;
}

header {
  text-align: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

.logo-container {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.logo {
  max-width: 105px;
  height: auto;
}

h1 {
  color: var(--primary-color);
  margin-bottom: 10px;
}

.tagline {
  color: var(--text-light);
  font-size: 1.1em;
}

.warning-box {
  background-color: #fff3e0;
  border-left: 4px solid var(--warning-color);
  padding: 15px;
  margin-bottom: 25px;
  border-radius: 4px;
}

.warning-box h3 {
  color: var(--warning-color);
  margin-bottom: 15px;
}

.warning-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.warning-item {
  background-color: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 0.85rem;
  line-height: 1.3;
  min-height: 40px;
  display: flex;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

@media (max-width: 1024px) {
  .warning-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .warning-grid {
    grid-template-columns: 1fr;
  }
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 15px;
}

.info-item {
  background-color: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 0.85rem;
  line-height: 1.3;
  min-height: 40px;
  display: flex;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

@media (max-width: 1024px) {
  .info-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .info-grid {
    grid-template-columns: 1fr;
  }
}

.form-group {
  margin-bottom: 20px;
}

label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
}

input[type="text"],
input[type="password"],
input[type="url"],
select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 16px;
  background-color: white;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="url"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(21, 101, 192, 0.2);
}

/* App message styling */
.app-message {
  background-color: #e3f2fd;
  border-left: 4px solid var(--primary-color);
  padding: 15px;
  margin: 15px 0;
  border-radius: 4px;
  font-style: italic;
  color: var(--text-color);
}

small {
  display: block;
  color: var(--text-light);
  margin-top: 5px;
  font-size: 0.85em;
}

.form-actions {
  margin-top: 30px;
  text-align: center;
}

button {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 12px 24px;
  font-size: 16px;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

button:hover {
  background-color: var(--primary-dark);
}

#back-btn, #restart-btn {
  background-color: #757575;
  margin-top: 20px;
}

#back-btn:hover, #restart-btn:hover {
  background-color: #616161;
}

.hidden {
  display: none;
}

/* Modal overlay */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  /* default hidden; shown via :not(.hidden) below */
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

/* Show modal only when hidden class is removed */
.modal:not(.hidden) {
  display: flex;
}

.modal .modal-content {
  background: #fff;
  width: min(720px, 92vw);
  max-height: 90vh;
  overflow: auto;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  padding: 20px;
}

.modal .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.modal .modal-close {
  background: transparent;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-light);
}

.modal .form-group label {
  font-weight: 600;
}

.modal .form-actions {
  display: flex;
  justify-content: flex-end;
}

/* New: delete app button */
.delete-app-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #ffffffcc; /* slight contrast to list background */
  color: #888;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  z-index: 50; /* ensure above list content */
}

.delete-app-btn:hover {
  background: #ffecec;
  color: #c62828;
}

#credentialsSection {
  background-color: var(--card-color);
  padding: 20px;
  border-radius: 8px;
  margin-top: 30px;
  border: 1px solid var(--border-color);
}

#credentialsSection h2 {
  margin-bottom: 20px;
  color: var(--primary-color);
}

/* Success and Error Messages */
.success-message {
  background-color: #e8f5e9;
  border-left: 4px solid var(--success-color);
  padding: 15px;
  margin: 20px 0;
  border-radius: 4px;
}

.error-message {
  background-color: #ffebee;
  border-left: 4px solid var(--error-color);
  padding: 15px;
  margin: 20px 0;
  border-radius: 4px;
}

#restartButton {
  display: block;
  margin: 20px auto;
}

/* Terminal window styles */
#terminal-window {
  margin: 30px 0;
  background-color: #1e1e1e;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  font-family: 'Courier New', monospace;
  width: 100%;
}

.terminal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #323232;
  padding: 8px 12px;
  border-bottom: 1px solid #444;
}

.terminal-title {
  color: #ddd;
  font-size: 0.9rem;
}



.terminal-content {
  padding: 12px;
  color: #ddd;
  min-height: 250px;
  max-height: 400px;
  overflow-y: auto;
}

#terminal {
  white-space: pre-wrap;
  font-size: 0.9rem;
  line-height: 1.4;
  margin: 0;
}

.command-line {
  color: #63c563;
  margin-bottom: 5px;
}

.command-line::before {
  content: '$ ';
  color: #63c563;
}

.output-line {
  color: #ddd;
  margin-bottom: 5px;
}

.error-line {
  color: #ff5f56;
  margin-bottom: 5px;
}

.success-line {
  color: #27c93f;
  margin-bottom: 5px;
}

.warning-line {
  color: #ffbd2e;
  margin-bottom: 5px;
}

/* Hide the old console output */
#console-output {
  display: none;
}



#error-details {
  background-color: #f5f5f5;
  padding: 15px;
  margin: 15px 0;
  border-radius: 4px;
  text-align: left;
  font-family: 'Courier New', Courier, monospace;
  font-size: 14px;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

footer {
  margin-top: 40px;
  text-align: center;
  color: var(--text-light);
  font-size: 0.9em;
  border-top: 1px solid var(--border-color);
  padding-top: 20px;
}

footer p {
  margin: 5px 0;
}

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

footer a:hover {
  text-decoration: underline;
}

/* Toast / Snackbar */
#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(51, 51, 51, 0.95);
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  font-size: 14px;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Catalogue Section Styles */
#catalogueSection {
  margin-bottom: 40px;
  padding-bottom: 30px;
  border-bottom: 1px solid var(--border-color);
}

#catalogueSection h2 {
  color: var(--primary-color);
  margin-bottom: 8px;
}

#catalogueSection .catalogue-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

#catalogueSection .catalogue-toolbar #layoutToggle {
  flex: 0 0 auto;
}

#catalogueSection .catalogue-toolbar .add-app-btn {
  margin-left: auto; /* push to right */
}

/* Layout toggle */
.layout-toggle {
  display: inline-flex;
  background: #e9ecef;
  border-radius: 6px;
}

.toggle-btn {
  background: #eef5ff;
  color: var(--primary-dark);
  border: 1px solid var(--primary-color);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
}

.toggle-btn.is-active {
  background: var(--primary-color);
  color: #fff;
}

.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin: 20px 0;
}

/* List layout container */
.apps-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 20px 0;
}

/* List Item Container - Column Flex */
.app-list-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  background-color: #f8f9fa;
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

/* Rows */
.app-list-row {
  display: flex;
  align-items: center;
  width: 100%;
}
.app-list-row.top { gap: 12px; }
.app-list-row.bottom { padding-left: 0; }

/* Elements */
.spacer { flex-grow: 1; }

.app-author {
  color: var(--text-light);
  font-size: 0.85em;
  white-space: nowrap;
}

.app-note {
  color: var(--text-color);
  font-size: 0.9em;
  line-height: 1.4;
}

/* List View Specific Overrides */
.app-list-item .app-description {
  flex: 0 1 auto;
  max-width: 40%; /* Prevent long descriptions from pushing actions */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}

.app-list-item .app-note {
  margin: 0;
  color: var(--text-light);
  text-align: left;
}

.apps-list .app-actions {
  padding-right: 0;
  margin-left: 0; /* Spacer handles push */
  flex-direction: row;
  gap: 6px;
  flex-wrap: nowrap;
}

/* Compact buttons in list mode only */
.apps-list .btn-primary, .apps-list .btn-secondary {
  padding: 6px 10px;
  font-size: 12px;
}

/* List-specific delete icon positioning and safety */
.apps-list .app-list-item .delete-app-btn {
  position: static; /* inline within actions for list mode */
  width: 28px;
  height: 28px;
  background: transparent;
  margin-left: 6px;
}

/* Mobile Responsive List Adjustments */
@media (max-width: 768px) {
  .app-list-row.top {
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .app-list-item .app-description {
    flex-basis: 100%;
    max-width: 100%;
    white-space: normal;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
  }

  .spacer { display: none; }
  
  .app-list-item .app-actions {
    margin-top: 8px;
    width: 100%;
    justify-content: flex-end;
  }
}

.app-card {
  background-color: #f8f9fa;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 16px;
  transition: box-shadow 0.2s, transform 0.2s;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

.app-card:hover {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.app-name {
  color: var(--primary-color);
  margin-bottom: 8px;
  font-size: 1.08em;
  font-weight: 600;
}

.app-description {
  color: var(--text-color);
  margin-bottom: 12px;
  font-style: italic;
  flex-grow: 1;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3; /* clamp to 3 lines on desktop */
  line-clamp: 3;
  -webkit-box-orient: vertical;
}

.app-actions {
  display: flex;
  gap: 8px;
  flex-direction: column;
}

.btn-primary, .btn-secondary {
  padding: 8px 12px;
  border-radius: 4px;
  text-decoration: none;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  display: inline-block;
}

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

.btn-primary:hover {
  background-color: var(--primary-dark);
}

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

.btn-secondary:hover {
  background-color: var(--primary-light);
  text-decoration: none;
}

.loading-message, .no-apps-message, .error-message {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
  font-style: italic;
}

.error-message {
  color: var(--error-color);
}

/* Responsive adjustments for catalogue */
@media (max-width: 768px) {
  .apps-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .apps-list {
    gap: 10px;
  }
  
  .app-card {
    padding: 14px;
  }

  .app-list-item {
    padding: 12px 14px;
  }
  
  .app-actions {
    gap: 6px;
  }
  
  .btn-primary, .btn-secondary {
    padding: 10px 14px;
    font-size: 15px;
  }

  /* Clamp descriptions tighter on mobile for compactness */
  .app-description {
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }
}

@media (min-width: 769px) {
  .app-actions {
    flex-direction: row;
  }
  
  .btn-primary {
    flex: 1;
  }
  
  .btn-secondary {
    flex: 0 0 auto;
    white-space: nowrap;
  }
}

@media (max-width: 600px) {
  .container {
    padding: 15px;
  }
  
  button {
    width: 100%;
  }
}

/* Turnstile widget styling */
.turnstile-container {
  display: flex;
  justify-content: center;
  margin: 15px 0;
}

.turnstile-container > div {
  display: flex;
  justify-content: center;
}

/* Hide Turnstile containers by default - they will be shown when Turnstile is enabled */
.turnstile-container:empty {
  display: none;
}
