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

:root {
    --primary: #DF1A22;
    --primary-dark: #A51218;
    --primary-light: #FCE8E9;
    --secondary: #0F8A3C;
    --danger: #C62828;
    --warning: #C27A00;
    --success: #0F8A3C;
    --text-primary: #1F2328;
    --text-secondary: #4B5563;
    --text-light: #6B7280;
    --border: #D9DEE5;
    --bg-light: #F2F5F8;
    --bg-lighter: #F7F9FC;
    --surface: #FFFFFF;
    --focus-ring: #7F1116;
    --focus-ring-soft: rgba(127, 17, 22, 0.24);
    --shadow-sm: 0 1px 2px rgba(9, 30, 66, 0.12);
    --shadow-md: 0 4px 12px rgba(9, 30, 66, 0.12);
    --shadow-lg: 0 8px 24px rgba(9, 30, 66, 0.14);
    --transition: all 0.2s ease;
    --brand-logo-size: 44px;
    --brand-logo-safe-space: 6px;
    --tab-icon-size: 18px;
    --tab-icon-stroke: 1.75px;
}

body {
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    color: var(--text-primary);
    background: var(--bg-lighter);
    min-height: 100vh;
    overflow-x: hidden;
}

body.authz-pending {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-lighter);
}

/* Background orbs */
.bg-orb {
    position: fixed;
    border-radius: 50%;
    opacity: 0.08;
    pointer-events: none;
    z-index: 0;
}

.orb-1 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(223, 26, 34, 0.2) 0%, rgba(223, 26, 34, 0) 70%);
    top: -200px;
    right: -200px;
    animation: float 20s infinite ease-in-out;
}

.orb-2 {
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(31, 35, 40, 0.12) 0%, rgba(31, 35, 40, 0) 70%);
    bottom: -150px;
    left: -150px;
    animation: float 25s infinite ease-in-out reverse;
}

@keyframes float {
    0%, 100% { transform: translate(0px, 0px); }
    50% { transform: translate(30px, 30px); }
}

/* Header */
.app-header {
    background: var(--surface);
    color: var(--text-primary);
    padding: 1rem 2rem;
    box-shadow: var(--shadow-md);
    border-bottom: 3px solid var(--primary);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand-logo {
    width: var(--brand-logo-size);
    height: var(--brand-logo-size);
    padding: var(--brand-logo-safe-space);
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    flex: 0 0 auto;
}

.brand-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.brand-kicker {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--primary);
    margin-bottom: 0.15rem;
}

.brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    line-height: 1.12;
}

.tagline {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.3rem;
    line-height: 1.2;
}

.auth-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.user-identity {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}

.user-avatar {
    width: 2.25rem;
    height: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 2.25rem;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-light);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 700;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.user-name {
    font-size: 0.95rem;
    overflow-wrap: anywhere;
}

/* Access Denied */
.access-denied-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-lighter);
}

.access-denied-content {
    text-align: center;
    background: var(--surface);
    padding: 2rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    max-width: 400px;
}

.access-denied-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.access-denied-content h1 {
    color: var(--danger);
    margin-bottom: 1rem;
}

.access-denied-content p {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.access-denied-content .meta {
    font-size: 0.9rem;
    color: var(--text-light);
}

.hidden {
    display: none !important;
}

/* Main content */
.main-content {
    display: flex;
    gap: 2rem;
    padding: 2rem;
    margin: 0;
    position: relative;
    z-index: 1;
    width: 100%;
}

/* Tabs */
.tabs {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 240px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    padding-right: 1.5rem;
    margin: 0;
}

/* Nav Groups */
.nav-group {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.nav-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    transition: var(--transition);
    text-align: left;
}

.nav-group-header:hover {
    color: var(--primary-dark);
    background: var(--bg-light);
}

.nav-group-header:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

.nav-group-chevron {
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
    flex-shrink: 0;
    margin-right: 4px;
    margin-bottom: 2px;
}

.nav-group.collapsed .nav-group-chevron {
    transform: rotate(-45deg);
    margin-bottom: 0;
    margin-right: 6px;
}

.nav-group-items {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: 0.35rem;
}

.nav-group.collapsed .nav-group-items {
    display: none;
}

/* Content Area */
.content-area {
    flex: 1;
    min-width: 0;
}

.tab-label {
    line-height: 1;
    font-weight: 600;
}

.tab-icon {
    width: var(--tab-icon-size);
    height: var(--tab-icon-size);
    display: inline-block;
    position: relative;
    flex: 0 0 var(--tab-icon-size);
}

.tab-icon-apps {
    border: var(--tab-icon-stroke) solid currentColor;
    border-radius: 4px;
}

.tab-icon-apps::before,
.tab-icon-apps::after {
    content: '';
    position: absolute;
    left: 3px;
    right: 3px;
    height: var(--tab-icon-stroke);
    background: currentColor;
}

.tab-icon-apps::before {
    top: 5px;
}

.tab-icon-apps::after {
    top: 10px;
}

.tab-icon-create {
    border: var(--tab-icon-stroke) solid currentColor;
    border-radius: 50%;
}

.tab-icon-create::before,
.tab-icon-create::after {
    content: '';
    position: absolute;
    background: currentColor;
}

.tab-icon-create::before {
    width: 8px;
    height: var(--tab-icon-stroke);
    left: 4px;
    top: 7px;
}

.tab-icon-create::after {
    width: var(--tab-icon-stroke);
    height: 8px;
    left: 7px;
    top: 4px;
}

.tab-icon-delete {
    border: var(--tab-icon-stroke) solid currentColor;
    border-radius: 2px;
    height: 12px;
    width: 11px;
    margin-top: 4px;
    margin-left: 3px;
}

.tab-icon-delete::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    height: var(--tab-icon-stroke);
    background: currentColor;
    border-radius: 1px;
}

.tab-icon-delete::after {
    content: '';
    position: absolute;
    top: -5px;
    left: 2px;
    width: 5px;
    height: 2px;
    border: var(--tab-icon-stroke) solid currentColor;
    border-bottom: none;
    border-radius: 1px 1px 0 0;
}

.tab-icon-restore {
    border: var(--tab-icon-stroke) solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    transform: rotate(12deg);
}

.tab-icon-restore::before {
    content: '';
    position: absolute;
    right: -1px;
    top: 1px;
    width: 6px;
    height: 6px;
    border-top: var(--tab-icon-stroke) solid currentColor;
    border-right: var(--tab-icon-stroke) solid currentColor;
    transform: rotate(38deg);
}

.tab-icon-restore::after {
    display: none;
}

.tab-icon-exception {
    border: var(--tab-icon-stroke) solid currentColor;
    border-radius: 3px;
}

.tab-icon-exception::before,
.tab-icon-exception::after {
    content: '';
    position: absolute;
    left: 50%;
    background: currentColor;
    transform: translateX(-50%);
}

.tab-icon-exception::before {
    width: var(--tab-icon-stroke);
    top: 3px;
    bottom: 7px;
}

.tab-icon-exception::after {
    width: var(--tab-icon-stroke);
    height: var(--tab-icon-stroke);
    bottom: 3px;
}

.tab-button {
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-secondary);
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-align: left;
    width: 100%;
}

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

.tab-button.active {
    color: var(--primary-dark);
    border-left-color: var(--primary);
    background: rgba(223, 26, 34, 0.05);
}

.tab-button .tab-icon {
    transition: var(--transition);
}

.tab-button.active .tab-icon {
    background: var(--primary-light);
}

.tab-button.active .tab-icon-apps,
.tab-button.active .tab-icon-create,
.tab-button.active .tab-icon-delete,
.tab-button.active .tab-icon-restore,
.tab-button.active .tab-icon-exception {
    box-shadow: inset 0 0 0 1px rgba(165, 18, 24, 0.08);
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
    flex: 1;
    min-width: 0;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Section header */
.section-header {
    margin-bottom: 2rem;
}

.section-header h2 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.section-description {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* Search box */
.search-box {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.search-box input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    background: var(--surface);
}

.search-box input:focus {
    outline: none;
    border-color: var(--focus-ring);
    box-shadow: 0 0 0 3px var(--focus-ring-soft);
}

/* Applications grid */
.applications-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

/* Flag Exception list */
.exception-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.exception-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    flex-wrap: wrap;
    cursor: pointer;
    transition: var(--transition);
}

.exception-item:hover {
    border-color: rgba(223, 26, 34, 0.35);
    box-shadow: var(--shadow-md);
}

.exception-item-name {
    font-weight: 600;
    color: var(--primary-dark);
}

.exception-item-meta {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

.exception-checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-primary);
    cursor: pointer;
    white-space: nowrap;
}

.exception-checkbox {
    width: 1.1rem;
    height: 1.1rem;
    cursor: pointer;
}

.app-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    transition: var(--transition);
    cursor: pointer;
}

.app-card:hover {
    border-color: rgba(223, 26, 34, 0.35);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.app-card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 1rem;
}

.app-card-statuses {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.35rem;
}

.app-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-dark);
    word-break: break-word;
}

.app-status {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.app-status.active {
    background: rgba(15, 138, 60, 0.14);
    color: var(--success);
}

.app-status.disabled {
    background: rgba(198, 40, 40, 0.14);
    color: var(--danger);
}

.app-status.deleted {
    background: rgba(194, 122, 0, 0.15);
    color: var(--warning);
}

.app-status.unused {
    background: rgba(194, 122, 0, 0.15);
    color: var(--warning);
}

.app-card-meta {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.app-card-meta-item {
    display: grid;
    gap: 0.25rem;
    font-size: 0.9rem;
}

.app-card-meta-label {
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
}

.app-card-meta-value {
    color: var(--text-primary);
    word-break: break-all;
    font-family: monospace;
    font-size: 0.85rem;
}

.app-card-owner {
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--bg-light);
    border-radius: 8px;
    transition: var(--transition);
}

.app-card-owner:hover {
    background: rgba(223, 26, 34, 0.06);
}

.app-card-owner-label {
    font-size: 0.8rem;
    color: var(--text-light);
    text-transform: uppercase;
}

.app-card-owner-email {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.app-card-owner-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.35rem;
}

.app-card-owner-chip {
    font-size: 0.8rem;
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.15rem 0.55rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.app-card-owner-id {
    font-family: monospace;
}

.app-card-owner-more {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: italic;
    align-self: center;
}

.app-card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: auto;
}

.app-card-actions button {
    flex: 1;
}

/* Forms */
.form {
    background: var(--surface);
    padding: 2rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    max-width: 600px;
    box-shadow: var(--shadow-sm);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.form-label.required::after {
    content: ' *';
    color: var(--danger);
}

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: var(--transition);
    background: var(--surface);
}

.form-input:focus {
    outline: none;
    border-color: var(--focus-ring);
    box-shadow: 0 0 0 3px var(--focus-ring-soft);
}

.form-input:disabled {
    background: var(--bg-light);
    color: var(--text-light);
    cursor: not-allowed;
}

.form-group small {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-light);
}

.info-box {
    display: flex;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--primary-light);
    border-left: 4px solid var(--primary);
    border-radius: 8px;
    color: var(--primary-dark);
    font-size: 0.9rem;
}

.info-box.info-box-danger {
    background: rgba(198, 40, 40, 0.08);
    border-left-color: var(--danger);
    color: var(--danger);
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

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

.btn-primary:active:not(:disabled) {
    transform: translateY(1px);
}

.btn-outline {
    background: var(--surface);
    color: var(--primary-dark);
    border: 1px solid var(--primary-dark);
}

.btn-outline:hover:not(:disabled) {
    background: var(--primary-light);
}

.app-header .btn-outline {
    background: transparent;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

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

.btn-success:hover:not(:disabled) {
    background: #0a6310;
}

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

.btn-danger:hover:not(:disabled) {
    background: #aa1119;
}

.btn:focus-visible,
.tab-button:focus-visible,
.form-input:focus-visible,
.search-box input:focus-visible,
.modal-close:focus-visible,
.app-card:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

.btn:focus:not(:focus-visible),
.tab-button:focus:not(:focus-visible),
.form-input:focus:not(:focus-visible),
.search-box input:focus:not(:focus-visible),
.modal-close:focus:not(:focus-visible),
.app-card:focus:not(:focus-visible) {
    outline: none;
}

/* Status messages */
.status-message {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 8px;
    display: flex;
    align-items: start;
    gap: 0.75rem;
    font-size: 0.95rem;
}

.status-message.success {
    background: rgba(15, 138, 60, 0.12);
    color: var(--success);
    border-left: 4px solid var(--success);
}

.status-message.error {
    background: rgba(198, 40, 40, 0.12);
    color: var(--danger);
    border-left: 4px solid var(--danger);
}

.status-message.info {
    background: var(--primary-light);
    color: var(--primary-dark);
    border-left: 4px solid var(--primary);
}

.status-message.loading {
    background: rgba(194, 122, 0, 0.14);
    color: var(--warning);
    border-left: 4px solid var(--warning);
}

.status-icon {
    flex-shrink: 0;
    margin-top: 0.1rem;
}

/* Loading state */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 1rem;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 1rem;
    height: 1rem;
    margin-left: 0.5rem;
    border: 2px solid var(--primary-light);
    border-top: 2px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 2rem;
    padding: 1.5rem 0;
}

.page-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border);
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

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

.modal-header h2 {
    font-size: 1.25rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
}

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

    .tabs {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding-right: 0;
        padding-bottom: 0.75rem;
    }

    .nav-group-items {
        flex-direction: row;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.25rem;
    }

    .tab-button {
        border-left: none;
        border-bottom: 2px solid transparent;
        border-radius: 4px;
        white-space: nowrap;
        flex: 0 0 auto;
    }

    .tab-button.active {
        border-left: none;
        border-bottom-color: var(--primary);
    }

    .app-header {
        padding: 0.9rem 1rem;
    }

    .brand h1 {
        font-size: 1.2rem;
    }

    .tagline {
        font-size: 0.78rem;
    }

    .brand-logo {
        width: 38px;
        height: 38px;
        padding: 5px;
    }

    .tab-icon {
        width: 16px;
        height: 16px;
        flex-basis: 16px;
    }

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

    .form-actions {
        flex-direction: column;
    }

    .header-content {
        flex-direction: column;
        gap: 1rem;
    }

    .search-box {
        flex-direction: column;
    }

    .pagination {
        flex-wrap: wrap;
    }
}
