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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* User Roles */
.roles-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.role-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.role-item:hover {
    background-color: #e9ecef;
    border-color: #ced4da;
}

.role-name {
    font-weight: 500;
    color: #495057;
    flex: 1;
}

.role-remove-btn {
    min-width: 32px;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    font-size: 1.25rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 0.75rem;
}

.role-remove-btn:hover {
    transform: scale(1.1);
}

.text-muted {
    color: #6c757d;
    font-style: italic;
}

/* Navigation */
.navbar {
    background-color: #2c3e50;
    color: white;
    padding: 1rem 0;
    margin-bottom: 2rem;
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
    text-decoration: none;
}

.logo-title {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
}

.logo-subtitle {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.nav-links > a {
    color: white;
    text-decoration: none;
    padding: 0.45rem 0.65rem;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.nav-links > a:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.nav-links > a.is-active {
    background-color: rgba(255, 255, 255, 0.1) !important;
}

.nav-links > a.is-active:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
}

.nav-user-menu {
    position: relative;
}

.user-menu-trigger {
    border: 0;
    background: transparent;
    color: #f2f5f8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    cursor: pointer;
    padding: 0;
}

.user-menu-initials {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 9999px;
    border: 0;
    background-color: #dde2e8;
    color: #2f3842;
    font-size: 1.05rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}

.user-menu-chevron {
    font-size: 0.8rem;
    line-height: 1;
    color: rgba(255, 255, 255, 0.9);
    transition: transform 0.2s ease;
}

.user-menu-trigger:hover .user-menu-initials,
.nav-user-menu.is-open .user-menu-initials {
    background-color: #d5dbe2;
    color: #222a33;
}

.nav-user-menu.is-impersonating .user-menu-initials {
    background-color: #f3cfd1;
    color: #7f2427;
}

.nav-user-menu.is-impersonating .user-menu-trigger:hover .user-menu-initials,
.nav-user-menu.is-impersonating.is-open .user-menu-initials {
    background-color: #efc0c3;
    color: #711e21;
}

.nav-user-menu.is-open .user-menu-chevron {
    transform: rotate(180deg);
}

.user-menu-dropdown {
    position: absolute;
    top: calc(100% + 0.8rem);
    right: 0;
    min-width: 18rem;
    background: #fff;
    border: 2px solid #d2d8df;
    border-radius: 16px;
    box-shadow: 0 8px 22px rgba(20, 33, 45, 0.12);
    padding: 0.5rem 0;
    z-index: 1000;
}

.user-menu-label {
    padding: 0.55rem 1.1rem 0.7rem;
    font-size: 0.85rem;
    color: #5c6b7a;
    border-bottom: 1px solid #e4e9ef;
    margin-bottom: 0;
}

.user-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1.1rem;
    text-decoration: none;
    color: #29323c;
    font-size: 1rem;
}

.user-menu-item:hover {
    background: #f2f5f8;
}

.user-menu-section + .user-menu-section {
    margin-top: 0.3rem;
    padding-top: 0.3rem;
    border-top: 1px solid #e4e9ef;
}

.user-menu-item-disabled,
.user-menu-item-disabled:hover {
    color: #7d8895;
    background: transparent;
    cursor: not-allowed;
}

.user-menu-soon {
    display: inline-block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #627181;
    background: #e9eef4;
    border-radius: 9999px;
    padding: 0.1rem 0.45rem;
}

.user-menu-item-logout-full {
    color: #7a2a2a;
}

/* Login */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 68vh;
}

.login-box {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    margin-bottom: 1.5rem;
    text-align: center;
}

.login-box form .btn {
    display: block;
    margin: 0 auto;
}

.login-alt {
    margin-top: 0.75rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.login-alt-sep {
    display: inline-block;
    padding: 0 0.5rem;
    color: #666;
}

.login-alt .btn {
    display: inline-block;
    width: auto;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

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

/* Keep checkboxes aligned to the left (not stretched). */
.form-group input[type="checkbox"],
.form-group .request-field-checkbox {
    width: auto !important;
    max-width: none;
    padding: 0 !important;
    margin: 0 !important;
    display: inline-block;
    vertical-align: middle;
    float: none;
}

.request-edit-page .form-group input[type="checkbox"],
.request-edit-page .form-group .request-field-checkbox {
    width: auto !important;
    margin-left: 0 !important;
    justify-self: start;
    align-self: start;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background-color 0.2s;
}

.btn-primary {
    background-color: #3498db;
    color: white;
}

.btn-primary:hover {
    background-color: #2980b9;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.alert-error {
    background-color: #fee;
    color: #c33;
    border: 1px solid #fcc;
}

.alert-success {
    background-color: #efe;
    color: #3c3;
    border: 1px solid #cfc;
}

/* Dashboard */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stat-card h3 {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 0.5rem;
}

.stat-number {
    font-size: 2rem;
    font-weight: bold;
    color: #2c3e50;
}

.quick-actions {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.action-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

/* Tables */
.table {
    width: 100%;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.table table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.table th {
    background-color: #f8f9fa;
    font-weight: 600;
}

.table tr:hover {
    background-color: #f8f9fa;
}

/* Cards */
.card {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

.card-header {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #eee;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.card-body {
    margin-top: 1rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 500;
    margin-right: 0.5rem;
}

.badge-success {
    background-color: #d4edda;
    color: #155724;
}

.badge-danger {
    background-color: #f8d7da;
    color: #721c24;
}

.badge-primary {
    background-color: #cce5ff;
    color: #004085;
}

/* Buttons */
.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.request-row-actions {
    display: flex;
    align-items: stretch;
    gap: 0.4rem;
}

.request-row-actions form {
    margin: 0;
}

.request-row-actions .btn {
    height: 100%;
}

.request-show-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.request-show-actions form {
    margin: 0;
    display: flex;
    align-items: center;
}

.request-show-actions .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    line-height: 1;
}

.user-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.user-actions form {
    margin: 0;
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    margin: 0;
}

/* Template edit field table sizing */
.template-fields-table {
    table-layout: fixed;
    width: 100%;
}

.template-fields-table th:nth-child(1),
.template-fields-table td:nth-child(1) {
    width: 4rem;
}

.template-fields-table th:nth-child(2),
.template-fields-table td:nth-child(2) {
    width: 28%;
}

.template-fields-table th:nth-child(3),
.template-fields-table td:nth-child(3) {
    width: 20%;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.template-fields-table th:nth-child(4),
.template-fields-table td:nth-child(4) {
    width: 8.5rem;
    white-space: nowrap;
}

.template-fields-table th:nth-child(7),
.template-fields-table td:nth-child(7) {
    width: 8.5rem;
    min-width: 8.5rem;
}

.template-fields-table td:nth-child(7) .btn {
    width: 100%;
}

/* Template field edit dialog */
.field-edit-dialog {
    position: fixed;
    inset: 0;
    margin: auto;
    width: min(89.6rem, calc(100vw - 2rem));
    max-width: 89.6rem;
    border: 0;
    border-radius: 12px;
    padding: 0;
    background: #fff;
    color: #233240;
    box-shadow: 0 20px 52px rgba(17, 30, 43, 0.28);
}

.field-edit-dialog::backdrop {
    background: rgba(16, 24, 32, 0.45);
    backdrop-filter: blur(2px);
}

.field-edit-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1.25rem 1.4rem 1.4rem;
}

.field-edit-mapping-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.75rem;
    align-items: start;
}

.field-edit-mapping-group {
    margin-bottom: 0;
}

.field-edit-mapping-group textarea {
    min-height: 10rem;
    resize: vertical;
    font-family: 'Courier New', monospace;
}

.field-edit-token-panel {
    background: #f5f8fb;
    border: 1px solid #d7e1ea;
    border-radius: 8px;
    padding: 0.6rem;
    margin-top: 2rem;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 0.4rem;
}

.field-edit-token-title {
    margin: 0;
    font-size: 0.95rem;
    color: #1f3142;
}

.field-edit-token-hint {
    margin: 0.25rem 0 0.6rem;
    color: #5c6f83;
    font-size: 0.8rem;
}

.field-edit-token {
    width: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #a8c0d8;
    border-radius: 6px;
    background: #fff;
    color: #25425d;
    font-size: 0.88rem;
    font-weight: 600;
    text-align: center;
    padding: 0.4rem 0.55rem;
    cursor: grab;
}

.field-edit-token:active {
    cursor: grabbing;
}

.field-edit-token:hover {
    background: #eaf2fa;
    border-color: #84a7ca;
}

.field-edit-title {
    margin: 0;
    color: #1d2f3f;
}

.field-edit-meta {
    margin: 0;
    color: #4b5d70;
}

.field-edit-override-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(11rem, 13rem) minmax(11rem, 13rem) auto;
    align-items: end;
    gap: 1rem;
}

.field-edit-override-name-group {
    margin-bottom: 0;
}

.field-edit-inline-fieldtype-group {
    margin-bottom: 0;
}

.field-edit-inline-role-group {
    margin-bottom: 0;
}

.field-edit-inline-fieldtype-group label {
    white-space: nowrap;
}

.field-edit-inline-fieldtype-group select {
    width: 100%;
    min-height: 2.875rem;
    height: 2.875rem;
    line-height: 1.25;
    padding: 0.75rem;
    box-sizing: border-box;
}

.field-edit-inline-role-group label {
    white-space: nowrap;
}

.field-edit-inline-role-group select {
    width: 100%;
    min-height: 2.875rem;
    height: 2.875rem;
    line-height: 1.25;
    padding: 0.75rem;
    box-sizing: border-box;
}

.field-edit-override-name-group input {
    min-height: 2.875rem;
    height: 2.875rem;
    line-height: 1.25;
    box-sizing: border-box;
}

.field-edit-checkbox-inline {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-bottom: 0.7rem;
}

.field-edit-required-group {
    margin-bottom: 0.25rem;
}

.field-edit-required-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    cursor: pointer;
}

.field-edit-required-label input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.field-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

@media (max-width: 720px) {
    .field-edit-override-row {
        grid-template-columns: 1fr;
    }

    .field-edit-checkbox-inline {
        padding-bottom: 0;
    }

    .field-edit-mapping-layout {
        grid-template-columns: 1fr;
    }
}

code {
    background-color: #f4f4f4;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

/* Timeline */
.timeline {
    position: relative;
    padding-left: 2rem;
}

.timeline-item {
    position: relative;
    padding-bottom: 2rem;
    padding-left: 2rem;
}

.timeline-item:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    top: 1.5rem;
    bottom: -1rem;
    width: 2px;
    background-color: #ddd;
}

.timeline-marker {
    position: absolute;
    left: 0;
    top: 0.25rem;
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 0 2px;
}

.timeline-primary { background-color: #3498db; box-shadow: 0 0 0 2px #3498db; }
.timeline-success { background-color: #27ae60; box-shadow: 0 0 0 2px #27ae60; }
.timeline-danger { background-color: #e74c3c; box-shadow: 0 0 0 2px #e74c3c; }
.timeline-warning { background-color: #f39c12; box-shadow: 0 0 0 2px #f39c12; }
.timeline-info { background-color: #3498db; box-shadow: 0 0 0 2px #3498db; }

.timeline-content {
    background: white;
    padding: 1rem;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.timeline-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.timeline-date {
    color: #666;
    font-size: 0.875rem;
    margin-left: auto;
}

.timeline-body {
    color: #333;
    margin-top: 0.5rem;
}

/* Form Builder */
.form-builder-actions {
    margin-bottom: 1.5rem;
    display: flex;
    gap: 1rem;
}

.field-item {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.field-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    align-items: end;
}

.empty-state {
    text-align: center;
    padding: 2rem;
    color: #666;
}

/* Workflow Builder */
.workflow-builder-actions {
    margin-bottom: 1.5rem;
}

.workflow-builder-footer-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    margin-bottom: 0;
}

.step-item {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

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

.step-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

/* Inbox Table */
.table-filters {
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: #666;
}

/* Footer */
.footer {
    margin-top: 2rem;
    padding: 1rem 0 2rem;
    color: #4b5d70;
}

.footer .container {
    text-align: center;
}

/* Responsive */
@media (max-width: 768px) {
    .navbar .container {
        flex-direction: column;
        gap: 1rem;
    }

    .nav-links {
        flex-wrap: wrap;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .action-buttons {
        flex-direction: column;
    }
}
