/* ============================================
   Amebo Design System
   Bootstrap 5.3 + Custom Properties
   ============================================ */

:root,
[data-bs-theme="light"] {
  --amebo-bg: #ffffff;
  --amebo-bg-subtle: #f8f9fa;
  --amebo-bg-hover: #f1f3f5;
  --amebo-border: #e9ecef;
  --amebo-border-subtle: #f1f3f5;
  --amebo-text: #212529;
  --amebo-text-muted: #868e96;
  --amebo-text-light: #adb5bd;
  --amebo-sidebar-bg: #ffffff;
  --amebo-sidebar-border: #f1f3f5;
  --amebo-sidebar-hover: #f8f9fa;
  --amebo-sidebar-active-bg: #f8f9fa;
  --amebo-sidebar-active-border: #212529;
  --amebo-card-bg: #ffffff;
  --amebo-code-bg: #f8f9fa;
  --amebo-accent: #228be6;
  --amebo-success: #40c057;
  --amebo-warning: #fab005;
  --amebo-danger: #fa5252;
  --amebo-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --amebo-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --amebo-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);
}

[data-bs-theme="dark"] {
  --amebo-bg: #1a1b1e;
  --amebo-bg-subtle: #25262b;
  --amebo-bg-hover: #2c2e33;
  --amebo-border: #373a40;
  --amebo-border-subtle: #2c2e33;
  --amebo-text: #c1c2c5;
  --amebo-text-muted: #909296;
  --amebo-text-light: #5c5f66;
  --amebo-sidebar-bg: #1a1b1e;
  --amebo-sidebar-border: #25262b;
  --amebo-sidebar-hover: #25262b;
  --amebo-sidebar-active-bg: #25262b;
  --amebo-sidebar-active-border: #c1c2c5;
  --amebo-card-bg: #25262b;
  --amebo-code-bg: #2c2e33;
  --amebo-accent: #4dabf7;
  --amebo-success: #51cf66;
  --amebo-warning: #fcc419;
  --amebo-danger: #ff6b6b;
  --amebo-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --amebo-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --amebo-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.3);
}


/* ---- Typography ---- */

body, html {
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--amebo-bg);
  color: var(--amebo-text);
  font-size: 14px;
}

.font-mono {
  font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  font-size: 0.85em;
}

.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.8125rem; }
.text-muted-custom { color: var(--amebo-text-muted); }


/* ---- App Layout ---- */

.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.app-sidebar {
  width: 64px;
  min-width: 64px;
  height: 100vh;
  background: var(--amebo-sidebar-bg);
  border-right: 1px solid var(--amebo-sidebar-border);
  display: flex;
  flex-direction: column;
  transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1),
              min-width 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  position: relative;
  z-index: 30;
}

.app-sidebar.expanded {
  width: 240px;
  min-width: 240px;
}

.app-main {
  flex: 1;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--amebo-bg);
}

.app-main > section,
.app-main > section > div,
.app-main > section > template + div {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Static top area: page header + filters stay pinned */
.page-header,
.filter-bar {
  flex-shrink: 0;
}

/* Table wrapper fills remaining space and scrolls */
.data-table-wrapper {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--amebo-border-subtle);
  border-radius: 8px;
  background: var(--amebo-card-bg);
}

.page-content-scroll {
  padding: 2rem 2.5rem 0;
  flex-shrink: 0;
}

.page-table-area {
  flex: 1;
  min-height: 0;
  padding: 0 2.5rem 1rem;
  display: flex;
  flex-direction: column;
}

/* Hide x-cloak elements until Alpine initializes */
[x-cloak] { display: none !important; }


/* ---- Sidebar ---- */

.sidebar-brand {
  height: 64px;
  display: flex;
  align-items: center;
  padding: 0 18px;
  gap: 12px;
  white-space: nowrap;
  overflow: hidden;
  border-bottom: 1px solid var(--amebo-sidebar-border);
}

.brand-icon {
  font-size: 26px;
  color: var(--amebo-text);
  min-width: 26px;
}

.brand-text {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.5px;
  color: var(--amebo-text);
}

.brand-version {
  font-size: 0.7rem;
  color: var(--amebo-text-muted);
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar { display: none; }

.sidebar-nav .nav-link,
.sidebar-footer .nav-link {
  display: flex;
  align-items: center;
  height: 44px;
  padding: 0 20px;
  color: var(--amebo-text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.875rem;
  white-space: nowrap;
  transition: all 0.15s;
  border-left: 3px solid transparent;
  gap: 14px;
  cursor: pointer;
  background: transparent;
  border-top: none;
  border-right: none;
  border-bottom: none;
  width: 100%;
  text-align: left;
}

.sidebar-nav .nav-link:hover,
.sidebar-footer .nav-link:hover {
  background: var(--amebo-sidebar-hover);
  color: var(--amebo-text);
}

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

.nav-icon {
  font-size: 22px;
  min-width: 22px;
  color: inherit;
}

.nav-label {
  font-size: 0.875rem;
}


/* ---- Sidebar Footer ---- */

.sidebar-footer {
  padding: 0.5rem;
  border-top: 1px solid var(--amebo-sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-footer .theme-toggle,
.sidebar-footer .sidebar-toggle {
  border-left: 3px solid transparent;
  padding: 0 17px;
}

.new-resource-btn {
  overflow: hidden;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 4px;
}

.new-resource-btn .btn-label {
  font-size: 0.8125rem;
}


/* ---- Page Header ---- */

.page-header {
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--amebo-text);
  margin: 0;
}

.page-subtitle {
  font-size: 0.8125rem;
  color: var(--amebo-text-muted);
  margin: 0.125rem 0 0;
}


/* ---- Filter Bar ---- */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--amebo-bg-subtle);
  border-radius: 8px;
  border: 1px solid var(--amebo-border-subtle);
}

.filter-bar .form-control,
.filter-bar .form-select {
  font-size: 0.8125rem;
  background: var(--amebo-bg);
  border-color: var(--amebo-border);
  color: var(--amebo-text);
  height: 34px;
  padding: 0.25rem 0.625rem;
}

.filter-bar .form-control:focus,
.filter-bar .form-select:focus {
  border-color: var(--amebo-accent);
  box-shadow: 0 0 0 2px rgba(34, 139, 230, 0.15);
}

.filter-bar .input-icon {
  position: relative;
}

.filter-bar .input-icon .material-icons {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  color: var(--amebo-text-light);
  pointer-events: none;
}

.filter-bar .input-icon .form-control {
  padding-left: 32px;
}


/* ---- Data Table ---- */

.data-table-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.data-table-scroll::-webkit-scrollbar {
  width: 5px;
}
.data-table-scroll::-webkit-scrollbar-track {
  background: transparent;
}
.data-table-scroll::-webkit-scrollbar-thumb {
  background: var(--amebo-border);
  border-radius: 3px;
}

.data-table {
  width: 100%;
  margin: 0;
  font-size: 0.8125rem;
  color: var(--amebo-text);
  table-layout: fixed;
}

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

.data-table thead th {
  background: var(--amebo-bg-subtle);
  border-bottom: 1px solid var(--amebo-border) !important;
  color: var(--amebo-text-muted);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.625rem 1rem;
  white-space: nowrap;
  vertical-align: middle;
}

.data-table tbody td {
  padding: 0.625rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--amebo-border-subtle);
  color: var(--amebo-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table tbody tr {
  transition: background 0.1s;
}

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

.data-table tbody tr:last-child td {
  border-bottom: none;
}


/* ---- Tags & Badges ---- */

.tag-id {
  display: inline-block;
  max-width: 100%;
  padding: 2px 8px;
  background: var(--amebo-bg-subtle);
  border: 1px solid var(--amebo-border);
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: var(--amebo-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.6875rem;
  font-weight: 600;
}

.badge-status.success {
  background: rgba(64, 192, 87, 0.1);
  color: var(--amebo-success);
}

.badge-status.danger {
  background: rgba(250, 82, 82, 0.1);
  color: var(--amebo-danger);
}

.badge-status.warning {
  background: rgba(250, 176, 5, 0.1);
  color: var(--amebo-warning);
}


/* ---- Pagination ---- */

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--amebo-border-subtle);
  background: var(--amebo-bg-subtle);
  font-size: 0.8125rem;
  color: var(--amebo-text-muted);
  flex-shrink: 0;
}

.pagination-bar .btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--amebo-border);
  background: var(--amebo-bg);
  color: var(--amebo-text);
  cursor: pointer;
  transition: all 0.15s;
}

.pagination-bar .btn-icon:hover:not(:disabled) {
  background: var(--amebo-bg-hover);
  border-color: var(--amebo-text-light);
}

.pagination-bar .btn-icon:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pagination-bar .page-input {
  width: 48px;
  height: 32px;
  text-align: center;
  border: 1px solid var(--amebo-border);
  border-radius: 6px;
  background: var(--amebo-bg);
  color: var(--amebo-text);
  font-size: 0.8125rem;
  font-weight: 600;
}

.pagination-bar .rows-select {
  height: 32px;
  padding: 0 0.5rem;
  border: 1px solid var(--amebo-border);
  border-radius: 6px;
  background: var(--amebo-bg);
  color: var(--amebo-text);
  font-size: 0.8125rem;
}


/* ---- Code / JSON Display ---- */

.code-block {
  background: var(--amebo-code-bg);
  border: 1px solid var(--amebo-border);
  border-radius: 8px;
  padding: 1rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8125rem;
  line-height: 1.6;
  overflow-x: auto;
  color: var(--amebo-text);
  white-space: pre-wrap;
  word-break: break-word;
}


/* ---- Detail Panel (Preview) ---- */

.detail-panel {
  background: var(--amebo-card-bg);
  border: 1px solid var(--amebo-border);
  border-radius: 8px;
  overflow: hidden;
}

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


/* ---- Full-height Preview Layout (Actions schema) ---- */

.preview-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.preview-cards {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 1rem;
  padding: 0 2.5rem 1.5rem;
  overflow: hidden;
}

.preview-detail-card {
  width: 300px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
}

.preview-schema-card {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.preview-editor-ace {
  flex: 1;
  min-height: 0;
}

/* Ensure ACE fills its container */
.preview-editor-ace .ace_editor {
  width: 100% !important;
  height: 100% !important;
}

.detail-panel-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--amebo-border-subtle);
  margin-top: auto;
}


/* ---- Payload ACE Viewer (Events modal) ---- */

.payload-ace-viewer {
  width: 100%;
  min-height: 200px;
}

.payload-ace-viewer .ace_editor {
  width: 100% !important;
}

.detail-panel-body {
  padding: 1.25rem;
}

.detail-field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--amebo-border-subtle);
}

.detail-field:last-child {
  border-bottom: none;
}

.detail-field .field-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--amebo-text-muted);
}

.detail-field .field-value {
  font-weight: 500;
  color: var(--amebo-text);
}


/* ---- Modals ---- */

.modal-content {
  background: var(--amebo-card-bg);
  border: 1px solid var(--amebo-border);
}

.modal-header {
  padding: 1.25rem 1.5rem 0.75rem;
}

.modal-title {
  font-size: 1.125rem;
}

.modal-body {
  padding: 1rem 1.5rem;
}

.modal-footer {
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--amebo-border-subtle);
}

.form-label-sm {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--amebo-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 0.375rem;
}


/* ---- Buttons ---- */

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid var(--amebo-border);
  background: var(--amebo-bg);
  color: var(--amebo-text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-action:hover {
  background: var(--amebo-bg-hover);
  color: var(--amebo-text);
  border-color: var(--amebo-text-light);
}

.btn-action .material-icons {
  font-size: 16px;
}


/* ---- Empty State ---- */

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--amebo-text-light);
}

.empty-state .material-icons {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  opacity: 0.4;
}

.empty-state p {
  margin: 0;
  font-size: 0.875rem;
}


/* ---- Loading ---- */

.loading-spinner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--amebo-text-muted);
  font-size: 0.8125rem;
}

.loading-spinner .spinner-border {
  width: 1rem;
  height: 1rem;
  border-width: 2px;
}


/* ---- Ace Editor Overrides ---- */

#schemator, .ace-editor-container {
  border: 1px solid var(--amebo-border);
  border-radius: 8px;
  overflow: hidden;
}


/* ---- Utility Classes ---- */

.border-subtle { border-color: var(--amebo-border-subtle) !important; }
.bg-subtle { background: var(--amebo-bg-subtle) !important; }
.cursor-pointer { cursor: pointer; }
.transition-all { transition: all 0.15s ease; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }

/* Scrollbar styling */
.data-table-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--amebo-text-light);
}


/* ---- Login Page ---- */

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--amebo-bg-subtle);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--amebo-card-bg);
  border: 1px solid var(--amebo-border);
  border-radius: 12px;
  padding: 2.5rem;
  box-shadow: var(--amebo-shadow-lg);
}

.login-card .login-logo {
  width: 56px;
  height: 56px;
  margin-bottom: 1.5rem;
}

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.login-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--amebo-border);
}

.login-tabs button {
  flex: 1;
  padding: 0.625rem 1rem;
  border: none;
  background: transparent;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--amebo-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.login-tabs button.active {
  color: var(--amebo-text);
  border-bottom-color: var(--amebo-text);
}

.login-tabs button:hover:not(.active) {
  color: var(--amebo-text);
}
