/* ==========================================================================
   Cryrex Admin Panel — Dark Theme CSS
   ========================================================================== */

/* --- Reset & Base -------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    background: #0f0f1a;
    color: #d0d0e0;
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: #7c8aff;
    text-decoration: none;
}
a:hover {
    color: #a0aaff;
    text-decoration: underline;
}

/* --- Layout -------------------------------------------------------------- */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar ------------------------------------------------------------- */
.sidebar {
    width: 220px;
    background: #151528;
    border-right: 1px solid #252540;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 24px 20px 16px;
    border-bottom: 1px solid #252540;
}

.logo {
    font-size: 1.4rem;
    font-weight: 700;
    color: #7c8aff;
    letter-spacing: 3px;
}

.logo-sub {
    display: block;
    font-size: 0.75rem;
    color: #606080;
    margin-top: 2px;
    letter-spacing: 1px;
}

.nav-links {
    list-style: none;
    padding: 12px 0;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: #9090b0;
    font-size: 0.9rem;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
}
.nav-link:hover {
    background: #1e1e38;
    color: #d0d0e0;
    text-decoration: none;
}
.nav-link.active {
    background: #1e1e38;
    color: #7c8aff;
    border-right: 3px solid #7c8aff;
}

.nav-icon {
    font-size: 0.7rem;
    width: 16px;
    text-align: center;
}

.sidebar-footer {
    padding: 12px 0;
    border-top: 1px solid #252540;
}

.admin-name {
    display: block;
    padding: 4px 20px 8px;
    font-size: 0.75rem;
    color: #606080;
}

.nav-logout {
    color: #cc6666;
}
.nav-logout:hover {
    color: #ff8888;
    background: #281828;
}

/* --- Main Content -------------------------------------------------------- */
.main-content {
    flex: 1;
    margin-left: 220px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.content-header {
    padding: 20px 28px;
    background: #151528;
    border-bottom: 1px solid #252540;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.content-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
    color: #e0e0f0;
}

.content-body {
    padding: 24px 28px;
    flex: 1;
}

/* --- Stat Cards ---------------------------------------------------------- */
.stat-cards {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.stat-card {
    background: #1a1a30;
    border: 1px solid #252540;
    border-radius: 8px;
    padding: 20px 24px;
    min-width: 140px;
    flex: 1;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: #e0e0f0;
    line-height: 1;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 0.8rem;
    color: #707090;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card-success { border-left: 3px solid #44cc88; }
.stat-card-success .stat-value { color: #44cc88; }
.stat-card-warning { border-left: 3px solid #ccaa44; }
.stat-card-warning .stat-value { color: #ccaa44; }
.stat-card-danger { border-left: 3px solid #cc4444; }
.stat-card-danger .stat-value { color: #cc4444; }
.stat-card-muted { border-left: 3px solid #666680; }
.stat-card-muted .stat-value { color: #666680; }

/* --- Panels -------------------------------------------------------------- */
.panel {
    background: #1a1a30;
    border: 1px solid #252540;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.panel-title {
    font-size: 1rem;
    font-weight: 600;
    color: #c0c0d8;
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid #252540;
}

/* --- Tables -------------------------------------------------------------- */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: 10px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #707090;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #252540;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #1e1e35;
    font-size: 0.85rem;
    vertical-align: middle;
}

.data-table tbody tr:nth-child(even) {
    background: #161628;
}

.data-table tbody tr:hover {
    background: #1e1e38;
}

/* Detail table (key-value pairs) */
.detail-table {
    width: 100%;
    border-collapse: collapse;
}

.detail-table th {
    text-align: left;
    padding: 8px 12px;
    width: 180px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #707090;
    border-bottom: 1px solid #1e1e35;
    vertical-align: top;
}

.detail-table td {
    padding: 8px 12px;
    font-size: 0.85rem;
    border-bottom: 1px solid #1e1e35;
}

.detail-table .section-header th {
    padding-top: 16px;
    color: #7c8aff;
    font-size: 0.85rem;
    border-bottom: 1px solid #303050;
}

/* --- Badges -------------------------------------------------------------- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.badge-stable {
    background: #1a3320;
    color: #44cc88;
}
.badge-canary {
    background: #332a1a;
    color: #ccaa44;
}
.badge-success {
    background: #1a3320;
    color: #44cc88;
}
.badge-warning {
    background: #332a1a;
    color: #ccaa44;
}
.badge-danger {
    background: #331a1a;
    color: #cc4444;
}
.badge-muted {
    background: #252530;
    color: #707090;
}
.badge-event {
    background: #1a2033;
    color: #7c8aff;
}

/* --- Buttons ------------------------------------------------------------- */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, opacity 0.15s;
    line-height: 1.4;
}
.btn:hover {
    opacity: 0.85;
    text-decoration: none;
}

.btn-primary {
    background: #4c5ccc;
    color: #fff;
}
.btn-primary:hover {
    background: #5c6cdd;
    color: #fff;
}

.btn-success {
    background: #2a8855;
    color: #fff;
}
.btn-success:hover {
    background: #339966;
    color: #fff;
}

.btn-danger {
    background: #aa3333;
    color: #fff;
}
.btn-danger:hover {
    background: #cc4444;
    color: #fff;
}

.btn-warning {
    background: #997722;
    color: #fff;
}
.btn-warning:hover {
    background: #aa8833;
    color: #fff;
}

.btn-muted {
    background: #303045;
    color: #9090b0;
}
.btn-muted:hover {
    background: #404060;
    color: #c0c0d0;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.75rem;
}

.btn-block {
    display: block;
    width: 100%;
    text-align: center;
}

/* --- Forms --------------------------------------------------------------- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #9090b0;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group input[type="file"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    background: #0f0f1a;
    border: 1px solid #303050;
    border-radius: 6px;
    color: #d0d0e0;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #5c6cdd;
}

.form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.form-group select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23707090' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.form-hint {
    display: block;
    font-size: 0.75rem;
    color: #606080;
    margin-top: 4px;
}

.form-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.form-row .form-group {
    flex: 1;
    min-width: 140px;
    margin-bottom: 0;
}

.form-group-btn {
    flex: 0 0 auto !important;
    min-width: auto !important;
    display: flex;
    gap: 8px;
}

.form-actions {
    margin-top: 16px;
    display: flex;
    gap: 10px;
}

.form-inline {
    margin-bottom: 0;
}

.inline-form {
    display: inline-block;
    margin-right: 4px;
}

.filter-form .form-row {
    align-items: flex-end;
}

.file-input {
    padding: 8px !important;
}

/* --- Checkbox ------------------------------------------------------------ */
.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
}

.checkbox-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #5c6cdd;
}

.checkbox-group label {
    margin-bottom: 0;
    text-transform: none;
    font-weight: 400;
    font-size: 0.85rem;
}

/* --- Alerts -------------------------------------------------------------- */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 0.85rem;
}

.alert-danger {
    background: #2a1111;
    border: 1px solid #442222;
    color: #ee6666;
}

.alert-success {
    background: #112a11;
    border: 1px solid #224422;
    color: #66cc88;
}

/* --- Login Page ---------------------------------------------------------- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #0a0a16;
}

.login-container {
    width: 100%;
    max-width: 380px;
    padding: 20px;
}

.login-card {
    background: #151528;
    border: 1px solid #252540;
    border-radius: 12px;
    padding: 32px;
}

.login-header {
    text-align: center;
    margin-bottom: 28px;
}

.login-header .logo {
    font-size: 1.8rem;
}

.login-form .form-group {
    margin-bottom: 18px;
}

.login-form .btn {
    margin-top: 8px;
    padding: 12px;
    font-size: 0.95rem;
}

/* --- Tabs ---------------------------------------------------------------- */
.tab-bar {
    display: flex;
    gap: 0;
    margin-bottom: 0;
    border-bottom: 1px solid #252540;
}

.tab-btn {
    padding: 10px 20px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: #707090;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
    color: #b0b0d0;
}

.tab-btn.active {
    color: #7c8aff;
    border-bottom-color: #7c8aff;
}

.tab-content {
    padding-top: 16px;
}

/* --- Code Blocks --------------------------------------------------------- */
.code-block {
    background: #0a0a16;
    border: 1px solid #252540;
    border-radius: 6px;
    padding: 12px;
    font-family: "Cascadia Code", "Fira Code", "JetBrains Mono", monospace;
    font-size: 0.8rem;
    color: #b0b0d0;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 400px;
    overflow: auto;
}

.code-block-inline {
    background: #0a0a16;
    border: 1px solid #252540;
    border-radius: 4px;
    padding: 6px 8px;
    font-family: monospace;
    font-size: 0.75rem;
    color: #b0b0d0;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 200px;
    overflow: auto;
    margin-top: 4px;
}

.code-textarea {
    font-family: "Cascadia Code", "Fira Code", "JetBrains Mono", monospace !important;
    font-size: 0.8rem !important;
    line-height: 1.6 !important;
}

/* --- Workflow Editor ------------------------------------------------------ */
.workflow-header {
    margin-bottom: 16px;
}

.step-item {
    background: #13132a;
    border: 1px solid #252540;
    border-radius: 6px;
    padding: 16px;
    margin-bottom: 12px;
    position: relative;
    cursor: grab;
    transition: border-color 0.15s;
}

.step-item:active {
    cursor: grabbing;
}

.step-item.drag-over {
    border-color: #5c6cdd;
    background: #1a1a3a;
}

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

.step-number {
    font-size: 0.75rem;
    color: #505070;
    font-weight: 600;
    margin-right: 12px;
}

.step-type-select {
    flex: 1;
    max-width: 200px;
}

.step-type-select select {
    width: 100%;
    padding: 6px 10px;
    background: #0f0f1a;
    border: 1px solid #303050;
    border-radius: 4px;
    color: #d0d0e0;
    font-size: 0.85rem;
}

.step-remove {
    background: #331a1a;
    border: 1px solid #442222;
    color: #cc4444;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.15s;
}
.step-remove:hover {
    background: #442222;
}

.step-fields {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.step-fields .form-group {
    margin-bottom: 0;
}

.step-fields label {
    font-size: 0.75rem;
    margin-bottom: 2px;
}

.step-fields input,
.step-fields select {
    padding: 6px 10px;
    font-size: 0.8rem;
}

/* Drag handle indicator */
.drag-handle {
    color: #404060;
    font-size: 1.2rem;
    cursor: grab;
    user-select: none;
    margin-right: 8px;
}

/* --- Variable hints ------------------------------------------------------ */
.variable-hints {
    margin-top: 20px;
    padding: 12px 16px;
    background: #13132a;
    border: 1px solid #252540;
    border-radius: 6px;
    font-size: 0.8rem;
    color: #707090;
    line-height: 1.8;
}

.variable-hints h4 {
    color: #909090;
    font-size: 0.8rem;
    margin-bottom: 4px;
}

.variable-hints code {
    background: #0a0a16;
    padding: 1px 6px;
    border-radius: 3px;
    color: #ccaa44;
    font-size: 0.75rem;
}

/* --- File List ----------------------------------------------------------- */
.file-list {
    list-style: none;
    padding: 0;
}

.file-list li {
    padding: 6px 0;
    border-bottom: 1px solid #1e1e35;
    font-size: 0.85rem;
    color: #b0b0d0;
}

.file-list li:last-child {
    border-bottom: none;
}

/* --- Pagination ---------------------------------------------------------- */
.pagination {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 16px;
    justify-content: center;
}

.pagination-current {
    display: inline-block;
    padding: 4px 10px;
    background: #4c5ccc;
    color: #fff;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* --- Utility Classes ----------------------------------------------------- */
.text-mono {
    font-family: "Cascadia Code", "Fira Code", monospace;
}

.text-sm {
    font-size: 0.8rem;
}

.text-muted {
    color: #606080;
}

.text-link {
    color: #7c8aff;
}
.text-link:hover {
    color: #a0aaff;
}

.hidden {
    display: none !important;
}

.actions-cell {
    white-space: nowrap;
}

/* --- Details/Summary ----------------------------------------------------- */
details summary {
    cursor: pointer;
    color: #7c8aff;
    font-size: 0.8rem;
}

details summary:hover {
    color: #a0aaff;
}

.raw-json-details {
    margin-top: 12px;
}

/* --- Responsive (basic desktop support) ---------------------------------- */
@media (max-width: 1024px) {
    .sidebar {
        width: 180px;
    }
    .main-content {
        margin-left: 180px;
    }
    .stat-cards {
        flex-wrap: wrap;
    }
    .stat-card {
        min-width: 120px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 60px;
    }
    .sidebar-header {
        padding: 16px 8px;
    }
    .logo-sub, .admin-name {
        display: none;
    }
    .nav-link {
        padding: 10px;
        justify-content: center;
        font-size: 0;
    }
    .nav-icon {
        font-size: 1rem;
    }
    .main-content {
        margin-left: 60px;
    }
    .form-row {
        flex-direction: column;
    }
}
