/* =============================================================================
   adt-supabase-cms — base stylesheet
   ----------------------------------------------------------------------------
   The :root vars --primary-color/--primary-hover/--primary-light are set
   per-request by base.html from SystemConfig.ColorTheme. Use them everywhere
   instead of hard-coding hex values.
   ============================================================================= */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
                 Ubuntu, Cantarell, sans-serif;
    color: #1f2937;
    background: #f3f4f6;
    font-size: 14px;
}
a { color: var(--primary-color); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
       background: #e5e7eb; padding: 1px 4px; border-radius: 3px; font-size: 0.92em; }

/* ---------- App shell ---------- */
.app-container { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px;
    background: #111827;
    color: #f9fafb;
    display: flex; flex-direction: column;
    padding: 16px 0;
    transition: width 0.15s ease;
    position: sticky; top: 0; align-self: flex-start;
    height: 100vh; overflow-y: auto;
}
.sidebar-header { padding: 0 20px 16px; border-bottom: 1px solid #1f2937; }
.sidebar-header h2 { margin: 0; font-size: 18px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid #1f2937; }
.sidebar-user .user-icon { font-size: 22px; }
.sidebar-user-info { display: flex; flex-direction: column; font-size: 13px; }
.role-badge {
    display: inline-block; margin-top: 2px; font-size: 11px;
    color: var(--primary-color); text-transform: uppercase; letter-spacing: 0.5px;
}
.nav-menu { list-style: none; margin: 0; padding: 12px 0; flex: 1; }
.nav-menu li { margin: 0; }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 20px; color: #d1d5db; text-decoration: none;
    border-left: 3px solid transparent;
}
.nav-link:hover { background: #1f2937; color: #fff; text-decoration: none; }
.nav-link.active { background: #1f2937; border-left-color: var(--primary-color); color: #fff; }
.nav-icon { display: inline-block; width: 22px; text-align: center; }

.nav-group-toggle {
    width: 100%; background: transparent; border: 0; cursor: pointer;
    font: inherit; text-align: left;
}
.nav-caret {
    margin-left: auto; font-size: 10px; transition: transform 0.15s ease;
}
.nav-group.open > .nav-group-toggle .nav-caret { transform: rotate(180deg); }
.nav-submenu {
    list-style: none; margin: 0; padding: 0;
    max-height: 0; overflow: hidden; transition: max-height 0.15s ease;
}
.nav-group.open > .nav-submenu { max-height: 500px; }
.nav-sublink { padding-left: 44px; font-size: 13px; }
html.sidebar-collapsed .nav-caret { display: none; }
html.sidebar-collapsed .nav-submenu { max-height: 0 !important; }
html.sidebar-collapsed .nav-sublink { padding-left: 20px; }

.sidebar-footer { padding: 0 20px; }
.btn-logout {
    display: flex; align-items: center; gap: 10px;
    background: transparent; color: #d1d5db; padding: 10px 0;
}
.btn-logout:hover { color: #fff; text-decoration: none; }

.main-content { flex: 1; min-width: 0; }
.content-header {
    background: #fff; border-bottom: 1px solid #e5e7eb;
    padding: 14px 24px; display: flex; align-items: center; gap: 12px;
}
.content-header h1 { margin: 0; font-size: 20px; font-weight: 600; }
.sidebar-toggle {
    background: transparent; border: 0; font-size: 20px; cursor: pointer; color: #4b5563;
}
.content-body { padding: 24px; }

html.sidebar-collapsed .sidebar { width: 64px; }
html.sidebar-collapsed .sidebar-label { display: none; }

/* ---------- Section cards ---------- */
.section-card {
    background: #fff; border: 1px solid #e5e7eb; border-radius: 6px;
    padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.section-title { margin: 0 0 16px; font-size: 16px; font-weight: 600; color: #111827; }
.section-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.section-header-row .section-title { margin: 0; }
.section-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.record-info { color: #6b7280; font-size: 12px; }

/* ---------- Forms ---------- */
.form-card form { max-width: 900px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.form-group { margin-bottom: 16px; display: flex; flex-direction: column; }
.form-group label { font-weight: 500; margin-bottom: 6px; color: #374151; font-size: 13px; }
.form-group label small { font-weight: 400; color: #9ca3af; margin-left: 4px; }
.form-control {
    border: 1px solid #d1d5db; border-radius: 4px; padding: 8px 10px;
    font-size: 14px; background: #fff; color: #111827; font-family: inherit;
}
.form-control:focus { outline: 2px solid var(--primary-light); border-color: var(--primary-color); }
.form-control[readonly] { background: #f3f4f6; color: #6b7280; }
.code-area {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px; min-height: 460px; white-space: pre;
}
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.checkbox-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block; cursor: pointer; border: 0; border-radius: 4px;
    padding: 8px 14px; font-size: 14px; font-weight: 500;
    text-decoration: none; text-align: center; line-height: 1.2;
    background: #e5e7eb; color: #1f2937; transition: filter 0.1s;
}
.btn:hover { text-decoration: none; filter: brightness(0.95); }
.btn:disabled, .btn-disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary  { background: var(--primary-color); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary{ background: #e5e7eb; color: #1f2937; }
.btn-success  { background: #16a34a; color: #fff; }
.btn-warning  { background: #ca8a04; color: #fff; }
.btn-danger   { background: #dc2626; color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }
.btn-block { display: block; width: 100%; }

/* ---------- Tables ---------- */
.table-container { overflow-x: auto; border: 1px solid #e5e7eb; border-radius: 4px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; background: #fff; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #e5e7eb; vertical-align: top; }
.data-table th { background: #f9fafb; font-weight: 600; color: #374151; }
.data-table tbody tr:hover { background: #f9fafb; }
.empty-state { text-align: center; color: #6b7280; padding: 24px; }
.nowrap { white-space: nowrap; }

/* ---------- Table filter bar / sorting / pagination ---------- */
.table-filters {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 16px;
}
.table-filter { display: flex; flex-direction: column; gap: 4px; }
.table-filter label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: #6b7280; }
.table-filter .form-control { padding: 6px 8px; font-size: 13px; }
.data-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.data-table th.sortable:hover { background: #f3f4f6; }
.sort-arrow { color: var(--primary-color); font-size: 11px; }
.table-pager {
    display: flex; align-items: center; gap: 12px; justify-content: flex-end; margin-top: 12px;
}
.table-pager .tv-info { min-width: 90px; text-align: center; }

/* ---------- Badges ---------- */
.status-badge {
    display: inline-block; padding: 2px 8px; border-radius: 12px;
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
    background: #e5e7eb; color: #374151;
}
.status-Created    { background: #e0e7ff; color: #3730a3; }
.status-Deploying  { background: #fef3c7; color: #92400e; }
.status-Running    { background: #dcfce7; color: #166534; }
.status-Stopping   { background: #fed7aa; color: #9a3412; }
.status-Stopped    { background: #e5e7eb; color: #374151; }
.status-Starting   { background: #fef3c7; color: #92400e; }
.status-Failed     { background: #fee2e2; color: #991b1b; }
.status-Healthy    { background: #dcfce7; color: #166534; }
.status-Degraded   { background: #fef3c7; color: #92400e; }
.status-Down       { background: #fee2e2; color: #991b1b; }
.status-Unknown    { background: #e5e7eb; color: #6b7280; }
.status-Success    { background: #dcfce7; color: #166534; }
.status-Running    { background: #fef3c7; color: #92400e; }
.status-pending    { background: #fef3c7; color: #92400e; }
.status-active     { background: #dcfce7; color: #166534; }
.status-disabled   { background: #fee2e2; color: #991b1b; }
.role-superadmin   { background: #ede9fe; color: #5b21b6; }
.role-user         { background: #e0e7ff; color: #3730a3; }
.badge-success { background: #dcfce7; color: #166534; padding: 2px 8px; border-radius: 4px; font-size: 11px; }
.badge-warning { background: #fef3c7; color: #92400e; padding: 2px 8px; border-radius: 4px; font-size: 11px; }
.badge-danger  { background: #fee2e2; color: #991b1b; padding: 2px 8px; border-radius: 4px; font-size: 11px; }

/* ---------- Alerts ---------- */
.alert {
    border-radius: 4px; padding: 10px 14px; margin-bottom: 16px;
    border-left: 4px solid; font-size: 14px;
}
.alert-success { background: #ecfdf5; border-color: #16a34a; color: #064e3b; }
.alert-error   { background: #fef2f2; border-color: #dc2626; color: #7f1d1d; }

/* ---------- Login ---------- */
.login-body {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--primary-light), #fff);
}
.login-container { width: 100%; max-width: 380px; padding: 20px; }
.login-card { background: #fff; padding: 32px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.login-header { text-align: center; margin-bottom: 24px; }
.login-header h1 { margin: 0 0 6px; font-size: 22px; color: #111827; }
.login-header p { color: #6b7280; margin: 0; font-size: 13px; }
.login-footnote { color: #9ca3af; font-size: 12px; text-align: center; margin-top: 16px; }

/* ---------- Dashboard stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.stat-tile { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px; padding: 16px; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: #6b7280; }
.stat-value { font-size: 26px; font-weight: 600; color: #111827; margin: 6px 0; }
.stat-sub { font-size: 12px; color: #6b7280; margin-top: 4px; }
.stat-bar { background: #e5e7eb; height: 6px; border-radius: 3px; overflow: hidden; }
.stat-bar-fill { background: var(--primary-color); height: 100%; width: 0%; transition: width 0.3s ease; }
.stat-footnote { color: #6b7280; font-size: 12px; margin-top: 12px; }

/* ---------- Modal ---------- */
.modal {
    display: none; position: fixed; inset: 0; background: rgba(17,24,39,0.55);
    align-items: center; justify-content: center; z-index: 1000;
}
.modal-content {
    background: #fff; border-radius: 8px; padding: 20px; width: 480px; max-width: 92vw;
    max-height: 90vh; overflow: auto;
}
.modal-content-large { width: 900px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-header h3 { margin: 0; }
.modal-close { background: transparent; border: 0; font-size: 22px; cursor: pointer; color: #6b7280; }
.log-pre {
    background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
    white-space: pre-wrap; word-break: break-word; max-height: 60vh; overflow: auto;
}
