:root {
    --ui-primary: #1677ff;
    --ui-primary-soft: #e6f4ff;
    --ui-primary-hover: #4096ff;
    --ui-text: #1f2329;
    --ui-text-secondary: #646a73;
    --ui-border: #e5e6eb;
    --ui-border-strong: #d9d9d9;
    --ui-bg: #f2f3f5;
    --ui-card: #ffffff;
    --ui-success: #52c41a;
    --ui-danger: #ff4d4f;
    --ui-warning: #faad14;
    --ui-radius: 2px;
    --ui-sidebar-width: 204px;
    --ui-header-height: 56px;
    --ui-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: var(--ui-font);
    color: var(--ui-text);
    background: var(--ui-bg);
    font-size: 14px;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.hidden {
    display: none !important;
}

.layout {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--ui-sidebar-width) minmax(0, 1fr);
    background: var(--ui-bg);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: #fff;
    border-right: 1px solid var(--ui-border);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.brand {
    height: var(--ui-header-height);
    display: flex;
    align-items: center;
    padding: 0 18px;
    border-bottom: 1px solid var(--ui-border);
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
}

.brand-mark {
    width: 24px;
    height: 24px;
    display: inline-grid;
    place-items: center;
    margin-right: 10px;
    border-radius: 5px;
    color: #fff;
    background: var(--ui-primary);
    font-size: 12px;
    font-weight: 700;
}

.menu {
    padding: 8px 0;
    flex: 1;
}

.menu-item {
    width: 100%;
    min-height: 46px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px;
    border: 0;
    border-right: 3px solid transparent;
    background: transparent;
    color: #303133;
    text-align: left;
    transition: background 0.15s ease, color 0.15s ease;
}

.menu-item:hover {
    color: var(--ui-primary);
    background: #fafafa;
}

.menu-item.active {
    color: var(--ui-primary);
    background: var(--ui-primary-soft);
    border-right-color: var(--ui-primary);
}

.menu-icon {
    width: 16px;
    text-align: center;
    color: currentColor;
    font-size: 15px;
}

.sidebar-foot {
    border-top: 1px solid var(--ui-border);
    padding: 14px 18px;
    color: var(--ui-text-secondary);
    font-size: 12px;
}

.main {
    min-width: 0;
}

.topbar {
    height: var(--ui-header-height);
    background: #fff;
    border-bottom: 1px solid var(--ui-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 9;
}

.breadcrumb {
    color: var(--ui-text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.breadcrumb strong {
    color: var(--ui-text);
    font-weight: 500;
}

.account-area {
    display: flex;
    align-items: center;
    gap: 16px;
    color: var(--ui-text-secondary);
}

.account-name {
    color: var(--ui-text);
    font-weight: 500;
}

.content {
    padding: 0 24px 24px;
}

.page-title-wrap {
    margin: 0 -24px 24px;
    padding: 18px 24px 20px;
    background: #fff;
    border-bottom: 1px solid var(--ui-border);
}

.page-title {
    margin: 0;
    font-size: 20px;
    line-height: 1.4;
    font-weight: 600;
}

.page-subtitle {
    margin-top: 6px;
    color: var(--ui-text-secondary);
    font-size: 13px;
}

.card {
    background: var(--ui-card);
    border: 1px solid #eef0f3;
    border-radius: var(--ui-radius);
    box-shadow: var(--ui-shadow);
    margin-bottom: 16px;
}

.card-body {
    padding: 20px 24px;
}

.card-header {
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 24px;
    border-bottom: 1px solid var(--ui-border);
}

.card-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 16px 20px;
    align-items: end;
}

.form-item {
    grid-column: span 3;
    min-width: 0;
}

.form-item.span-2 {
    grid-column: span 2;
}

.form-item.span-4 {
    grid-column: span 4;
}

.form-item.span-6 {
    grid-column: span 6;
}

.form-item.actions {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.form-label {
    display: block;
    margin-bottom: 7px;
    color: #303133;
    font-size: 13px;
}

.input,
.select {
    width: 100%;
    height: 34px;
    padding: 0 11px;
    border: 1px solid var(--ui-border-strong);
    border-radius: var(--ui-radius);
    background: #fff;
    color: var(--ui-text);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus,
.select:focus {
    border-color: var(--ui-primary);
    box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.1);
}

.input::placeholder {
    color: #b6bac3;
}

.btn {
    height: 34px;
    padding: 0 15px;
    border-radius: var(--ui-radius);
    border: 1px solid var(--ui-border-strong);
    background: #fff;
    color: var(--ui-text);
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.btn:hover {
    color: var(--ui-primary);
    border-color: var(--ui-primary);
}

.btn-primary {
    color: #fff;
    border-color: var(--ui-primary);
    background: var(--ui-primary);
}

.btn-primary:hover {
    color: #fff;
    background: var(--ui-primary-hover);
    border-color: var(--ui-primary-hover);
}

.btn-danger {
    color: var(--ui-danger);
    border-color: #ffccc7;
    background: #fff;
}

.btn-danger:hover {
    color: #fff;
    border-color: var(--ui-danger);
    background: var(--ui-danger);
}

.btn-link {
    height: auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ui-primary);
}

.btn-link:hover {
    color: var(--ui-primary-hover);
}

.tabs {
    display: inline-flex;
    gap: 22px;
    border-bottom: 1px solid var(--ui-border);
    width: 100%;
    padding: 0 24px;
    background: #fff;
}

.tab-button {
    position: relative;
    height: 48px;
    padding: 0 2px;
    border: 0;
    background: transparent;
    color: var(--ui-text-secondary);
}

.tab-button.active {
    color: var(--ui-primary);
    font-weight: 500;
}

.tab-button.active::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    background: var(--ui-primary);
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin: 16px 0 0;
}

.stat-card {
    border: 1px solid var(--ui-border);
    background: #fafafa;
    padding: 14px 16px;
}

.stat-label {
    color: var(--ui-text-secondary);
    font-size: 12px;
}

.stat-value {
    margin-top: 5px;
    font-size: 20px;
    font-weight: 600;
    color: var(--ui-text);
}

.table-wrap {
    overflow: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    background: #fff;
}

th,
td {
    padding: 13px 12px;
    text-align: left;
    border-bottom: 1px solid var(--ui-border);
    white-space: nowrap;
}

th {
    background: #fafafa;
    color: #303133;
    font-weight: 500;
    font-size: 13px;
}

td {
    color: #4e5969;
}

tbody tr:hover td {
    background: #fafcff;
}

.table-empty {
    text-align: center;
    padding: 48px 20px;
    color: #8c8c8c;
}

.tag {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 0 7px;
    border-radius: 2px;
    border: 1px solid;
    font-size: 12px;
}

.tag-success {
    color: #389e0d;
    background: #f6ffed;
    border-color: #b7eb8f;
}

.tag-danger {
    color: #cf1322;
    background: #fff1f0;
    border-color: #ffa39e;
}

.tag-neutral {
    color: #595959;
    background: #fafafa;
    border-color: #d9d9d9;
}

.status-pending {
    color: var(--ui-danger);
    font-weight: 500;
}

.status-processed {
    color: var(--ui-success);
    font-weight: 500;
}

.uid-button {
    border: 0;
    background: transparent;
    color: var(--ui-primary);
    padding: 0;
    text-decoration: none;
}

.uid-button:hover {
    text-decoration: underline;
}

.uid-button.processed {
    color: var(--ui-text-secondary);
    cursor: default;
}

.muted {
    color: var(--ui-text-secondary);
}

.message {
    margin-top: 12px;
    color: var(--ui-text-secondary);
}

.debug-panel {
    margin-top: 16px;
    border-top: 1px dashed var(--ui-border);
    padding-top: 14px;
}

.debug-panel summary {
    color: var(--ui-text-secondary);
    cursor: pointer;
}

pre {
    margin: 12px 0 0;
    padding: 12px;
    background: #0f172a;
    color: #dbeafe;
    border-radius: 4px;
    overflow: auto;
    max-height: 260px;
    white-space: pre-wrap;
    word-break: break-word;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px;
    background: #f4f6f8;
}

.login-card {
    width: min(420px, 100%);
    background: #fff;
    border: 1px solid var(--ui-border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
    padding: 34px;
}

.login-title {
    margin: 0 0 8px;
    font-size: 24px;
}

.login-desc {
    margin: 0 0 26px;
    color: var(--ui-text-secondary);
}

.login-form .form-item {
    margin-bottom: 16px;
}

.login-form .btn {
    width: 100%;
    height: 38px;
}

.login-status {
    margin-top: 14px;
    color: var(--ui-text-secondary);
    font-size: 12px;
    text-align: center;
}

.modal-mask {
    --modal-mask-duration: 180ms;
    --modal-enter-duration: 240ms;
    --modal-exit-duration: 160ms;
    --modal-enter-ease: cubic-bezier(0.22, 1, 0.36, 1);
    --modal-exit-ease: cubic-bezier(0.4, 0, 1, 1);

    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 24px;
    animation: modal-mask-in var(--modal-mask-duration) ease-out both;
}

.modal-mask .modal {
    animation: modal-enter var(--modal-enter-duration) var(--modal-enter-ease) both;
    transform-origin: center center;
    will-change: transform, opacity;
}

.modal-mask.modal-closing {
    animation: modal-mask-out var(--modal-exit-duration) ease-in both;
    pointer-events: none;
}

.modal-mask.modal-closing .modal {
    animation: modal-exit var(--modal-exit-duration) var(--modal-exit-ease) both;
}

@keyframes modal-mask-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modal-mask-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes modal-enter {
    from {
        opacity: 0;
        transform: translate3d(0, 18px, 0) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
}

@keyframes modal-exit {
    from {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
    to {
        opacity: 0;
        transform: translate3d(0, 10px, 0) scale(0.98);
    }
}

.modal {
    width: min(520px, 100%);
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
}

@media (prefers-reduced-motion: reduce) {
    .modal-mask,
    .modal-mask .modal,
    .modal-mask.modal-closing,
    .modal-mask.modal-closing .modal {
        animation: none;
    }
}

.modal-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--ui-border);
    font-size: 16px;
    font-weight: 600;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px 18px;
}

.token-box {
    padding: 12px;
    background: #f7f8fa;
    border: 1px solid var(--ui-border);
    word-break: break-all;
    line-height: 1.7;
}

@media (max-width: 1100px) {
    .form-item,
    .form-item.span-2,
    .form-item.span-4 {
        grid-column: span 6;
    }

    .stats-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    :root {
        --ui-sidebar-width: 164px;
    }

    .content,
    .topbar {
        padding-left: 14px;
        padding-right: 14px;
    }

    .page-title-wrap {
        margin-left: -14px;
        margin-right: -14px;
        padding-left: 14px;
        padding-right: 14px;
    }

    .form-item,
    .form-item.span-2,
    .form-item.span-4,
    .form-item.span-6 {
        grid-column: 1 / -1;
    }

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

.modal-form {
    display: grid;
    gap: 16px;
}

.expiry-input {
    min-width: 180px;
}

.btn-link.danger-link {
    color: var(--ui-danger);
}

.btn-link.danger-link:hover {
    color: #ff7875;
}

/* v2: Agent assignment / sub-agent management */
.operation-col {
    width: 180px;
}

.row-actions {
    gap: 14px;
}

.readonly-field {
    min-height: 34px;
    display: flex;
    align-items: center;
    padding: 0 11px;
    border: 1px solid var(--ui-border);
    background: #fafafa;
    color: var(--ui-text-secondary);
}

.assignment-card {
    overflow: hidden;
}

.assignment-section + .assignment-section {
    border-top: 16px solid var(--ui-bg);
}

.assignment-section .card-header:first-child {
    background: #fff;
}

.compact-header {
    min-height: 50px;
    background: #fff;
}

.section-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.auto-assign-grid .form-item,
.manual-assign-grid .form-item {
    grid-column: span 2;
}

.auto-assign-grid .form-item:first-child,
.manual-assign-grid .form-item:first-child {
    grid-column: span 3;
}

.auto-assign-grid .form-item.actions,
.manual-assign-grid .form-item.actions {
    grid-column: span 2;
}

/* v2: minimal Sub-Agent task page */
.sub-agent-page {
    background: var(--ui-bg);
}

.sub-agent-shell {
    min-height: 100vh;
    padding: 12px;
}

.sub-task-card {
    margin: 0;
    min-height: calc(100vh - 24px);
}

.sub-task-tabs-row {
    min-height: 50px;
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--ui-border);
}

.sub-task-tabs {
    width: auto;
    border-bottom: 0;
    flex: 1;
}

.sub-logout {
    align-self: center;
    margin-right: 20px;
}

.sub-task-header {
    min-height: 54px;
}

.sub-query-toolbar {
    margin-left: auto;
}

.sub-task-table-wrap {
    min-height: 180px;
}

.task-table {
    table-layout: fixed;
}

.task-table th,
.task-table td {
    vertical-align: middle;
}

.task-table .task-uid {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.task-status,
.invite-status {
    min-width: 52px;
    justify-content: center;
}

@media (max-width: 1100px) {
    .auto-assign-grid .form-item,
    .manual-assign-grid .form-item,
    .auto-assign-grid .form-item:first-child,
    .manual-assign-grid .form-item:first-child,
    .auto-assign-grid .form-item.actions,
    .manual-assign-grid .form-item.actions {
        grid-column: span 6;
    }
}

@media (max-width: 760px) {
    .sub-agent-shell {
        padding: 0;
        background: #fff;
    }

    .sub-task-card {
        min-height: 100vh;
        border: 0;
        box-shadow: none;
    }

    .sub-task-tabs-row {
        min-height: 48px;
    }

    .sub-task-tabs {
        padding: 0 14px;
        gap: 24px;
    }

    .sub-task-tabs .tab-button {
        height: 48px;
    }

    .sub-logout {
        display: none;
    }

    .sub-task-header {
        min-height: 52px;
        padding: 0 12px;
        gap: 8px;
    }

    .sub-task-header .card-title {
        font-size: 15px;
    }

    .sub-query-toolbar {
        gap: 8px;
        flex-wrap: nowrap;
    }

    .sub-query-toolbar .muted {
        max-width: 130px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 12px;
    }

    .sub-query-toolbar .btn {
        height: 34px;
        padding: 0 14px;
    }

    .sub-task-table-wrap {
        overflow-x: hidden;
    }

    .task-table {
        width: 100%;
        table-layout: fixed;
        font-size: 13px;
    }

    .task-table th,
    .task-table td {
        padding: 12px 7px;
        white-space: normal;
        word-break: break-word;
        text-align: center;
    }

    .task-table th:first-child,
    .task-table td:first-child {
        text-align: left;
        padding-left: 12px;
    }

    .task-table .uid-button {
        font-size: 13px;
        line-height: 1.35;
        white-space: normal;
        word-break: break-all;
        text-align: left;
    }

    .task-status,
    .invite-status {
        min-width: 0;
        padding: 0 5px;
        font-size: 11px;
    }

    .auto-assign-grid .form-item,
    .manual-assign-grid .form-item,
    .auto-assign-grid .form-item:first-child,
    .manual-assign-grid .form-item:first-child,
    .auto-assign-grid .form-item.actions,
    .manual-assign-grid .form-item.actions {
        grid-column: 1 / -1;
    }
}

/* v3: assignment tabs share one workspace */
.assignment-tabs {
    padding: 0 24px;
}

.assignment-section + .assignment-section {
    border-top: 0;
}
